'订单ID', 'pay_type' => '支付类型', 'memo' => '扣款说明', 'order_model' => '订单信息', ]; } public function load($data, $formName = null) { $scope = $formName === null ? $this->formName() : $formName; if ($scope === '' && !empty($data)) { $this->setAttributes($data, false); $this->order_model = OrderMain::findOne(['ORDER_ID' => $this->order_id, 'CANCEL_FLAG' => 0]); if (!$this->order_model) { $this->addError('order_model', '找不到对应订单'); } return true; } elseif (isset($data[$scope])) { $this->setAttributes($data[$scope]); return true; } else { return false; } } function __construct($order_id, $pay_type, $memo) { $this->time = date('Y-m-d H:i:s'); $this->short_time = ' 18:00:00'; $this->user = 1; $this->order_id = $order_id; $this->pay_type = $pay_type; $this->memo = $memo; parent::__construct(); } function __get($name) { return $this->$name; } function __set($name, $value) { $this->$name = $value; } /** * Function Description:预付主流程(供应商) * Function Name: insertBalanceMain * * * @author LUOCJ */ public function insertBalanceMain($price = 0) { $data = ['code' => '0', 'info' => '插入成功']; // 读取供应商扣款旧记录 $load_data = array('order_id' => $this->order_id, 'pay_type' => $this->pay_type, 'memo' => $this->memo); if (!$this->load($load_data, '') || !$this->validate()) { return array('code' => '-1', 'info' => implode(',', array_column($this->getErrors(), 0))); } //创建需要插入和修改的对象 $update_res = self::updateBalanceModel($price); if (!$update_res) { $data['code'] = '2'; $data['info'] = '创建或插入失败'; return $data; } return $data; } /* * 插入渠道商预付记录 */ public function insertChannelBalanceMain($price = 0, $channel_id = 0) { $data = ['code' => '0', 'info' => '插入成功']; $load_data = array('order_id' => $this->order_id, 'pay_type' => $this->pay_type, 'memo' => $this->memo); if (!$this->load($load_data, '') || !$this->validate()) { return array('code' => '-1', 'info' => implode(',', array_column($this->getErrors(), 0))); } //创建需要插入和修改的对象, 执行操作 $update_res = self::updateChannelBalanceModel($price, $channel_id); if (!$update_res) { $data['code'] = '2'; $data['info'] = '创建或插入失败'; return $data; } return $data; } /** * Function Description:获取订单对象 * Function Name: getOrderMainModel * * @return static * * @author LUOCJ */ protected function getOrderMainModel() { $this->order_model = OrderMain::findOne(['ORDER_ID' => $this->order_id, 'CANCEL_FLAG' => 0]); if (!$this->order_model) { return false; } else { return true; } } /** * @Author wanglg * @Desc 供应商余额变化记录 * @param $price用于订单修改时订单修改变化之前的订单成本金额 * @return bool */ protected function updateBalanceModel($price) { //供应商预付款对象 $balance_his_model = new OperaBalanceHis(); // 查找供应商信息 $base_supplier_model = BaseSupplier::findOne(['ID' => $this->order_model->PROD_TOP_ORG_ID, 'CANCEL_FLAG' => 0, 'SUPPLIER_TYPE' => 187]); if (!$base_supplier_model) { return false; } // 供应商余额变动及供应商信息变化值 //赋个值渠道商修改变化,余额改变为订单的基础价,即就是采购价,如果是下单调用接口,变动金额为 $balance_his_model->order_id = $this->order_id; $balance_his_model->create_time = $balance_his_model->update_time = $this->time; $balance_his_model->supplier_id = $this->order_model->PROD_TOP_ORG_ID; $balance_his_model->pay_reason = $this->memo; $balance_his_model->pay_type = $this->pay_type; if ($this->order_model->BASE_PRICE < 0 || !empty($price)) $balance_his_model->change_value = $price; else $balance_his_model->change_value = $this->order_model->BASE_PRICE; $balance_his_model->create_user_id = $balance_his_model->update_user_id = $this->user; /** * 扣款口径 区分预订口径,入住口径,离店口径 * 预订口径直接扣款,巴士直接扣款 */ if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD || $this->order_model->ORDER_PROD_TYPE == self::BUS_TYPE) { $balance_his_model->expect_time = $balance_his_model->pay_time = $this->time; $balance_his_model->pay_status = self::PAY_STATUS_YKK; $balance_his_model->balance_before = $base_supplier_model->ACCOUNT_BALANCE; if ($this->pay_type == self::STATUS_ADD) // 余额变动类型:充值,账户余额+变动金额 $balance_his_model->balance_after = ((float)$balance_his_model->balance_before) + ((float)$balance_his_model->change_value); else if ($this->pay_type == self::STATUS_REDUCE) // 余额变动类型:扣款,账户余额 - 变动金额 $balance_his_model->balance_after = $balance_his_model->balance_before - (float)$balance_his_model->change_value; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_RZ) { // 入住口径执行扣款时间是订单入住时间 $balance_his_model->expect_time = $this->order_model->PROD_START_STATION_DATE . $this->short_time; $balance_his_model->pay_status = self::PAY_STATUS_DKK; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_LD) {// 离店口径执行扣款时间是订单完成时间,即客人离店时间 $balance_his_model->expect_time = $this->order_model->PROD_END_STATION_DATE . $this->short_time; $balance_his_model->pay_status = self::PAY_STATUS_DKK; } else { return false; } // 供应商列表余额修改为变动后的金额 $base_supplier_model->ACCOUNT_BALANCE = $balance_his_model->balance_after; $base_supplier_model->UPDATE_USER_ID = $this->user; $bt = Yii::$app->db->beginTransaction(); if ($balance_his_model->save()) { if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD || $this->order_model->ORDER_PROD_TYPE == self::BUS_TYPE) { $base_supplier_model->save(false); } $bt->commit(); } else { $bt->rollBack(); return false; } return true; } /** * @Author wanglg * @Desc 渠道商对应的扣款操作 * @return bool */ protected function updateChannelBalanceModel($price = 0, $channel_id = 0) { //找出渠道对象 $balance_his_model = new ChannelBalanceHis(); $channel_info = empty($channel_id) ? $this->order_model->OUTSIDE_SALE_ORG_ID : $channel_id; $base_supplier_model = BaseSupplier::findOne(['ID' => $channel_info, 'CANCEL_FLAG' => 0, 'SUPPLIER_TYPE' => 301]); if (!$base_supplier_model) { return false; } // 变动记录赋值用于保存 $balance_his_model->order_id = $this->order_id; $balance_his_model->create_time = $balance_his_model->update_time = $this->time; $balance_his_model->supplier_id = $channel_info; $balance_his_model->pay_reason = $this->memo; $balance_his_model->pay_type = $this->pay_type; if ($this->order_model->ORDER_PRICE < 0 || !empty($price)) $balance_his_model->change_value = $price; else $balance_his_model->change_value = $this->order_model->ORDER_PRICE; $balance_his_model->create_user_id = $balance_his_model->update_user_id = $this->user; /** * 扣款口径 区分预订口径,入住口径,离店口径, 根据口径判断扣款时间及支付状态 */ // 预订口径,直接执行扣款操作 巴士订单直接进行扣款操作! if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD || $this->order_model->ORDER_PROD_TYPE == self::BUS_TYPE) { $balance_his_model->expect_time = $balance_his_model->pay_time = $this->time; $balance_his_model->pay_status = self::PAY_STATUS_YKK; $balance_his_model->balance_before = $base_supplier_model->ACCOUNT_BALANCE; if ($this->pay_type == self::STATUS_ADD) // 充值或金额回退,计算渠道商变动后账户余额 $balance_his_model->balance_after = (float)$balance_his_model->balance_before + (float)$balance_his_model->change_value; else if ($this->pay_type == self::STATUS_REDUCE)// 下单扣款,计算渠道商变动后账户余额 $balance_his_model->balance_after = $balance_his_model->balance_before - (float)$balance_his_model->change_value; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_RZ) { // 入住口径,根据订单入住时间扣款 $balance_his_model->expect_time = $this->order_model->PROD_START_STATION_DATE . $this->short_time; $balance_his_model->pay_status = self::PAY_STATUS_DKK; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_LD) { // 离店口径,根据订单离店时间执行扣款操作 $balance_his_model->expect_time = $this->order_model->PROD_END_STATION_DATE . $this->short_time; $balance_his_model->pay_status = self::PAY_STATUS_DKK; } else { return false; } $base_supplier_model->ACCOUNT_BALANCE = $balance_his_model->balance_after; $base_supplier_model->UPDATE_USER_ID = $this->user; $bt = Yii::$app->db->beginTransaction(); $result = $balance_his_model->save(); if ($result) { if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD || $this->order_model->ORDER_PROD_TYPE == self::BUS_TYPE) { $base_supplier_model->save(false); } $bt->commit(); } else { $bt->rollBack(); return false; } return true; } /** * Function Description: 取消订单流程 * Function Name: cancelBalanceMain * @param $price下单 * @return array * * @author LUOCJ * * 有扣款 -》 插入新纪录,读取最新的订单相关扣款记录 */ public function cancelBalanceMain() { $data = ['code' => '0', 'info' => '取消成功']; $his_model = OperaBalanceHis::find()->where(['order_id' => $this->order_id])->orderBy('create_time desc')->one(); if (!$his_model) { $data['code'] = '1'; $data['info'] = '无该记录'; return $data; } if ($his_model->pay_status == self::PAY_STATUS_DKK) { $his_model->pay_status = self::PAY_STATUS_YQX; $his_model->update_user_id = $this->user; $his_model->update_time = $this->time; if (!$his_model->save()) { $data['code'] = '3'; $data['info'] = '修改失败'; return $data; } } elseif ($his_model->pay_status == self::PAY_STATUS_YKK) { $data = $this->insertBalanceMain($his_model->change_value); } else { $data['code'] = '2'; $data['info'] = '该记录为已取消,不进行操作'; return $data; } return $data; } /** * @Author wanglg * @Desc 取消操作渠道商记录对应的操作流程 * @return array */ public function cancelChannelBalanceMain() { $data = ['code' => '0', 'info' => '取消成功']; $his_model = ChannelBalanceHis::find()->where(['order_id' => $this->order_id])->orderBy('create_time desc')->one(); if (!$his_model) { $data['code'] = '1'; $data['info'] = '无该记录'; return $data; } // 扣款状态:待扣款,直接操作该记录,将扣款状态修改为取消;如果是已扣款,则新增一条记录,将扣款金额返还给渠道商;取消状态不做操作 if ($his_model->pay_status == self::PAY_STATUS_DKK) { $his_model->pay_status = self::PAY_STATUS_YQX; $his_model->update_user_id = $this->user; $his_model->update_time = $this->time; if (!$his_model->save()) { $data['code'] = '3'; $data['info'] = '修改失败'; return $data; } } elseif ($his_model->pay_status == self::PAY_STATUS_YKK) { $data = $this->insertChannelBalanceMain($his_model->change_value, $his_model->supplier_id); } else { $data['code'] = '2'; $data['info'] = '该记录为已取消,不进行操作'; return $data; } return $data; } /** * Function Description:定时任务更新his表 * Function Name: timingBalanceMain * * @author LUOCJ */ public static function timingUpdateBalanceMain($user_id) { //刷新失败列表 $failures = []; $data = ['code' => '0', 'info' => '全部更新成功']; $end_time = date('Y-m-d 18:00:01'); $models = OperaBalanceHis::find()->where(['and', ['<', 'expect_time', $end_time], ['=', 'pay_status', self::PAY_STATUS_DKK]])->all(); foreach ($models as $k => $his_model) { $order_model = OrderMain::findOne(['order_id' => $his_model->order_id, 'cancel_flag' => 0]); if (!$order_model) { $failures = $his_model->order_id; continue; } $supplier_model = BaseSupplier::findOne(['ID' => $order_model->PROD_TOP_ORG_ID]); if (!$supplier_model) continue; $bt = Yii::$app->db->beginTransaction(); //状态置为已扣款 $his_model->pay_status = self::PAY_STATUS_YKK; //变动之前账户余额 $his_model->balance_before = $supplier_model->ACCOUNT_BALANCE; //变动之后账户余额 if ($his_model->pay_type == self::STATUS_ADD) $his_model->balance_after = $his_model->balance_before + (float)$his_model->change_value; else if ($his_model->pay_type == self::STATUS_REDUCE) $his_model->balance_after = $his_model->balance_before - (float)$his_model->change_value; //供应商余额变动 $supplier_model->ACCOUNT_BALANCE = $his_model->balance_after; //修改时间 $his_model->update_time = $his_model->pay_time = date('Y-m-d H:i:s'); $his_model->update_user_id = $user_id; if ($his_model->save() && $supplier_model->save()) { $bt->commit(); } else { $failures = $his_model->order_id; $bt->rollBack(); } } if (count($failures) == 0) { return $data; } else { $data['code'] = '1'; $data['info'] = '部分订单更新失败'; $data['data'] = $failures; return $data; } } /** * @Author wanglg * @Desc 定时任务更新渠道订单记录表 * @param $user_id * @return array */ public static function timingUpdateChannelBalanceMain($user_id) { //刷新失败列表 $failures = []; $data = ['code' => '0', 'info' => '全部更新成功']; $end_time = date('Y-m-d 18:00:01'); $models = ChannelBalanceHis::find()->where(['and', ['<', 'expect_time', $end_time], ['=', 'pay_status', self::PAY_STATUS_DKK]])->all(); foreach ($models as $k => $his_model) { $order_model = OrderMain::findOne(['order_id' => $his_model->order_id, 'cancel_flag' => 0]); if (!$order_model) { $failures = $his_model->order_id; continue; } $supplier_model = BaseSupplier::findOne(['ID' => $his_model->supplier_id]); if (!$supplier_model) continue; $bt = Yii::$app->db->beginTransaction(); //状态置为已扣款 $his_model->pay_status = self::PAY_STATUS_YKK; //变动之前账户余额 $his_model->balance_before = $supplier_model->ACCOUNT_BALANCE; //变动之后账户余额 if ($his_model->pay_type == self::STATUS_ADD) $his_model->balance_after = $his_model->balance_before + (float)$his_model->change_value; else if ($his_model->pay_type == self::STATUS_REDUCE) $his_model->balance_after = $his_model->balance_before - (float)$his_model->change_value; //供应商余额变动 $supplier_model->ACCOUNT_BALANCE = $his_model->balance_after; //修改时间 $his_model->update_time = $his_model->pay_time = date('Y-m-d H:i:s'); $his_model->update_user_id = $user_id; if ($his_model->save() && $supplier_model->save()) { $bt->commit(); } else { $failures = $his_model->order_id; $bt->rollBack(); } } if (count($failures) == 0) { return $data; } else { $data['code'] = '1'; $data['info'] = '部分订单更新失败'; $data['data'] = $failures; return $data; } } /** * Function Description:检查数据 * Function Name: checkData * * @return bool * * @author LUOCJ */ protected function checkData() { if ($this->order_id == '' || $this->order_id == 0 || $this->pay_type == '' || $this->memo == '' || !in_array($this->pay_type, [self::STATUS_ADD, self::STATUS_REDUCE])) { return false; } else { return true; } } public function addLog($data, $memo = '') { if (!file_exists(__DIR__ . '/../log/balance')) { mkdir(__DIR__ . '/../log/balance'); } //获取调用行数; $debug_model = debug_backtrace(); $debug = $debug_model[0]; $lines = '文件:' . $debug['file'] . '行数' . $debug['line']; file_put_contents(__DIR__ . '/../log/balance/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '供应商相关信息::' . '调用行数:' . $lines . 'order_id:' . $this->order_id . ' 返回值:' . json_encode($data, JSON_UNESCAPED_UNICODE) . '其他:' . $memo . PHP_EOL, FILE_APPEND); } /** * @Author wanglg * @Desc 创建渠道商预支付记录日志记录 * @param $data * @param string $memo */ public function createChannelLog($data, $memo = '') { if (!file_exists(__DIR__ . '/../log/channel')) { mkdir(__DIR__ . '/../log/channel'); } //获取调用行数; $debug_model = debug_backtrace(); $debug = $debug_model[0]; $lines = '文件:' . $debug['file'] . '行数' . $debug['line']; file_put_contents(__DIR__ . '/../log/channel/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '渠道商相关信息::' . '调用行数:' . $lines . 'order_id:' . $this->order_id . ' 返回值:' . json_encode($data, JSON_UNESCAPED_UNICODE) . '其他:' . $memo . PHP_EOL, FILE_APPEND); } /** * Function Description:余额主流程批量修改 * Function Name: insertBalanceMain * * * @author LUOCJ */ public function insertBalanceMainBatch() { $data = ['code' => '0', 'info' => '插入成功']; $flag = $this->checkData(); if (!$flag) return ['code' => '-1', 'info' => '参数不对,请检查']; //获取订单对象 $order_model = self::getOrderMainModel(); if (!$order_model) { $data['code'] = '1'; $data['info'] = '找不到对应订单'; return $data; } //创建需要插入和修改的对象 $update_res = self::updateBalanceModelBatch(); if (!$update_res) { $data['code'] = '2'; $data['info'] = '创建或插入失败'; return $data; } return $data; } /** * Function Description:批量导入进行修改 * Function Name: updateBalanceModel * * @return bool * * @author LUOCJ */ protected function updateBalanceModelBatch() { //找个对象 $balance_his_model = new OperaBalanceHis(); $base_supplier_model = BaseSupplier::findOne(['ID' => $this->order_model->PROD_TOP_ORG_ID, 'CANCEL_FLAG' => 0]); if (!$base_supplier_model) { return false; } //如果重复 即最后创建的记录为扣款则不进行插入 $his_model = OperaBalanceHis::find()->where(['and', ['=', 'order_id', $this->order_id]])->orderBy('create_time desc')->one(); if ($his_model) { return false; } //赋个值 $balance_his_model->order_id = $this->order_id; //时间修改为订单创建的时间 $balance_his_model->create_time = $this->order_model->CREATE_TIME; $balance_his_model->update_time = $this->order_model->UPDATE_TIME; $balance_his_model->supplier_id = $this->order_model->PROD_TOP_ORG_ID; $balance_his_model->pay_reason = $this->memo; $balance_his_model->pay_type = $this->pay_type; if ($this->order_model->BASE_PRICE < 0) $balance_his_model->change_value = 0; else $balance_his_model->change_value = $this->order_model->BASE_PRICE; $balance_his_model->create_user_id = $balance_his_model->update_user_id = $this->user; /** * 扣款口径 区分预订口径,入住口径,离店口径 */ if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD) { $balance_his_model->expect_time = $balance_his_model->pay_time = $this->order_model->UPDATE_TIME; $balance_his_model->pay_status = 2; $balance_his_model->balance_before = $base_supplier_model->ACCOUNT_BALANCE; if ($this->pay_type == self::STATUS_ADD) $balance_his_model->balance_after = $balance_his_model->balance_before + (float)$this->order_model->BASE_PRICE; else if ($this->pay_type == self::STATUS_REDUCE) $balance_his_model->balance_after = $balance_his_model->balance_before - (float)$this->order_model->BASE_PRICE; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_RZ) { $balance_his_model->expect_time = $this->order_model->PROD_START_STATION_DATE . $this->short_time; $balance_his_model->pay_status = 1; } elseif ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_LD) { $balance_his_model->expect_time = $this->order_model->PROD_END_STATION_DATE . $this->short_time; $balance_his_model->pay_status = 1; } else { return false; } $base_supplier_model->ACCOUNT_BALANCE = $balance_his_model->balance_after; $base_supplier_model->UPDATE_USER_ID = $this->user; $bt = Yii::$app->db->beginTransaction(); if ($balance_his_model->save()) { if ($base_supplier_model->DEDUCT_TYPE == OperaBalanceHisSearch::DEDUCT_TYPE_YD) { $base_supplier_model->save(false); } $bt->commit(); } else { $bt->rollBack(); return false; } return true; } /** * Function Description:获取短信 插入或修改tailormessage表 * Function Name: actionGetMessage * * @return array|string * * @author LUOCJ */ static function getMessage() { //获取短信 $flag = Msg::getMessage(); $json = ['code' => '0', 'info' => '获取成功', 'data' => $flag, 'order_main_failure' => []]; //$flag = [200,"{\"result\":\"0\",\"desc\":\"\u6210\u529f\",\"delivers\":[{\"phone\":\"15201998183\",\"content\":\"\u54c8\u54c8\u54c8\u54c8\u4e0a\u8f66\u5730\u5740#\u6d4b\u8bd5\u7684\u4e0a\u8f66\u5730\u6ca1\u9519\u554a\u554a\u554a\u725b\u903c\u554a##\u5740#6464376\u5475\u5475\u7edd\u5bf9\u7edd\u5bf9\u7edd\u5bf9\u5bb6\",\"subcode\":\"78301\",\"delivertime\":\"2017-08-23 16:03:36\"}]}"]; if (!$flag) { $json['code'] = '1'; $json['info'] = '无短信数据'; return $json; } // $tp_data = json_decode($flag); $data = json_decode($flag[1]); if ($data->result !== "0" || !isset($data->delivers)) { $json['code'] = '2'; $json['info'] = 'result为0或者无数据'; return $json; } //有数据则对数据进行遍历 if (count($data->delivers) > 0) { foreach ($data->delivers as $k => $v) { //有则更新,无则新建 $model = TailorCustomerReplyMessage::findOne(['tel' => $v->phone, 'reply_time' => $v->delivertime]); if (!$model) { $model = new TailorCustomerReplyMessage(); } $model->tel = $v->phone; $model->reply_info = $v->content; $model->reply_time = $v->delivertime; $model->sub_code = $v->subcode; if (!$model->save()) { $json['code'] = '2'; $json['info'] = $model->tel . ',' . $model->reply_time . ',' . '保存失败'; return $json; } //进行订单返写,失败的订单号记入数组写入log $order_res = self::updateMessageToOrderMain($model); $json['order_main_failure'] = $order_res; } } return $json; } /** * Function Description:返写入order_main * Function Name: updateMessageToOrderMain * @param TailorCustomerReplyMessage $model * * @return array * * @author LUOCJ */ static function updateMessageToOrderMain(TailorCustomerReplyMessage $model) { $json = ['code' => '0', 'info' => '写入成功', 'data' => []]; $tomorrow = date("Y-m-d", strtotime("+1 day")); $today = date("Y-m-d"); //邱哥说 9-1 10:48 //比如说 一个人定了10/1 和 11/1的 //今天回复地址,两条都更新 //10/2日回复地址,只更新11/1的那单 $order_main_models = OrderMain::find() ->joinWith('operaLine') ->where( ['and', ['like', 'order_main.CUSTOMER_MOBILE', $model->tel], ['=', 'order_main.CANCEL_FLAG', 0], ['=', 'order_main.ORDER_VALID_STATUS', 1], ['=', 'order_main.ORDER_PROD_TYPE', 82], ['>=', 'order_main.RUN_DATE', $today], ['=', 'opera_line.TAILOR_FLAG', 1], ])->all(); if (!$order_main_models) { $json['code'] = '1'; $json['info'] = '找不到对应订单'; return $json; } //处理短信数据 获取地址 $address = self::getAddressInMessage($model->reply_info, '#', '#'); foreach ($order_main_models as $k => $order_main_model) { if ($address === false) { $order_main_model->CUSTOMER_MEMO = $order_main_model->CUSTOMER_MEMO . '|' . $model->reply_info; } else { $order_main_model->CUSTOMER_ADDRESS = $address; } if (!$order_main_model->save(false)) { $json['code'] = '2'; $json['info'] = '保存失败'; $json['data'][] = $order_main_model->order_id; return $json; } } return $json; } /** * Function Description:获取指定字符间的文字 * Function Name: getAddressInMessage * @param $message * @param $start * @param $end * * @return bool|string * * @author LUOCJ */ static function getAddressInMessage($message, $start, $end) { $start_pos = mb_stripos($message, $start); $end_pos = mb_strripos($message, $end); if ($start_pos == $end_pos) { return false; } $result = mb_substr($message, $start_pos + 1, $end_pos - $start_pos - 1); return $result; } /** * Function Description:定时任务,每隔一段时间对未回复短信的用户 发送短信提醒 * Function Name: sendNoAddressMessage * * * @author LUOCJ */ static function sendNoAddressMessage() { //■每天晚上19点 针对第二天9点前出发的还未设置地址的上门接订单发送最终提醒短信 //■每天早上10点 针对当天9点后出发的还未设置地址的上门接订单发送最终提醒短信 $time = date('H'); // $time = 10; $flag_time = '09:00'; if ($time == 19) { $run_time_arr = [date('Y-m-d', strtotime("+1 day"))]; $flag_compare = '<='; } elseif ($time == 10) { $run_time_arr = [date('Y-m-d')]; $flag_compare = '>'; } else { $json['code'] = '4'; $json['info'] = '时间不对,不发送短信'; return $json; } $json = ['code' => '0', 'info' => '发送成功']; $models = OrderMain::find() ->joinWith('operaLine') ->where( ['and', ['=', 'order_main.ORDER_VALID_STATUS', 1], ['=', 'order_main.CANCEL_FLAG', 0], ['=', 'order_main.ORDER_PROD_TYPE', 82], ['=', 'order_main.CUSTOMER_ADDRESS', ''], ['!=', 'order_main.CUSTOMER_MOBILE', ''], ['in', 'order_main.RUN_DATE', $run_time_arr], [$flag_compare, 'order_main.RUN_TIME', $flag_time], ['=', 'opera_line.TAILOR_FLAG', 1], ] ) ->groupBy('PARENT_ORDER_ID') ->all(); if (!$models) { $json['code'] = '1'; $json['info'] = '找不到需要发送的订单'; return $json; } $content = "您购买的旅游产品包含免费上门接至集合点的服务,请您按照\"#上车地址#\"的格式回复短信 ,填写您的上车地址,我们将安排车辆上门接您。如您选择自行前往,也请务必短信回复\"#不需要#\"。20点前如还未收到您的回复,将视为您自动放弃本项服务,感谢您的理解和支持。"; $tels_arr = []; $msg_web_name = \Yii::$app->params['msg_web_name']; foreach ($models as $k => $model) { if (isset($msg_web_name[$model->MAIN_CORP_ID])) {//有设置的用设置的 没有设置的用默认的1 $tels_arr[$model->MAIN_CORP_ID][] = $model->CUSTOMER_MOBILE; } else { $tels_arr[1][] = $model->CUSTOMER_MOBILE; } } if (count($tels_arr) <= 0) { $json['code'] = '2'; $json['info'] = '没有需要发送短信的号码'; return $json; } $sendFlag = true; foreach ($tels_arr as $key => $tels) { $tels_str = implode(',', $tels); $res = Msg::sendTelMsg($tels_str, $content, $key);//区分不同的主体发送不通短信 if ($res !== 0) { if (!file_exists(__DIR__ . '/../log/tailor')) { mkdir(__DIR__ . '/../log/tailor'); } file_put_contents(__DIR__ . '/../log/tailor/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . '发送用户详细地址短信提醒 短信发送失败 电话号码为' . $tels_str . PHP_EOL, FILE_APPEND); $sendFlag = false; } } if ($sendFlag == false) { $json['code'] = '3'; $json['info'] = '短信发送失败'; } return $json; } public function validatePrimary($attribute, $params) { if ($this->Spider_room == 0 || $this->RoomID == 0) { $this->addError($attribute, $params['message']); } } /** * @Author wanglg * @Desc验证扣款类型是否正确 */ public function mustInArray($attribute) { if (!in_array($this->$attribute, [self::STATUS_ADD, self::STATUS_REDUCE])) { $this->addError($attribute, '扣款类型不正确'); } } }