|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- <?php
-
- namespace backend\modules\api\models;
-
- use yii\db\ActiveRecord;
- use yii\base\Exception;
- use common\models\Msg;
- use backend\modules\api\models\OrderMain;
- use Yii;
-
- /**
- * This is the model class for table "opera_message_template".
- *
- * @property integer $id
- * @property integer $supplier_id
- * @property integer $ticket_group_id
- * @property integer $ticket_id
- * @property string $content1
- * @property string $content2
- * @property string $content3
- * @property string $content4
- * @property string $content5
- * @property integer $create_user_id
- * @property string $create_time
- * @property integer $update_user_id
- * @property string $update_time
- * @property integer $template_type
- * @property integer $cancel_flag
- */
- class OperaMessageTemplate extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_message_template';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['supplier_id', 'ticket_group_id', 'ticket_id', 'create_user_id', 'update_user_id', 'template_type', 'cancel_flag'], 'integer'],
- [['ticket_group_id', 'ticket_id', 'content1', 'content2', 'content3', 'content4', 'content5', 'content6'], 'required'],
- [['content1', 'content2', 'content3', 'content4', 'content5', 'content6'], 'string'],
- [['create_time', 'update_time'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'supplier_id' => 'Supplier ID',
- 'ticket_group_id' => 'Ticket Group ID',
- 'ticket_id' => 'Ticket ID',
- 'content1' => 'Content1',
- 'content2' => 'Content2',
- 'content3' => 'Content3',
- 'content4' => 'Content4',
- 'content5' => 'Content5',
- 'content6' => 'Content6',
- 'create_user_id' => 'Create User ID',
- 'create_time' => 'Create Time',
- 'update_user_id' => 'Update User ID',
- 'update_time' => 'Update Time',
- 'template_type' => 'Template Type',
- 'cancel_flag' => 'Cancel Flag',
- ];
- }
-
- /**
- * Function Description:OTA获取短信内容
- * Function Name: otaGetMsg
- * @param int $order_id
- * @param string $type :one 预定短信, two 出行短信
- * @return mixed
- *
- * @author 温依莅
- */
- public function otaGetMsgInfo($order_id, $type = 'one')
- {
- $json = array();
- if (!$order_id) {
- $json["code"] = '1';
- $json["info"] = '参数不正确';
- return $json;
- }
- //1,根据order_id获得短信内容
- $content_arr = $this->getMsgInfo($order_id, $type);
- //2,部分异常处理
- if ($content_arr == 'noRunInfo') {
- $json["code"] = '2';
- $json["info"] = '无出行信息';
- return $json;
- }
- if ($content_arr == 'notSend') {
- $json["code"] = '3';
- $json["info"] = '此线路票种不发送短信';
- return $json;
- }
- if ($content_arr == 'noTemplate') {
- $json["code"] = '4';
- $json["info"] = '模板信息缺失';
- return $json;
- }
- if ($content_arr == 'wrongOrderId') {
- $json["code"] = '5';
- $json["info"] = '错误订单号';
- return $json;
- }
-
- $name = $content_arr[0];
- $tel = $content_arr[1];
- $content = $content_arr[2];
-
-
- $json["code"] = '0';
- $json["info"] = '获取成功';
- $json['name'] = $name;
- $json['mobile'] = $tel;
- $json['content'] = $content;
- return $json;
- }
-
- /**
- * Function Description:下单发送短信
- * Function Name: orderSendMsg
- * @param int $order_id
- * @param string $template_type 使用模板类型 one:预订短信1或预定短信2(根据下单时间判断),two:出行短信,three:换车提醒短信
- * @return mixed
- *
- * @author 温依莅
- */
- public function orderSendMsg($order_id, $template_type = 'one')
- {
- if (!$order_id) {
- $json["code"] = '1';
- $json["info"] = '参数不正确';
- return $json;
- }
- $user_id = 2;//system用户
-
- //1,获得需要发送短信的内容
- $content_arr = $this->getMsgInfo($order_id, $template_type);
- //2,部分异常处理
- if ($content_arr == 'wrongOrderId') {
- $json["code"] = '2';
- $json["info"] = '错误订单号';
- return $json;
- }
- if ($content_arr == 'noRunInfo') {
- $json["code"] = '2';
- $json["info"] = '无出行信息';
- return $json;
- }
- if ($content_arr == 'notSend') {
- $json["code"] = '2';
- $json["info"] = '此线路票种不发送短信';
- return $json;
- }
- if ($content_arr == 'noTemplate') {
- $json["code"] = '2';
- $json["info"] = '模板信息缺失';
- return $json;
- }
- //3,根据短信相关信息发送短信
- $name = $content_arr[0];
- $tel = $content_arr[1];
- $content = $content_arr[2];
- $runInfo = isset($content_arr[3]) ? $content_arr[3] : false;
- $main_corp_id = $runInfo['main_corp_id'] ? $runInfo['main_corp_id'] : 1;
- $bus_no = trim($content_arr[4]['bus_no']);//车牌号,如果为空则认为没有派车,
- if (!$tel) {
- $json["code"] = '2';
- $json["info"] = '无效手机号';
- return $json;
- }
- //=============出行短信只有已派车的情况才发送===============//
- if ($template_type != 'two' || $bus_no) {
- $send_success = '-100'; //若最后记录为-100,说明未执行短信发送
-
- $send_success = Msg::sendTelMsg($tel, $content,$main_corp_id);
-
- //4,短信记录插入order_send_message表
- $current_time = date("Y-m-d H:i:s");
- $send_msg_values = [
- 'ORDER_ID' => $order_id,
- 'SEND_MOBILE' => $tel,
- 'SEND_MESSAGE' => $content,
- 'SEND_TIME' => $current_time,
- 'SEND_ERROR' => $send_success,
- 'CREATE_USER_ID' => $user_id,
- 'CREATE_TIME' => $current_time,
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => $current_time,
- ];
- $msgRecord = new OrderSendMessage();
- $msgRecord->attributes = $send_msg_values;
- $res = $msgRecord->insert();
- }
-
-
- //某些特殊线路发送提醒短信
- if ($runInfo != false && isset($runInfo["parent_prod_id"])) {
- 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) {
- // $alert_tel = "18106523772"; // 该手机号不发送短信了 modify nizf
- // $alert_content = "舟山希尔顿酒店有订单了,订单号({$order_id})";
- // Msg::sendTelMsg($alert_tel, $alert_content,$main_corp_id);
- } 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) {
- $alert_tel = "18817847097";
- $alert_content = "全城接送进单了,订单号({$order_id}),出发日期:{$runInfo['start_date']}";
- Msg::sendTelMsg($alert_tel, $alert_content,$main_corp_id);
- }
- }
-
- $json["code"] = '0';
- $json["info"] = '短信已发送';
- $json['resCode'] = $send_success;
- return $json;
- }
-
- /**
- * Function Description:获取票种模板
- * Function Name: getTemplate
- * @param int $prod_id
- * @param int $supplier_id
- * @param int $line_id
- * @return array
- *
- * @author 温依莅
- */
- public function getTemplate($prod_id, $supplier_id, $line_id)
- {
- //按优先级:渠道票种>线路默认>系统默认 的顺序获取 最终预定成功短信
-
- #1,取默认模板
- $default = self::find()->where(['template_type' => 0, 'cancel_flag' => 0])->asArray()->one();
- $defaultContent1 = $default['content1'];
- $defaultContent2 = $default['content2'];
- $defaultContent3 = $default['content3'];
- $defaultContent4 = $default['content4'];
- $defaultContent5 = $default['content5'];
- $defaultContent6 = $default['content6'];
- #2,查询是否有该线路类型(0固定巴士线路,705动态巴士线路)的特定模板
- $typeContent1 = '';
- $typeContent2 = '';
- $typeContent3 = '';
- $res = self::find()->select(['line_id', 'tailor_type'])->from('opera_line')->where(['line_id' => $line_id])->asArray()->limit(1)->one();// 查看线路类型
- if ($res) {
- $line_type = $res['tailor_type'];
- $type_res = self::find()->where(['line_type' => $line_type, 'cancel_flag' => 0, 'template_type' => 3])->asArray()->one();
- $typeContent1 = isset($type_res['content1']) ? $type_res['content1'] : '';
- $typeContent2 = isset($type_res['content2']) ? $type_res['content2'] : '';
- $typeContent3 = isset($type_res['content3']) ? $type_res['content3'] : '';
- }
- #3,查询是否有该线路的特定的模板
- $lineContent1 = '';
- $lineContent2 = '';
- $lineContent3 = '';
- //3.1 温州市到舟山市450588,舟山市到温州市450589的线路模板
- if (in_array($line_id, array(450588, 450589))) {
- $lineContent1 = $defaultContent1 . '紧急联系电话:18100158199。';
- $lineContent2 = $defaultContent2 . '紧急联系电话:18100158199。';
- }
- //3.3 杭州市-普陀山450517,普陀山-杭州450522
- if ($line_id == 450517) {
- $lineContent1 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。紧急电话:15888866564。';
- $lineContent2 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。紧急电话:15888866564。';
- } else if ($line_id == 450522) {
- $lineContent1 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。紧急电话:15888866564。';
- $lineContent2 = '您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{车票张数}张(请最晚提前10分钟到达)。上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。紧急电话:15888866564。';
- }
-
- #4,查询是否有该票种该渠道的特定模板
- $prod = self::find()->where(['ticket_id' => $prod_id, 'supplier_id' => $supplier_id, 'cancel_flag' => 0, 'template_type' => 2])->asArray()->one();
- $prodContent1 = isset($prod['content1']) ? $prod['content1'] : '';
- $prodContent2 = isset($prod['content2']) ? $prod['content2'] : '';
- $prodContent3 = isset($prod['content3']) ? $prod['content3'] : '';
-
- //5,按优先级:渠道票种>线路模板>线路类型模板>系统默认 的顺序 生成最终 的模板数组(包括:预订成功1,预订成功2,出行提醒短信3)
- $final = array();
- $final['content1'] = $prodContent1 ? $prodContent1 : ($lineContent1 ? $lineContent1 : ($typeContent1 ? $typeContent1 : $defaultContent1));
- $final['content2'] = $prodContent2 ? $prodContent2 : ($lineContent2 ? $lineContent2 : ($typeContent2 ? $typeContent2 : $defaultContent2));
- $final['content3'] = $prodContent3 ? $prodContent3 : ($lineContent3 ? $lineContent3 : ($typeContent3 ? $typeContent3 : $defaultContent3));
- $final['content4'] = $defaultContent4;
- $final['content5'] = $defaultContent5;
- $final['content6'] = $defaultContent6;
-
- return $final;
- }
-
- /**
- * Function Description:获取下单应发短信内容
- * Function Name: getMsgInfo
- * @param int $order_id
- * @param string $type :one,预定短信 two,出行短信 three 新的出行短信
- * @return array
- *
- * @author 温依莅
- */
- public function getMsgInfo($order_id, $type = 'one')
- {
- //1获取短信模板所需参数
- #1.1,获取出发时间,地点run_info
- $runInfo = self::find()->select([
- 'count(a.id) as order_count',
- 'a.create_time as create_time',
- 'a.prod_start_station_date as start_date',
- 'a.prod_start_station_time as start_time',
- 'a.prod_end_station_date as end_date',
- 'a.prod_end_station_time as end_time',
- 'a.parent_order_id as parent_order_id',
- 'a.prod_start_station_area_name as start_area',
- 'a.prod_end_station_area_name as end_area',
- 'a.prod_start_station_res_name as res_name',
- 'a.prod_end_station_res_name as end_res_name',
- 'a.parent_prod_id as parent_prod_id',
- 'a.prod_id as prod_id',
- 'a.outside_sale_org_id as supplier_id',
- 'a.prod_name as prod_name',
- 'group_concat(a.run_bus_seat_name) as order_seat_list',
- 'a.customer_name as customer_name',
- 'a.customer_mobile as customer_mobile',
- 'a.main_corp_id',
- 'start_station_address' => BaseResourceProperty::find()->select('property')->where('res_id = a.prod_start_station_res_id and type_id = 279')->limit(1),
- ])->from(OrderMain::tableName() . ' as a')
- ->where(['a.parent_order_id' => $order_id, 'a.cancel_flag' => 0])
- ->asArray()
- ->one();
-
- #1.2,获取司机信息
- $driverInfo = self::find()->select([
- 'a.send_bus_res_id as bus_res_id',
- 'a.send_bus_no as bus_no',
- 'a.send_driver_name as driver_name',
- 'a.send_driver_mobile as driver_mobile'
- ])->from(RunBus::tableName() . ' as a')
- ->innerJoin(OrderMain::tableName() . ' as b', 'a.run_id=b.run_id and a.bus_order_id=b.run_bus_order_id')
- ->where(['a.cancel_flag' => 0, 'b.parent_order_id' => $order_id])
- ->groupBy('a.run_id')
- ->asArray()
- ->one();
- #1.3,部分异常处理
- if (($runInfo['order_count'] == 0 && $runInfo['prod_id'] == null) || $runInfo['parent_order_id'] == 0) {
- return 'wrongOrderId';
- }
- if (!$runInfo) {
- return 'noRunInfo';//无出行信息
- }
-
- if ($type == 'two') {
- $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);//不发送出行短信的线路
- } else {
- $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
- }
-
- if (in_array($runInfo['parent_prod_id'], $notSendLine)) {
- return 'notSend';
- }
- //2,获取短信模板
- #根据order_id获取该订单线路拥有者的售卖渠道id
- $supplier_id = $this->getOwnerSupplier($order_id);
- $final = $this->getTemplate($runInfo['prod_id'], $supplier_id, $runInfo['parent_prod_id']);
-
- if (!$final['content1'] || !$final['content2']) {
- return 'noTemplate';//模板信息缺失;
- }
-
- //3,处理短信模板,得到真实发送的短信信息
-
- $tomorrow = date("Y-m-d", strtotime("+1 day"));//明天日期
- $now_time = date('Y-m-d H:i', time()); //现在时间
- $today = date('Y-m-d', time()); //今天日期
-
- #3.1获取ticket短链接
- $long_url = 'http://ticket.' . DOMAIN . '/ticket.php?orderid=' . $order_id;
- $shortUrl = Msg::sinaShortenUrl($long_url);
-
- #3.2不同时间下单选用不同短信模板
- if ($type == 'two') { //如果是出行短信,直接采用模板3
- $content = $final['content3'];
- } else if ($type == 'three') { //如果是出行短信,直接采用模板3
- $content = $final['content4'];
- } else if ($type == 'four') { //如果是出行短信,直接采用模板3
- $content = $final['content5'];
- } else if ($type == 'five') { //如果是出行短信,直接采用模板3
- $content = $final['content6'];
- } else {
- $pre_hour = date("Y-m-d H:i", strtotime($runInfo['start_date'] . " " . $runInfo['start_time'] . " -1 hours"));
- if ($now_time > $pre_hour) { //发车前1小时之内才会发送带有座位参数的短信
- $content = $final['content2'];
- } else {
- $content = $final['content1'];
- }
- }
- #3.3根据runInfo替换短信模板信息
- //{订单号}{出发地}{上车站点}{目的地}{下车站点}){车票张数}{出发日期}{出发时间}{车牌号}{司机姓司机电话}{上车站点详细地址}{车票链接}
-
- $order_count = $runInfo['order_count'] ? $runInfo['order_count'] : '';//订单数
- $start_date = $runInfo['start_date'] ? $runInfo['start_date'] : ''; //出发日期
- $start_time = $runInfo['start_time'] ? $runInfo['start_time'] : ''; //出发时间
- $start_area = $runInfo['start_area'] ? $runInfo['start_area'] : ''; //出发地
- $end_area = $runInfo['end_area'] ? $runInfo['end_area'] : ''; //目的地
- $res_name = $runInfo['res_name'] ? $runInfo['res_name'] : ''; //上车站点
- $end_res_name = $runInfo['end_res_name'] ? $runInfo['end_res_name'] : ''; //下车站点
- $start_station_address = $runInfo['start_station_address'] ? $runInfo['start_station_address'] : '';//上车详细地址
-
- $customer_name = $runInfo['customer_name'];
- $customer_mobile = $runInfo['customer_mobile'];
-
-
- $content = str_replace("{下车站点}", $end_res_name, $content);
- $content = str_replace("{出发日期}", $start_date, $content);
- $content = str_replace("{出发时间}", $start_time, $content);
- $content = str_replace("{上车站点}", $res_name, $content);
- $content = str_replace("{出发地}", $start_area, $content);
- $content = str_replace("{目的地}", $end_area, $content);
-
- $content = str_replace("{车票张数}", $order_count, $content);
- $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
- $content = str_replace("{订单号}", $order_id, $content);
-
- $content = str_replace("{车票链接}", $shortUrl, $content);
- $order_seat_list = str_replace(",", "/", $runInfo["order_seat_list"]);
- $content = str_replace("{座位号}", $order_seat_list, $content);
-
- if ($driverInfo) {
- $bus_no = $driverInfo['bus_no'] ? $driverInfo['bus_no'] : "";
- $driver_name = $driverInfo['driver_name'] ? $driverInfo['driver_name'] : "";
- $driver_mobile = $driverInfo['driver_mobile'] ? $driverInfo['driver_mobile'] : "";
-
- if ($bus_no == "") {
- $content = str_replace("车牌号{车牌号}", "", $content);
- } else {
- $content = str_replace("{车牌号}", $bus_no, $content);
- }
- if ($driver_name == "") {
- $content = str_replace(",司机电话{司机姓司机电话},", "", $content);
- } else {
- $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
- $driver_name_mobile = $driver_xing . $driver_mobile;
- $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
- $content = str_replace("{司机号码}", $driver_name_mobile, $content);
- }
- } else {
- $content = str_replace("车牌号{车牌号},", "", $content);
- $content = str_replace("司机电话{司机姓司机电话},", "", $content);
- }
-
- #4,返回发送短信相关信息
- return array($customer_name, $customer_mobile, $content, $runInfo, $driverInfo);
-
- }
-
- /**
- * Function Description:获取该订单对应的线路实际拥有者
- * Function Name: getOwnerSupplier
- * @param int $order_id 订单号
- *
- * @return int
- *
- * @author 温依莅
- */
- public function getOwnerSupplier($order_id)
- {
- //订单基本信息
- $order_res = self::find()->select([
- 'parent_order_id',
- 'outside_sale_org_id',
- 'sale_path',
- 'agent_level'
- ])->from(OrderMain::tableName())
- ->where(['parent_order_id' => $order_id, 'cancel_flag' => 0])
- ->asArray()
- ->one();
- $supplier_id = $order_res['outside_sale_org_id'];
- //判断是否是代售,如果是代售,更新渠道为 线路拥有者的售卖渠道
- if ($order_res['sale_path']) {
- $sale_path_arr = explode(',', $order_res['sale_path']);
- $owner_order_id = end($sale_path_arr);
- $res = self::find()->select([
- 'parent_order_id',
- 'outside_sale_org_id',
- 'sale_path',
- 'agent_level'
- ])->from(OrderMain::tableName())
- ->where(['parent_order_id' => $owner_order_id, 'cancel_flag' => 0])
- ->asArray()
- ->one();
- $owner_supplier_id = $res['outside_sale_org_id'];
- $supplier_id = $owner_supplier_id;
- }
- return $supplier_id;
- }
-
- public function getGroupSuccessMsgInfo($order_id)
- {
- //1获取短信模板所需参数
- #1.1,获取组合订单信息
- $orderInfo = self::find()->select([
- 'order_title_id',
- 'cus_name',
- 'cus_phone'
- ])->from(OrderTitle::tableName())
- ->where(['order_title_id' => $order_id])
- ->asArray()
- ->one();
- #1.3,部分异常处理
- if (!$orderInfo) {
- return false;//无出行信息
- }
-
- //2,获取短信模板
- $final = $this->getTemplate(0, 0, 0);
-
- if (!$final || !isset($final['content5'])) {
- return false;//模板信息缺失;
- }
- $content = $final['content5'];
- $customer_name = $orderInfo["cus_name"];
- $customer_mobile = $orderInfo["cus_phone"];
- #3.3根据runInfo替换短信模板信息
- //{订单号}{出发地}{上车站点}{目的地}{下车站点}){车票张数}{出发日期}{出发时间}{车牌号}{司机姓司机电话}{上车站点详细地址}{车票链接}
- $content = str_replace("{订单号}", $order_id, $content);
- #4,返回发送短信相关信息
- return array($customer_name, $customer_mobile, $content);
- }
-
-
- public function sendBusChangeRemindMsg($run_start_time, $itinerary_name, $new_bus_no)
- {
- $send_txt = "出行车辆变更通知:{$run_start_time}出发的{$itinerary_name}的车辆已变更为{$new_bus_no},请及时和车调人员进行确认!";
- $send_mobile = "18817847097,13625816476";
- Msg::sendTelMsg($send_mobile, $send_txt);
- }
-
- public function sendNewUserRemindMsg($run_id, $bus_order_id, $send_bus_count = 1)
- {
- $model_order_main = new OrderMain();
- $need_send_id_array = $model_order_main->getOrderArrayFromRunbus($run_id, $bus_order_id);
- $message_template = $send_bus_count <= 1 ? "two" : "three";
- foreach ($need_send_id_array as $order_info) {
- $order_id = $order_info["parent_order_id"];
- $send_mobile = $order_info["customer_mobile"];
- $send_message = $this->getMsgInfo($order_id, $message_template);
- if ($send_message == "notSend") {
- continue;
- }
- $send_success = Msg::sendTelMsg($send_message[1], $send_message[2],$order_info['main_corp_id']);
- //短信记录插入order_send_message表
- $current_time = date("Y-m-d H:i:s");
- $send_msg_values = [
- 'ORDER_ID' => $order_id,
- 'SEND_MOBILE' => $send_message[1],
- 'SEND_MESSAGE' => $send_message[2],
- 'SEND_TIME' => $current_time,
- 'SEND_ERROR' => $send_success,
- 'CREATE_USER_ID' => 2,
- 'CREATE_TIME' => $current_time,
- 'UPDATE_USER_ID' => 2,
- 'UPDATE_TIME' => $current_time,
- ];
- $msgRecord = new OrderSendMessage();
- $msgRecord->attributes = $send_msg_values;
- $res = $msgRecord->insert();
- }
- }
-
- public function addSuccessMessage($order_id, $send_mobile, $send_txt)
- {
- $insert_sql = " INSERT INTO send_bus_success_message (id, order_id, create_time,send_flag,send_mobile,send_message )
- VALUES (NULL,{$order_id},now(),0,'{$send_mobile}','{$send_txt}');";
- $res = Yii::$app->db->createCommand($insert_sql)->execute();
- }
-
- /**
- * Function Description:发送短信白名单添加
- * Function Name: insertAppointSendMessage
- * @param $order_id
- *
- * @return mixed
- *
- * @author LUOCJ
- */
- public function insertAppointSendMessage($order_id)
- {
- $model = AppointSendMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
- if ($model) {
- $json['code'] = '1';
- $json['info'] = '该数据已存在,不能重复添加';
- return $json;
- }
- $model = new AppointSendMessage();
- $now = date('Y-m-d H:i:s');
- $user = 1;
- $model->create_time = $model->update_time = $now;
- $model->create_user_id = $model->update_user_id = $user;
- $model->cancel_flag = 0;
- $model->order_id = $order_id;
- if (!$model->save()) {
- $json['code'] = '2';
- $json['info'] = '保存失败,请检查数据' . $model->getFirstError();
- return $json;
- }
- $json['code'] = '0';
- $json['info'] = '保存成功';
- return $json;
- }
-
- public function cancelAppointSendMessage($order_id)
- {
- $model = AppointSendMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
- if (!$model) {
- $json['code'] = '1';
- $json['info'] = '该数据不存在,请检查订单号';
- return $json;
- }
- $model->cancel_flag = 1;
- if (!$model->save()) {
- $json['code'] = '2';
- $json['info'] = '删除白名单失败,请检查数据';
- return $json;
- }
- $json['code'] = '0';
- $json['info'] = '刪除成功';
- return $json;
- }
-
- /**
- * Function Description:发送短信白名单添加
- * Function Name: insertAppointSendMessage
- * @param $order_id
- *
- * @return mixed
- *
- * @author LUOCJ
- */
- public function insertWechatClickMessage($order_id)
- {
- $model = WechatClickMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
- if ($model) {
- $json['code'] = '1';
- $json['info'] = '该数据已存在,不能重复添加';
- return $json;
- }
- $model = new WechatClickMessage();
- $now = date('Y-m-d H:i:s');
- $user = 1;
- $model->create_time = $model->update_time = $now;
- $model->create_user_id = $model->update_user_id = $user;
- $model->cancel_flag = 0;
- $model->order_id = $order_id;
- if (!$model->save()) {
- $json['code'] = '2';
- $json['info'] = '保存失败,请检查数据';
- return $json;
- }
- $json['code'] = '0';
- $json['info'] = '保存成功';
- return $json;
- }
-
- public function cancelWechatClickMessage($order_id)
- {
- $model = WechatClickMessage::findOne(['order_id' => $order_id, 'cancel_flag' => 0]);
- if (!$model) {
- $json['code'] = '1';
- $json['info'] = '该数据不存在,请检查订单号';
- return $json;
- }
- $model->cancel_flag = 1;
- if (!$model->save()) {
- $json['code'] = '2';
- $json['info'] = '删除失败,请检查数据';
- return $json;
- }
- $json['code'] = '0';
- $json['info'] = '刪除成功';
- return $json;
- }
-
- /**
- * Function Description:下单发送短信
- * Function Name: orderSendMsg
- * @param int $order_id
- * @param string $template_type 使用模板类型 one:预订短信1或预定短信2(根据下单时间判断),two:出行短信,three:换车提醒短信
- * @return mixed
- *
- * @author 邱颂
- */
- public function orderSendFreeMsg($order_id, $user_id, $send_message)
- {
- if (!$order_id) {
- $json["code"] = '1';
- $json["info"] = '参数不正确';
- return $json;
- }
-
- //1,获得需要发送的手机号码
- $order_main_info = OrderMain::findOne(["ORDER_ID" => $order_id]);
- if (!$order_main_info) {
- $json["code"] = '1';
- $json["info"] = '参数不正确';
- return $json;
- }
- $send_tel = $order_main_info->CUSTOMER_MOBILE;
-
- $send_success = '-100'; //若最后记录为-100,说明未执行短信发送
- $send_success = Msg::sendTelMsg($send_tel, $send_message,$order_main_info->MAIN_CORP_ID);
-
- //2,短信记录插入order_send_message表
- $current_time = date("Y-m-d H:i:s");
- $send_msg_values = [
- 'ORDER_ID' => $order_id,
- 'SEND_MOBILE' => $send_tel,
- 'SEND_MESSAGE' => $send_message,
- 'SEND_TIME' => $current_time,
- 'SEND_ERROR' => $send_success,
- 'CREATE_USER_ID' => $user_id,
- 'CREATE_TIME' => $current_time,
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => $current_time,
- ];
- $msgRecord = new OrderSendMessage();
- $msgRecord->attributes = $send_msg_values;
- $res = $msgRecord->insert();
-
- $json["code"] = '0';
- $json["info"] = '短信已发送';
- $json['resCode'] = $send_success;
- return $json;
- }
-
- }
|