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)); } }
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); }
private function sendAuditRefundNotification($order, $pass, $amount, $note) { $course = $this->getCourseService()->getCourse($order['targetId']); if (empty($course)) { return false; } if ($pass) { $message = $this->setting('refund.successNotification', ''); } else { $message = $this->setting('refund.failedNotification', ''); } if (empty($message)) { return false; } $courseUrl = $this->generateUrl('course_show', array('id' => $course['id'])); $variables = array('course' => "<a href='{$courseUrl}'>{$course['title']}</a>", 'amount' => $amount, 'note' => $note); $message = StringToolkit::template($message, $variables); $this->getNotificationService()->notify($order['userId'], 'default', $message); return true; }
public function applyRefundOrder($id, $amount, $reason, $container) { $order = $this->getOrderService()->getOrder($id); if (empty($order)) { throw $this->createServiceException('订单不存在,不嫩申请退款。'); } $refund = $this->getOrderService()->applyRefundOrder($id, $amount, $reason); if ($refund['status'] == 'created') { $this->getCourseService()->lockStudent($order['targetId'], $order['userId']); $setting = $this->getSettingService()->get('refund'); $message = empty($setting) or empty($setting['applyNotification']) ? '' : $setting['applyNotification']; if ($message) { $courseUrl = $container->get('router')->generate('course_show', array('id' => $course['id'])); $variables = array('course' => "<a href='{$courseUrl}'>{$course['title']}</a>"); $message = StringToolkit::template($message, $variables); $this->getNotificationService()->notify($refund['userId'], 'default', $message); } } elseif ($refund['status'] == 'success') { $this->getCourseService()->removeStudent($order['targetId'], $order['userId']); } return $refund; }
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); } } }
public function applyRefundOrder($id, $amount, $reason, $container) { $user = $this->getCurrentUser(); $order = $this->getOrderService()->getOrder($id); if (empty($order)) { throw $this->createServiceException('订单不存在,不能申请退款。'); } $refund = $this->getOrderService()->applyRefundOrder($id, $amount, $reason); if ($refund['status'] == 'created') { $this->getClassroomService()->lockStudent($order['targetId'], $order['userId']); $setting = $this->getSettingService()->get('refund'); $message = empty($setting) || empty($setting['applyNotification']) ? '' : $setting['applyNotification']; $classroom = $this->getClassroomService()->getClassroom($order["targetId"]); $classroomUrl = $container->get('router')->generate('classroom_show', array('id' => $classroom['id'])); if ($message) { $variables = array('item' => "<a href='{$classroomUrl}'>{$classroom['title']}</a>"); $message = StringToolkit::template($message, $variables); $this->getNotificationService()->notify($refund['userId'], 'default', $message); } $adminmessage = '用户' . "{$user['nickname']}" . '申请退款' . "<a href='{$classroomUrl}'>{$classroom['title']}</a>" . "{$classroomSetting['name']},请审核。"; $adminCount = $this->getUserService()->searchUserCount(array('roles' => 'ADMIN')); $admins = $this->getUserService()->searchUsers(array('roles' => 'ADMIN'), array('id', 'DESC'), 0, $adminCount); foreach ($admins as $key => $admin) { $this->getNotificationService()->notify($admin['id'], 'default', $adminmessage); } } elseif ($refund['status'] == 'success') { $this->getClassroomService()->exitClassroom($order['targetId'], $order['userId']); } return $refund; }
private function simplifyClassroom($classroom) { return array('id' => $classroom['id'], 'title' => $classroom['title'], 'picture' => $classroom['middlePicture'], 'about' => StringToolkit::plain($classroom['about'], 100), 'price' => $classroom['price']); }
protected function simplifyLesson($lesson) { return array('id' => $lesson['id'], 'number' => $lesson['number'], 'type' => $lesson['type'], 'title' => $lesson['title'], 'summary' => StringToolkit::plain($lesson['summary'], 100)); }
public function createInviteCode($userId) { $inviteCode = StringToolkit::createRandomString(5); $inviteCode = strtoupper($inviteCode); $code = array('inviteCode' => $inviteCode); return $this->getUserDao()->updateUser($userId, $code); }
public function promoteLinkAction(Request $request) { $user = $this->getCurrentUser(); $message = null; $site = $this->getSettingService()->get('site', array()); $inviteSetting = $this->getSettingService()->get('invite', array()); $urlContent = $this->generateUrl('register', array(), true); $registerUrl = $urlContent . '?inviteCode=' . $user['inviteCode']; if ($inviteSetting['inviteInfomation_template']) { $variables = array('siteName' => $site['name'], 'registerUrl' => $registerUrl); $message = StringToolkit::template($inviteSetting['inviteInfomation_template'], $variables); } return $this->render('TopxiaWebBundle:Coin:promote-link-modal.html.twig', array('code' => $user['inviteCode'], 'inviteInfomation_template' => $message)); }
public function dataViewAction(Request $request, $blockId) { $block = $this->getBlockService()->getBlock($blockId); unset($block['meta']['default']); foreach ($block['meta']['items'] as $key => &$item) { $item['default'] = $block['data'][$key]; } return new Response('<pre>' . StringToolkit::jsonPettry(json_encode($block['meta'], JSON_UNESCAPED_UNICODE)) . '</pre>'); }
protected function simplifyTestpaperResult($testpaperResult) { return array('id' => $testpaperResult['id'], 'score' => $testpaperResult['score'], 'objectiveScore' => $testpaperResult['objectiveScore'], 'subjectiveScore' => $testpaperResult['subjectiveScore'], 'teacherSay' => StringToolkit::plain($testpaperResult['teacherSay'], 100), 'passedStatus' => $testpaperResult['passedStatus']); }
protected function sendAuditRefundNotification($orderRefundProcessor, $order, $data) { $target = $orderRefundProcessor->getTarget($order['targetId']); if (empty($target)) { return false; } if ($data['result'] == 'pass') { $message = $this->setting('refund.successNotification', ''); } else { $message = $this->setting('refund.failedNotification', ''); } if (empty($message)) { return false; } $targetUrl = $this->generateUrl($order["targetType"] . '_show', array('id' => $order['targetId'])); $variables = array("{$order['targetType']}" => "<a href='{$targetUrl}'>{$target['title']}</a>", "amount" => $data["amount"], "note" => $data["note"]); $message = StringToolkit::template($message, $variables); $this->getNotificationService()->notify($order['userId'], 'default', $message); }
public function testJsonPettryWithString() { $string = "hello,I'm stefaine."; $jstring = json_encode($string); $result = StringToolkit::jsonPettry($jstring); $this->assertEquals($jstring, $result); }