|
- <?php
- /**
- * Function Description:组合订单状态变更
- * Function Name: GroupOrderController
- * ${PARAM_DOC}
- *
- * @return ${TYPE_HINT}
- * ${THROWS_DOC}
- *
- * @author 娄梦宁
- */
-
- namespace console\controllers;
-
- use backend\modules\api\logic\CancelTourist;
- use backend\modules\api\models\ErrorOrderLog;
- use backend\modules\api\util\Util;
- use backend\modules\zzcs\models\OrderGroupConnect;
- use backend\modules\zzcs\models\OrderTitle;
- use backend\modules\zzcs\models\OrderTitleCancelRequest;
- use common\components\zOfficeWechat;
- use common\util\CtripUtil;
- use yii\base\Exception;
- use yii\web\Controller;
- use console\models\GroupOrder;
-
-
- class GroupOrderController extends Controller
- {
- public $enableCsrfValidation = false;
-
- public function actionIndex()
- {
- print_r('HELLO');
- }
-
- /*
- * 待确认订单变已确认
- */
- public function actionConfirmOrder()
- {
- $order_group_connect = new OrderGroupConnect();
- $order_title = new OrderTitle();
- //待确认订单变已确认
- $order_un_confirm_arr = $order_title->getOrders(1);
- $un_confirm = [];
- $un_log_str = '';
- $cancel_arr = [];
- $cancel_log_str = '';
- $count2 = 0;
- $count1 = 0;
- $count3 = 0;
- foreach ($order_un_confirm_arr as $v) {
- $tmp_order_arr = $order_group_connect->getStatusByTitle($v['order_title_id']);
- //判断确认条件
- $is_ok = 1;
- foreach ($tmp_order_arr as $val) {
- if ($val['order_type'] == 1 && $val['order_status'] != 146) {//车票不是已出票
- $is_ok = 0;
- }
- if ($val['order_type'] == 3 && $val['order_status'] != 146) {//门票不是已出票
- $is_ok = 0;
- }
- if ($val['order_type'] == 2 && $val['order_status'] != 314) {//酒店不是已安排
- $is_ok = 0;
- }
- }
- if ($is_ok == 1) {//状态可变已确认
- $un_confirm[] = $v['order_title_id'];
- $un_log_str .= ', ' . $v['order_title_id'];
- }
- //判断取消条件
- $is_cancel = 1;
- foreach ($tmp_order_arr as $val) {
- if ($val['order_type'] == 1 && $val['order_status'] != 148) {//车票不是已取消
- $is_cancel = 0;
- }
- if ($val['order_type'] == 2 && $val['order_status'] != 148 && $val['order_status'] != 383) {//酒店不是已取消
- $is_cancel = 0;
- }
- if ($val['order_type'] == 3 && $val['order_status'] != 148) {//门票不是已取消
- $is_cancel = 0;
- }
- }
- if ($is_cancel == 1) {
- $cancel_arr[] = $v['order_title_id'];
- $cancel_log_str .= ', ' . $v['order_title_id'];
- }
- }
- if (!empty($un_confirm)) {
- $count1 = $order_title->confirmGroupOrder($un_confirm);
- }
- if (!empty($cancel_arr)) {
- $count2 = $order_title->cancelGroupOrder($cancel_arr);
- }
- if ($count1 != 0) {
- file_put_contents(__DIR__ . '/../log/group-order/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $un_log_str . "订单状态变已确认" . PHP_EOL, FILE_APPEND);
- }
- //已确认的单车资源订单变已取消,或车加景,或单景
- $order_only_bus = $order_title->getOnlyBus();
- foreach ($order_only_bus as $val) {
- $is_only_bus_cancel = 1;
- $tmp_arr = $order_group_connect->getStatusByTitle($val['order_title_id']);
- foreach ($tmp_arr as $v) {
- if ($v['order_status'] != 148) {//不是已取消
- $is_only_bus_cancel = 0;
- }
- }
- if ($is_only_bus_cancel == 1) {
- $cancel_only_arr[] = $val['order_title_id'];
- $cancel_log_str .= ', ' . $val['order_title_id'];
- }
- }
- if (!empty($cancel_only_arr)) {
- $count3 = $order_title->cancelGroupOrderOnlyBus($cancel_only_arr);
- }
- if ($count2 != 0 || $count3 != 0) {
- file_put_contents(__DIR__ . '/../log/group-oder/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $cancel_log_str . "订单状态变已取消" . PHP_EOL, FILE_APPEND);
- }
- }
-
- /*
- * 已确认订单变已完成
- */
- public function actionFinishOrder()
- {
- $order_group_connect = new OrderGroupConnect();
- $order_title = new OrderTitle();
- $order_confirm_arr = $order_title->getOrders(2);
- $finish_order_arr = [];
- $finish_order_date = array();
- $log_str = '';
- $error = [];
- foreach ($order_confirm_arr as $val) {
- $end_date = $order_group_connect->getMaxDate($val['order_title_id']);
- if (!empty($end_date) && strtotime($end_date['max_date']) < time()) {
- $finish_order_arr[] = $val['order_title_id'];
- $finish_order_date[$val['order_title_id']] = $end_date['max_date'];
- $log_str .= ', ' . $val['order_title_id'];
- //发送携程通知 错误不处理 记录下来
- try {
- if ($val['is_connected_order'] != 1 || empty($val['outside_order_no'])) {//非携程直连或者没有携程订单号不发送 通知
- continue;
- }
- $result = CtripUtil::NoticeOrderConsumed($val['outside_order_no'], $val['order_title_id'], $val['adult_num']);
- if ($result['flag'] == false) {
- $error[] = $val['order_title_id'];
- }
- } catch (Exception $e) {
- }
- }
- }
- $count = $order_title->FinishGroupOrder($finish_order_arr, $finish_order_date);
- if ($count != 0) {
- file_put_contents(__DIR__ . '/../log/group-order/' . date("Y-m-d") . '.log', date("Y-m-d H:i:s") . $log_str . "订单状态变已完成,携程通知异常订单:" . implode(',', $error) . PHP_EOL, FILE_APPEND);
- }
- }
-
- /**
- * Function Description:自由行订单酒店全部取消后取消整体订单
- * Function Name: actionCheckTouristOrder
- *
- *
- * @author 娄梦宁
- */
- public function actionCheckTouristOrder()
- {
- $order_title = new OrderTitle();
- $order_group_connect = new OrderGroupConnect();
- $tourist_hotel_id = $order_title->getGroupHotelOrder();
- if (!empty($tourist_hotel_id)) {
- foreach ($tourist_hotel_id as $val) {
- $is_cancel = 0;
- $is_all_cancel = 0;
- $tmp_arr = $order_group_connect->getStatusByTitle($val['order_title_id']);
- foreach ($tmp_arr as $v) {
- if ($v['order_type'] == 2 && ($v['order_status'] == 148 || $v['order_status'] == 383)) {//酒店子资源有已取消的
- $is_cancel = 1;
- }
- if ($v['order_type'] == 2 && $v['order_status'] != 148 && $v['order_status'] != 383) {//酒店子资源有未取消的
- $is_all_cancel = 1;
- }
- }
- if ($is_cancel == 1 && $is_all_cancel == 0) {
- //酒店子资源全部已取消,自由行订单取消
- $cancel_tourist = new CancelTourist();
- $cancel_result = $cancel_tourist->CancelTouristById($val['order_title_id'], 2, '定时任务 酒店子资源全部取消后取消自由行订单', 0);
- //弱异常错误数据库记录
- if ($cancel_result['code'] != 0) {
- $error_order_info = new ErrorOrderLog();
- if (isset($cancel_result['info'])) {
- $error_msg = $cancel_result['info'];
- } else {
- $error_msg = '';
- }
- $error_order_info->istOrderLog($val['order_title_id'], '定时任务 酒店子资源全部取消后取消自由行订单失败 ' . $error_msg);
- }
- //通知微信端自由行订单取消
- $send_result = Util::interfaceZzcx($val['order_title_id'], 4);
- //推送错误记录错误
- if (!isset($send_result['code']) && $send_result['code'] != 0) {
- $error_order_info = new ErrorOrderLog();
- if (isset($send_result['info'])) {
- $error_msg = $send_result['info'];
- } else {
- $error_msg = '';
- }
- $error_order_info->istOrderLog($val['order_title_id'], '微信自由行取消订单通知微信端返回值错误 ' . $error_msg);
- }
- }
- }
- }
- }
-
- /**
- * Function Description:对自由行产品已确认订单发送预订成功短信
- * Function Name: actionSendBookMsg
- *
- *
- * @author 温依莅
- */
- public function actionSendBookMsg()
- {
- $group_obj = new GroupOrder();
- $group_obj->sendBookMsg();
- }
-
- /**
- * Des:携程直连
- * Name: actionCtripNoticeOrderCancel
- * @author 倪宗锋
- */
- public function actionCtripNoticeOrderCancel()
- {
- $group_obj = new GroupOrder();
- $group_obj->ctripNoticeOrderCancel();
- }
-
- /**
- * Function Description:取消申请通知定时任务
- * Function Name: actionCheckCancelRequest
- *
- *
- * @author 冒炎
- */
- public function actionCheckCancelRequest()
- {
- $model = new OrderTitleCancelRequest();
- $arr = $model->check_cancel_request();
- if (!empty($arr)) {
- $list_str = implode(',', $arr);
- $send_arr = array(
- 'agentid' => '1000004',
- 'title' => '【自由行订单】取消申请通知',
- 'msg' => '您有快过期的携程当地玩乐自由行订单取消申请未处理,订单号为' . $list_str,
- 'touser' => 'loumn',
- // 'touser' => 'gaoj|panlj|wanr|duanry|yangyf|yiy|liuel|wangbs|nizf'
- );
- zOfficeWechat::sendMsg($send_arr);
- }
- }
-
- }
|