You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

742 regels
31 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use yii\db\ActiveRecord;
  4. use yii\base\Exception;
  5. use common\models\Msg;
  6. use backend\modules\api\models\OrderMain;
  7. use Yii;
  8. /**
  9. * This is the model class for table "opera_message_template".
  10. *
  11. * @property integer $id
  12. * @property integer $supplier_id
  13. * @property integer $ticket_group_id
  14. * @property integer $ticket_id
  15. * @property string $content1
  16. * @property string $content2
  17. * @property string $content3
  18. * @property string $content4
  19. * @property string $content5
  20. * @property integer $create_user_id
  21. * @property string $create_time
  22. * @property integer $update_user_id
  23. * @property string $update_time
  24. * @property integer $template_type
  25. * @property integer $cancel_flag
  26. */
  27. class OperaMessageTemplate extends ActiveRecord
  28. {
  29. /**
  30. * @inheritdoc
  31. */
  32. public static function tableName()
  33. {
  34. return 'opera_message_template';
  35. }
  36. /**
  37. * @inheritdoc
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['supplier_id', 'ticket_group_id', 'ticket_id', 'create_user_id', 'update_user_id', 'template_type', 'cancel_flag'], 'integer'],
  43. [['ticket_group_id', 'ticket_id', 'content1', 'content2', 'content3', 'content4', 'content5', 'content6'], 'required'],
  44. [['content1', 'content2', 'content3', 'content4', 'content5', 'content6'], 'string'],
  45. [['create_time', 'update_time'], 'string', 'max' => 20],
  46. ];
  47. }
  48. /**
  49. * @inheritdoc
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'supplier_id' => 'Supplier ID',
  56. 'ticket_group_id' => 'Ticket Group ID',
  57. 'ticket_id' => 'Ticket ID',
  58. 'content1' => 'Content1',
  59. 'content2' => 'Content2',
  60. 'content3' => 'Content3',
  61. 'content4' => 'Content4',
  62. 'content5' => 'Content5',
  63. 'content6' => 'Content6',
  64. 'create_user_id' => 'Create User ID',
  65. 'create_time' => 'Create Time',
  66. 'update_user_id' => 'Update User ID',
  67. 'update_time' => 'Update Time',
  68. 'template_type' => 'Template Type',
  69. 'cancel_flag' => 'Cancel Flag',
  70. ];
  71. }
  72. /**
  73. * Function Description:OTA获取短信内容
  74. * Function Name: otaGetMsg
  75. * @param int $order_id
  76. * @param string $type :one 预定短信, two 出行短信
  77. * @return mixed
  78. *
  79. * @author 温依莅
  80. */
  81. public function otaGetMsgInfo($order_id, $type = 'one')
  82. {
  83. $json = array();
  84. if (!$order_id) {
  85. $json["code"] = '1';
  86. $json["info"] = '参数不正确';
  87. return $json;
  88. }
  89. //1,根据order_id获得短信内容
  90. $content_arr = $this->getMsgInfo($order_id, $type);
  91. //2,部分异常处理
  92. if ($content_arr == 'noRunInfo') {
  93. $json["code"] = '2';
  94. $json["info"] = '无出行信息';
  95. return $json;
  96. }
  97. if ($content_arr == 'notSend') {
  98. $json["code"] = '3';
  99. $json["info"] = '此线路票种不发送短信';
  100. return $json;
  101. }
  102. if ($content_arr == 'noTemplate') {
  103. $json["code"] = '4';
  104. $json["info"] = '模板信息缺失';
  105. return $json;
  106. }
  107. if ($content_arr == 'wrongOrderId') {
  108. $json["code"] = '5';
  109. $json["info"] = '错误订单号';
  110. return $json;
  111. }
  112. $name = $content_arr[0];
  113. $tel = $content_arr[1];
  114. $content = $content_arr[2];
  115. $json["code"] = '0';
  116. $json["info"] = '获取成功';
  117. $json['name'] = $name;
  118. $json['mobile'] = $tel;
  119. $json['content'] = $content;
  120. return $json;
  121. }
  122. /**
  123. * Function Description:下单发送短信
  124. * Function Name: orderSendMsg
  125. * @param int $order_id
  126. * @param string $template_type 使用模板类型 one:预订短信1或预定短信2(根据下单时间判断),two:出行短信,three:换车提醒短信
  127. * @return mixed
  128. *
  129. * @author 温依莅
  130. */
  131. public function orderSendMsg($order_id, $template_type = 'one')
  132. {
  133. if (!$order_id) {
  134. $json["code"] = '1';
  135. $json["info"] = '参数不正确';
  136. return $json;
  137. }
  138. $user_id = 2;//system用户
  139. //1,获得需要发送短信的内容
  140. $content_arr = $this->getMsgInfo($order_id, $template_type);
  141. //2,部分异常处理
  142. if ($content_arr == 'wrongOrderId') {
  143. $json["code"] = '2';
  144. $json["info"] = '错误订单号';
  145. return $json;
  146. }
  147. if ($content_arr == 'noRunInfo') {
  148. $json["code"] = '2';
  149. $json["info"] = '无出行信息';
  150. return $json;
  151. }
  152. if ($content_arr == 'notSend') {
  153. $json["code"] = '2';
  154. $json["info"] = '此线路票种不发送短信';
  155. return $json;
  156. }
  157. if ($content_arr == 'noTemplate') {
  158. $json["code"] = '2';
  159. $json["info"] = '模板信息缺失';
  160. return $json;
  161. }
  162. //3,根据短信相关信息发送短信
  163. $name = $content_arr[0];
  164. $tel = $content_arr[1];
  165. $content = $content_arr[2];
  166. $runInfo = isset($content_arr[3]) ? $content_arr[3] : false;
  167. $main_corp_id = $runInfo['main_corp_id'] ? $runInfo['main_corp_id'] : 1;
  168. $bus_no = trim($content_arr[4]['bus_no']);//车牌号,如果为空则认为没有派车,
  169. if (!$tel) {
  170. $json["code"] = '2';
  171. $json["info"] = '无效手机号';
  172. return $json;
  173. }
  174. //=============出行短信只有已派车的情况才发送===============//
  175. if ($template_type != 'two' || $bus_no) {
  176. $send_success = '-100'; //若最后记录为-100,说明未执行短信发送
  177. $send_success = Msg::sendTelMsg($tel, $content,$main_corp_id);
  178. //4,短信记录插入order_send_message表
  179. $current_time = date("Y-m-d H:i:s");
  180. $send_msg_values = [
  181. 'ORDER_ID' => $order_id,
  182. 'SEND_MOBILE' => $tel,
  183. 'SEND_MESSAGE' => $content,
  184. 'SEND_TIME' => $current_time,
  185. 'SEND_ERROR' => $send_success,
  186. 'CREATE_USER_ID' => $user_id,
  187. 'CREATE_TIME' => $current_time,
  188. 'UPDATE_USER_ID' => $user_id,
  189. 'UPDATE_TIME' => $current_time,
  190. ];
  191. $msgRecord = new OrderSendMessage();
  192. $msgRecord->attributes = $send_msg_values;
  193. $res = $msgRecord->insert();
  194. }
  195. //某些特殊线路发送提醒短信
  196. if ($runInfo != false && isset($runInfo["parent_prod_id"])) {
  197. if ($runInfo["parent_prod_id"] == 451538 || $runInfo["parent_prod_id"] == 451539 || $runInfo["parent_prod_id"] == 451524 || $runInfo["parent_prod_id"] == 451525 || $runInfo["parent_prod_id"] == 451560 || $runInfo["parent_prod_id"] == 451561) {
  198. // $alert_tel = "18106523772"; // 该手机号不发送短信了 modify nizf
  199. // $alert_content = "舟山希尔顿酒店有订单了,订单号({$order_id})";
  200. // Msg::sendTelMsg($alert_tel, $alert_content,$main_corp_id);
  201. } else if ($runInfo["parent_prod_id"] == 451928 || $runInfo["parent_prod_id"] == 451927 || $runInfo["parent_prod_id"] == 451926 || $runInfo["parent_prod_id"] == 451929 || $runInfo["parent_prod_id"] == 451930 || $runInfo["parent_prod_id"] == 451931) {
  202. $alert_tel = "18817847097";
  203. $alert_content = "全城接送进单了,订单号({$order_id}),出发日期:{$runInfo['start_date']}";
  204. Msg::sendTelMsg($alert_tel, $alert_content,$main_corp_id);
  205. }
  206. }
  207. $json["code"] = '0';
  208. $json["info"] = '短信已发送';
  209. $json['resCode'] = $send_success;
  210. return $json;
  211. }
  212. /**
  213. * Function Description:获取票种模板
  214. * Function Name: getTemplate
  215. * @param int $prod_id
  216. * @param int $supplier_id
  217. * @param int $line_id
  218. * @return array
  219. *
  220. * @author 温依莅
  221. */
  222. public function getTemplate($prod_id, $supplier_id, $line_id)
  223. {
  224. //按优先级:渠道票种>线路默认>系统默认 的顺序获取 最终预定成功短信
  225. #1,取默认模板
  226. $default = self::find()->where(['template_type' => 0, 'cancel_flag' => 0])->asArray()->one();
  227. $defaultContent1 = $default['content1'];
  228. $defaultContent2 = $default['content2'];
  229. $defaultContent3 = $default['content3'];
  230. $defaultContent4 = $default['content4'];
  231. $defaultContent5 = $default['content5'];
  232. $defaultContent6 = $default['content6'];
  233. #2,查询是否有该线路类型(0固定巴士线路,705动态巴士线路)的特定模板
  234. $typeContent1 = '';
  235. $typeContent2 = '';
  236. $typeContent3 = '';
  237. $res = self::find()->select(['line_id', 'tailor_type'])->from('opera_line')->where(['line_id' => $line_id])->asArray()->limit(1)->one();// 查看线路类型
  238. if ($res) {
  239. $line_type = $res['tailor_type'];
  240. $type_res = self::find()->where(['line_type' => $line_type, 'cancel_flag' => 0, 'template_type' => 3])->asArray()->one();
  241. $typeContent1 = isset($type_res['content1']) ? $type_res['content1'] : '';
  242. $typeContent2 = isset($type_res['content2']) ? $type_res['content2'] : '';
  243. $typeContent3 = isset($type_res['content3']) ? $type_res['content3'] : '';
  244. }
  245. #3,查询是否有该线路的特定的模板
  246. $lineContent1 = '';
  247. $lineContent2 = '';
  248. $lineContent3 = '';
  249. //3.1 温州市到舟山市450588,舟山市到温州市450589的线路模板
  250. if (in_array($line_id, array(450588, 450589))) {
  251. $lineContent1 = $defaultContent1 . '紧急联系电话:18100158199。';
  252. $lineContent2 = $defaultContent2 . '紧急联系电话:18100158199。';
  253. }
  254. //3.3 杭州市-普陀山450517,普陀山-杭州450522
  255. if ($line_id == 450517) {
  256. $lineContent1 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。紧急电话:15888866564。';
  257. $lineContent2 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。紧急电话:15888866564。';
  258. } else if ($line_id == 450522) {
  259. $lineContent1 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。紧急电话:15888866564。';
  260. $lineContent2 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。紧急电话:15888866564。';
  261. }
  262. #4,查询是否有该票种该渠道的特定模板
  263. $prod = self::find()->where(['ticket_id' => $prod_id, 'supplier_id' => $supplier_id, 'cancel_flag' => 0, 'template_type' => 2])->asArray()->one();
  264. $prodContent1 = isset($prod['content1']) ? $prod['content1'] : '';
  265. $prodContent2 = isset($prod['content2']) ? $prod['content2'] : '';
  266. $prodContent3 = isset($prod['content3']) ? $prod['content3'] : '';
  267. //5,按优先级:渠道票种>线路模板>线路类型模板>系统默认 的顺序 生成最终 的模板数组(包括:预订成功1,预订成功2,出行提醒短信3)
  268. $final = array();
  269. $final['content1'] = $prodContent1 ? $prodContent1 : ($lineContent1 ? $lineContent1 : ($typeContent1 ? $typeContent1 : $defaultContent1));
  270. $final['content2'] = $prodContent2 ? $prodContent2 : ($lineContent2 ? $lineContent2 : ($typeContent2 ? $typeContent2 : $defaultContent2));
  271. $final['content3'] = $prodContent3 ? $prodContent3 : ($lineContent3 ? $lineContent3 : ($typeContent3 ? $typeContent3 : $defaultContent3));
  272. $final['content4'] = $defaultContent4;
  273. $final['content5'] = $defaultContent5;
  274. $final['content6'] = $defaultContent6;
  275. return $final;
  276. }
  277. /**
  278. * Function Description:获取下单应发短信内容
  279. * Function Name: getMsgInfo
  280. * @param int $order_id
  281. * @param string $type :one,预定短信 two,出行短信 three 新的出行短信
  282. * @return array
  283. *
  284. * @author 温依莅
  285. */
  286. public function getMsgInfo($order_id, $type = 'one')
  287. {
  288. //1获取短信模板所需参数
  289. #1.1,获取出发时间,地点run_info
  290. $runInfo = self::find()->select([
  291. 'count(a.id) as order_count',
  292. 'a.create_time as create_time',
  293. 'a.prod_start_station_date as start_date',
  294. 'a.prod_start_station_time as start_time',
  295. 'a.prod_end_station_date as end_date',
  296. 'a.prod_end_station_time as end_time',
  297. 'a.parent_order_id as parent_order_id',
  298. 'a.prod_start_station_area_name as start_area',
  299. 'a.prod_end_station_area_name as end_area',
  300. 'a.prod_start_station_res_name as res_name',
  301. 'a.prod_end_station_res_name as end_res_name',
  302. 'a.parent_prod_id as parent_prod_id',
  303. 'a.prod_id as prod_id',
  304. 'a.outside_sale_org_id as supplier_id',
  305. 'a.prod_name as prod_name',
  306. 'group_concat(a.run_bus_seat_name) as order_seat_list',
  307. 'a.customer_name as customer_name',
  308. 'a.customer_mobile as customer_mobile',
  309. 'a.main_corp_id',
  310. 'start_station_address' => BaseResourceProperty::find()->select('property')->where('res_id = a.prod_start_station_res_id and type_id = 279')->limit(1),
  311. ])->from(OrderMain::tableName() . ' as a')
  312. ->where(['a.parent_order_id' => $order_id, 'a.cancel_flag' => 0])
  313. ->asArray()
  314. ->one();
  315. #1.2,获取司机信息
  316. $driverInfo = self::find()->select([
  317. 'a.send_bus_res_id as bus_res_id',
  318. 'a.send_bus_no as bus_no',
  319. 'a.send_driver_name as driver_name',
  320. 'a.send_driver_mobile as driver_mobile'
  321. ])->from(RunBus::tableName() . ' as a')
  322. ->innerJoin(OrderMain::tableName() . ' as b', 'a.run_id=b.run_id and a.bus_order_id=b.run_bus_order_id')
  323. ->where(['a.cancel_flag' => 0, 'b.parent_order_id' => $order_id])
  324. ->groupBy('a.run_id')
  325. ->asArray()
  326. ->one();
  327. #1.3,部分异常处理
  328. if (($runInfo['order_count'] == 0 && $runInfo['prod_id'] == null) || $runInfo['parent_order_id'] == 0) {
  329. return 'wrongOrderId';
  330. }
  331. if (!$runInfo) {
  332. return 'noRunInfo';//无出行信息
  333. }
  334. if ($type == 'two') {
  335. $notSendLine = array(152690, 152703, 451023, 451024, 451025, 451026, 451027, 451028, 451440, 451441, 448780, 450008, 448781, 451623, 451624, 451625, 451626, 451627, 451628, 451629, 451630, 451636, 451637, 451671, 451874, 451875, 451868, 451869);//不发送出行短信的线路
  336. } else {
  337. $notSendLine = array(451023, 451024, 451025, 451026, 451027, 451028, 451623, 451624, 451625, 451626, 451627, 451628, 451629, 451630, 451636, 451637, 451671, 451874, 451875, 451868, 451869);//不发送预定短信的线路 451926,451927,451928,451929,451930,451931
  338. }
  339. if (in_array($runInfo['parent_prod_id'], $notSendLine)) {
  340. return 'notSend';
  341. }
  342. //2,获取短信模板
  343. #根据order_id获取该订单线路拥有者的售卖渠道id
  344. $supplier_id = $this->getOwnerSupplier($order_id);
  345. $final = $this->getTemplate($runInfo['prod_id'], $supplier_id, $runInfo['parent_prod_id']);
  346. if (!$final['content1'] || !$final['content2']) {
  347. return 'noTemplate';//模板信息缺失;
  348. }
  349. //3,处理短信模板,得到真实发送的短信信息
  350. $tomorrow = date("Y-m-d", strtotime("+1 day"));//明天日期
  351. $now_time = date('Y-m-d H:i', time()); //现在时间
  352. $today = date('Y-m-d', time()); //今天日期
  353. #3.1获取ticket短链接
  354. $long_url = 'http://ticket.' . DOMAIN . '/ticket.php?orderid=' . $order_id;
  355. $shortUrl = Msg::sinaShortenUrl($long_url);
  356. #3.2不同时间下单选用不同短信模板
  357. if ($type == 'two') { //如果是出行短信,直接采用模板3
  358. $content = $final['content3'];
  359. } else if ($type == 'three') { //如果是出行短信,直接采用模板3
  360. $content = $final['content4'];
  361. } else if ($type == 'four') { //如果是出行短信,直接采用模板3
  362. $content = $final['content5'];
  363. } else if ($type == 'five') { //如果是出行短信,直接采用模板3
  364. $content = $final['content6'];
  365. } else {
  366. $pre_hour = date("Y-m-d H:i", strtotime($runInfo['start_date'] . " " . $runInfo['start_time'] . " -1 hours"));
  367. if ($now_time > $pre_hour) { //发车前1小时之内才会发送带有座位参数的短信
  368. $content = $final['content2'];
  369. } else {
  370. $content = $final['content1'];
  371. }
  372. }
  373. #3.3根据runInfo替换短信模板信息
  374. //{订单号}{出发地}{上车站点}{目的地}{下车站点}){车票张数}{出发日期}{出发时间}{车牌号}{司机姓司机电话}{上车站点详细地址}{车票链接}
  375. $order_count = $runInfo['order_count'] ? $runInfo['order_count'] : '';//订单数
  376. $start_date = $runInfo['start_date'] ? $runInfo['start_date'] : ''; //出发日期
  377. $start_time = $runInfo['start_time'] ? $runInfo['start_time'] : ''; //出发时间
  378. $start_area = $runInfo['start_area'] ? $runInfo['start_area'] : ''; //出发地
  379. $end_area = $runInfo['end_area'] ? $runInfo['end_area'] : ''; //目的地
  380. $res_name = $runInfo['res_name'] ? $runInfo['res_name'] : ''; //上车站点
  381. $end_res_name = $runInfo['end_res_name'] ? $runInfo['end_res_name'] : ''; //下车站点
  382. $start_station_address = $runInfo['start_station_address'] ? $runInfo['start_station_address'] : '';//上车详细地址
  383. $customer_name = $runInfo['customer_name'];
  384. $customer_mobile = $runInfo['customer_mobile'];
  385. $content = str_replace("{下车站点}", $end_res_name, $content);
  386. $content = str_replace("{出发日期}", $start_date, $content);
  387. $content = str_replace("{出发时间}", $start_time, $content);
  388. $content = str_replace("{上车站点}", $res_name, $content);
  389. $content = str_replace("{出发地}", $start_area, $content);
  390. $content = str_replace("{目的地}", $end_area, $content);
  391. $content = str_replace("{车票张数}", $order_count, $content);
  392. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  393. $content = str_replace("{订单号}", $order_id, $content);
  394. $content = str_replace("{车票链接}", $shortUrl, $content);
  395. $order_seat_list = str_replace(",", "/", $runInfo["order_seat_list"]);
  396. $content = str_replace("{座位号}", $order_seat_list, $content);
  397. if ($driverInfo) {
  398. $bus_no = $driverInfo['bus_no'] ? $driverInfo['bus_no'] : "";
  399. $driver_name = $driverInfo['driver_name'] ? $driverInfo['driver_name'] : "";
  400. $driver_mobile = $driverInfo['driver_mobile'] ? $driverInfo['driver_mobile'] : "";
  401. if ($bus_no == "") {
  402. $content = str_replace("车牌号{车牌号}", "", $content);
  403. } else {
  404. $content = str_replace("{车牌号}", $bus_no, $content);
  405. }
  406. if ($driver_name == "") {
  407. $content = str_replace(",司机电话{司机姓司机电话},", "", $content);
  408. } else {
  409. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  410. $driver_name_mobile = $driver_xing . $driver_mobile;
  411. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  412. $content = str_replace("{司机号码}", $driver_name_mobile, $content);
  413. }
  414. } else {
  415. $content = str_replace("车牌号{车牌号},", "", $content);
  416. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  417. }
  418. #4,返回发送短信相关信息
  419. return array($customer_name, $customer_mobile, $content, $runInfo, $driverInfo);
  420. }
  421. /**
  422. * Function Description:获取该订单对应的线路实际拥有者
  423. * Function Name: getOwnerSupplier
  424. * @param int $order_id 订单号
  425. *
  426. * @return int
  427. *
  428. * @author 温依莅
  429. */
  430. public function getOwnerSupplier($order_id)
  431. {
  432. //订单基本信息
  433. $order_res = self::find()->select([
  434. 'parent_order_id',
  435. 'outside_sale_org_id',
  436. 'sale_path',
  437. 'agent_level'
  438. ])->from(OrderMain::tableName())
  439. ->where(['parent_order_id' => $order_id, 'cancel_flag' => 0])
  440. ->asArray()
  441. ->one();
  442. $supplier_id = $order_res['outside_sale_org_id'];
  443. //判断是否是代售,如果是代售,更新渠道为 线路拥有者的售卖渠道
  444. if ($order_res['sale_path']) {
  445. $sale_path_arr = explode(',', $order_res['sale_path']);
  446. $owner_order_id = end($sale_path_arr);
  447. $res = self::find()->select([
  448. 'parent_order_id',
  449. 'outside_sale_org_id',
  450. 'sale_path',
  451. 'agent_level'
  452. ])->from(OrderMain::tableName())
  453. ->where(['parent_order_id' => $owner_order_id, 'cancel_flag' => 0])
  454. ->asArray()
  455. ->one();
  456. $owner_supplier_id = $res['outside_sale_org_id'];
  457. $supplier_id = $owner_supplier_id;
  458. }
  459. return $supplier_id;
  460. }
  461. public function getGroupSuccessMsgInfo($order_id)
  462. {
  463. //1获取短信模板所需参数
  464. #1.1,获取组合订单信息
  465. $orderInfo = self::find()->select([
  466. 'order_title_id',
  467. 'cus_name',
  468. 'cus_phone'
  469. ])->from(OrderTitle::tableName())
  470. ->where(['order_title_id' => $order_id])
  471. ->asArray()
  472. ->one();
  473. #1.3,部分异常处理
  474. if (!$orderInfo) {
  475. return false;//无出行信息
  476. }
  477. //2,获取短信模板
  478. $final = $this->getTemplate(0, 0, 0);
  479. if (!$final || !isset($final['content5'])) {
  480. return false;//模板信息缺失;
  481. }
  482. $content = $final['content5'];
  483. $customer_name = $orderInfo["cus_name"];
  484. $customer_mobile = $orderInfo["cus_phone"];
  485. #3.3根据runInfo替换短信模板信息
  486. //{订单号}{出发地}{上车站点}{目的地}{下车站点}){车票张数}{出发日期}{出发时间}{车牌号}{司机姓司机电话}{上车站点详细地址}{车票链接}
  487. $content = str_replace("{订单号}", $order_id, $content);
  488. #4,返回发送短信相关信息
  489. return array($customer_name, $customer_mobile, $content);
  490. }
  491. public function sendBusChangeRemindMsg($run_start_time, $itinerary_name, $new_bus_no)
  492. {
  493. $send_txt = "出行车辆变更通知:{$run_start_time}出发的{$itinerary_name}的车辆已变更为{$new_bus_no},请及时和车调人员进行确认!";
  494. $send_mobile = "18817847097,13625816476";
  495. Msg::sendTelMsg($send_mobile, $send_txt);
  496. }
  497. public function sendNewUserRemindMsg($run_id, $bus_order_id, $send_bus_count = 1)
  498. {
  499. $model_order_main = new OrderMain();
  500. $need_send_id_array = $model_order_main->getOrderArrayFromRunbus($run_id, $bus_order_id);
  501. $message_template = $send_bus_count <= 1 ? "two" : "three";
  502. foreach ($need_send_id_array as $order_info) {
  503. $order_id = $order_info["parent_order_id"];
  504. $send_mobile = $order_info["customer_mobile"];
  505. $send_message = $this->getMsgInfo($order_id, $message_template);
  506. if ($send_message == "notSend") {
  507. continue;
  508. }
  509. $send_success = Msg::sendTelMsg($send_message[1], $send_message[2],$order_info['main_corp_id']);
  510. //短信记录插入order_send_message表
  511. $current_time = date("Y-m-d H:i:s");
  512. $send_msg_values = [
  513. 'ORDER_ID' => $order_id,
  514. 'SEND_MOBILE' => $send_message[1],
  515. 'SEND_MESSAGE' => $send_message[2],
  516. 'SEND_TIME' => $current_time,
  517. 'SEND_ERROR' => $send_success,
  518. 'CREATE_USER_ID' => 2,
  519. 'CREATE_TIME' => $current_time,
  520. 'UPDATE_USER_ID' => 2,
  521. 'UPDATE_TIME' => $current_time,
  522. ];
  523. $msgRecord = new OrderSendMessage();
  524. $msgRecord->attributes = $send_msg_values;
  525. $res = $msgRecord->insert();
  526. }
  527. }
  528. public function addSuccessMessage($order_id, $send_mobile, $send_txt)
  529. {
  530. $insert_sql = " INSERT INTO send_bus_success_message (id, order_id, create_time,send_flag,send_mobile,send_message )
  531. VALUES (NULL,{$order_id},now(),0,'{$send_mobile}','{$send_txt}');";
  532. $res = Yii::$app->db->createCommand($insert_sql)->execute();
  533. }
  534. /**
  535. * Function Description:发送短信白名单添加
  536. * Function Name: insertAppointSendMessage
  537. * @param $order_id
  538. *
  539. * @return mixed
  540. *
  541. * @author LUOCJ
  542. */
  543. public function insertAppointSendMessage($order_id)
  544. {
  545. $model = AppointSendMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
  546. if ($model) {
  547. $json['code'] = '1';
  548. $json['info'] = '该数据已存在,不能重复添加';
  549. return $json;
  550. }
  551. $model = new AppointSendMessage();
  552. $now = date('Y-m-d H:i:s');
  553. $user = 1;
  554. $model->create_time = $model->update_time = $now;
  555. $model->create_user_id = $model->update_user_id = $user;
  556. $model->cancel_flag = 0;
  557. $model->order_id = $order_id;
  558. if (!$model->save()) {
  559. $json['code'] = '2';
  560. $json['info'] = '保存失败,请检查数据' . $model->getFirstError();
  561. return $json;
  562. }
  563. $json['code'] = '0';
  564. $json['info'] = '保存成功';
  565. return $json;
  566. }
  567. public function cancelAppointSendMessage($order_id)
  568. {
  569. $model = AppointSendMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
  570. if (!$model) {
  571. $json['code'] = '1';
  572. $json['info'] = '该数据不存在,请检查订单号';
  573. return $json;
  574. }
  575. $model->cancel_flag = 1;
  576. if (!$model->save()) {
  577. $json['code'] = '2';
  578. $json['info'] = '删除白名单失败,请检查数据';
  579. return $json;
  580. }
  581. $json['code'] = '0';
  582. $json['info'] = '刪除成功';
  583. return $json;
  584. }
  585. /**
  586. * Function Description:发送短信白名单添加
  587. * Function Name: insertAppointSendMessage
  588. * @param $order_id
  589. *
  590. * @return mixed
  591. *
  592. * @author LUOCJ
  593. */
  594. public function insertWechatClickMessage($order_id)
  595. {
  596. $model = WechatClickMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
  597. if ($model) {
  598. $json['code'] = '1';
  599. $json['info'] = '该数据已存在,不能重复添加';
  600. return $json;
  601. }
  602. $model = new WechatClickMessage();
  603. $now = date('Y-m-d H:i:s');
  604. $user = 1;
  605. $model->create_time = $model->update_time = $now;
  606. $model->create_user_id = $model->update_user_id = $user;
  607. $model->cancel_flag = 0;
  608. $model->order_id = $order_id;
  609. if (!$model->save()) {
  610. $json['code'] = '2';
  611. $json['info'] = '保存失败,请检查数据';
  612. return $json;
  613. }
  614. $json['code'] = '0';
  615. $json['info'] = '保存成功';
  616. return $json;
  617. }
  618. public function cancelWechatClickMessage($order_id)
  619. {
  620. $model = WechatClickMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
  621. if (!$model) {
  622. $json['code'] = '1';
  623. $json['info'] = '该数据不存在,请检查订单号';
  624. return $json;
  625. }
  626. $model->cancel_flag = 1;
  627. if (!$model->save()) {
  628. $json['code'] = '2';
  629. $json['info'] = '删除失败,请检查数据';
  630. return $json;
  631. }
  632. $json['code'] = '0';
  633. $json['info'] = '刪除成功';
  634. return $json;
  635. }
  636. /**
  637. * Function Description:下单发送短信
  638. * Function Name: orderSendMsg
  639. * @param int $order_id
  640. * @param string $template_type 使用模板类型 one:预订短信1或预定短信2(根据下单时间判断),two:出行短信,three:换车提醒短信
  641. * @return mixed
  642. *
  643. * @author 邱颂
  644. */
  645. public function orderSendFreeMsg($order_id, $user_id, $send_message)
  646. {
  647. if (!$order_id) {
  648. $json["code"] = '1';
  649. $json["info"] = '参数不正确';
  650. return $json;
  651. }
  652. //1,获得需要发送的手机号码
  653. $order_main_info = OrderMain::findOne(["ORDER_ID" => $order_id]);
  654. if (!$order_main_info) {
  655. $json["code"] = '1';
  656. $json["info"] = '参数不正确';
  657. return $json;
  658. }
  659. $send_tel = $order_main_info->CUSTOMER_MOBILE;
  660. $send_success = '-100'; //若最后记录为-100,说明未执行短信发送
  661. $send_success = Msg::sendTelMsg($send_tel, $send_message,$order_main_info->MAIN_CORP_ID);
  662. //2,短信记录插入order_send_message表
  663. $current_time = date("Y-m-d H:i:s");
  664. $send_msg_values = [
  665. 'ORDER_ID' => $order_id,
  666. 'SEND_MOBILE' => $send_tel,
  667. 'SEND_MESSAGE' => $send_message,
  668. 'SEND_TIME' => $current_time,
  669. 'SEND_ERROR' => $send_success,
  670. 'CREATE_USER_ID' => $user_id,
  671. 'CREATE_TIME' => $current_time,
  672. 'UPDATE_USER_ID' => $user_id,
  673. 'UPDATE_TIME' => $current_time,
  674. ];
  675. $msgRecord = new OrderSendMessage();
  676. $msgRecord->attributes = $send_msg_values;
  677. $res = $msgRecord->insert();
  678. $json["code"] = '0';
  679. $json["info"] = '短信已发送';
  680. $json['resCode'] = $send_success;
  681. return $json;
  682. }
  683. }