Ejemplo n.º 1
0
 public function sendAction(Request $request, $targetType, $id)
 {
     $smsType = 'sms_' . $targetType . '_publish';
     $index = $request->query->get('index');
     $onceSendNum = 1000;
     $url = $request->query->get('url');
     $count = $request->query->get('count');
     $parameters = array();
     if ($targetType == 'classroom') {
         $classroom = $this->getClassroomService()->getClassroom($id);
         $classroomSetting = $this->getSettingService()->get("classroom");
         $classroomName = isset($classroomSetting['name']) ? $classroomSetting['name'] : '班级';
         $classroom['title'] = StringToolkit::cutter($classroom['title'], 20, 15, 4);
         $parameters['classroom_title'] = $classroomName . ':《' . $classroom['title'] . '》';
         $description = $parameters['classroom_title'] . '发布';
         $students = $this->getUserService()->searchUsers(array('hasVerifiedMobile' => true), array('createdTime', 'DESC'), $index, $onceSendNum);
     } elseif ($targetType == 'course') {
         $course = $this->getCourseService()->getCourse($id);
         $course['title'] = StringToolkit::cutter($course['title'], 20, 15, 4);
         $parameters['course_title'] = '课程:《' . $course['title'] . '》';
         $description = $parameters['course_title'] . '发布';
         if ($course['parentId']) {
             $classroom = $this->getClassroomService()->findClassroomByCourseId($course['id']);
             if ($classroom) {
                 $count = $this->getClassroomService()->searchMemberCount(array('classroomId' => $classroom['classroomId']));
                 $students = $this->getClassroomService()->searchMembers(array('classroomId' => $classroom['classroomId']), array('createdTime', 'Desc'), $index, $onceSendNum);
             }
         } else {
             $students = $this->getUserService()->searchUsers(array('hasVerifiedMobile' => true), array('createdTime', 'DESC'), $index, $onceSendNum);
         }
     }
     if (!$this->getSmsService()->isOpen($smsType)) {
         throw new \RuntimeException("请先开启相关设置!");
     }
     $parameters['url'] = $url . ' ';
     if (!empty($students)) {
         if ($targetType == 'course' && $course['parentId']) {
             $studentIds = ArrayToolkit::column($students, 'userId');
         } else {
             $studentIds = ArrayToolkit::column($students, 'id');
         }
         $users = $this->getUserService()->findUsersByIds($studentIds);
         foreach ($users as $key => $value) {
             if (strlen($value['verifiedMobile']) == 0 || $value['locked']) {
                 unset($users[$key]);
             }
         }
         if (!empty($users)) {
             $userIds = ArrayToolkit::column($users, 'id');
             $result = $this->getSmsService()->smsSend($smsType, $userIds, $description, $parameters);
         }
     }
     if ($count > $index + $onceSendNum) {
         return $this->createJsonResponse(array('index' => $index + $onceSendNum, 'process' => intval(($index + $onceSendNum) / $count * 100)));
     } else {
         return $this->createJsonResponse(array('status' => 'success', 'process' => 100));
     }
 }
Ejemplo n.º 2
0
 public function getSmsInfo($targetId, $index, $smsType)
 {
     global $kernel;
     $siteSetting = $this->getSettingService()->get('site');
     $siteSetting['url'] = rtrim($siteSetting['url']);
     $siteSetting['url'] = rtrim($siteSetting['url'], '/');
     $hostName = $siteSetting['url'];
     $lesson = $this->getCourseService()->getLesson($targetId);
     if (empty($lesson)) {
         throw new \RuntimeException('课时不存在');
     }
     $originUrl = $hostName;
     $originUrl .= $kernel->getContainer()->get('router')->generate('course_learn', array('id' => $lesson['courseId']));
     $originUrl .= '#lesson/' . $lesson['id'];
     $url = $this->changeLink($originUrl);
     $course = $this->getCourseService()->getCourse($lesson['courseId']);
     $to = '';
     if ($course['parentId']) {
         $classroom = $this->getClassroomService()->findClassroomByCourseId($course['id']);
         if ($classroom) {
             $students = $this->getClassroomService()->searchMembers(array('classroomId' => $classroom['classroomId']), array('createdTime', 'Desc'), $index, 1000);
         }
     } else {
         $students = $this->getCourseService()->searchMembers(array('courseId' => $course['id']), array('createdTime', 'Desc'), $index, 1000);
     }
     $studentIds = ArrayToolkit::column($students, 'userId');
     $to = $this->getUsersMobile($studentIds);
     $lesson['title'] = StringToolkit::cutter($lesson['title'], 20, 15, 4);
     $parameters['lesson_title'] = '课时:《' . $lesson['title'] . '》';
     if ($lesson['type'] == 'live') {
         $parameters['startTime'] = date("Y-m-d H:i:s", $lesson['startTime']);
     }
     $course['title'] = StringToolkit::cutter($course['title'], 20, 15, 4);
     $parameters['course_title'] = '课程:《' . $course['title'] . '》';
     if ($smsType == 'sms_normal_lesson_publish' || $smsType == 'sms_live_lesson_publish') {
         $description = $parameters['course_title'] . ' ' . $parameters['lesson_title'] . '发布';
     } else {
         $description = $parameters['course_title'] . ' ' . $parameters['lesson_title'] . '预告';
     }
     $parameters['url'] = $url;
     return array('mobile' => $to, 'category' => $smsType, 'description' => $description, 'parameters' => $parameters);
 }
Ejemplo n.º 3
0
 public function onOrderPaySuccess(ServiceEvent $event)
 {
     $order = $event->getSubject();
     $targetType = $event->getArgument('targetType');
     $smsType = 'sms_' . $targetType . '_buy_notify';
     if ($this->getSmsService()->isOpen($smsType)) {
         $userId = $order['userId'];
         $user = $this->getUserService()->getUser($userId);
         $parameters = array();
         $parameters['order_title'] = $order['title'];
         $parameters['order_title'] = StringToolkit::cutter($parameters['order_title'], 20, 15, 4);
         if ($targetType == 'coin') {
             $parameters['totalPrice'] = $order['amount'] . '元';
         } else {
             $parameters['totalPrice'] = $order['totalPrice'] . '元';
         }
         $description = $parameters['order_title'] . '成功回执';
         if (strlen($user['verifiedMobile']) != 0) {
             $this->getSmsService()->smsSend($smsType, array($userId), $description, $parameters);
         }
     }
 }