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.
 
 
 
 
 
 

263 lines
10 KiB

  1. <?php
  2. /**
  3. * Function Description:组合订单状态变更
  4. * Function Name: GroupOrderController
  5. * ${PARAM_DOC}
  6. *
  7. * @return ${TYPE_HINT}
  8. * ${THROWS_DOC}
  9. *
  10. * @author 娄梦宁
  11. */
  12. namespace console\controllers;
  13. use backend\modules\api\logic\CancelTourist;
  14. use backend\modules\api\models\ErrorOrderLog;
  15. use backend\modules\api\util\Util;
  16. use backend\modules\zzcs\models\OrderGroupConnect;
  17. use backend\modules\zzcs\models\OrderTitle;
  18. use backend\modules\zzcs\models\OrderTitleCancelRequest;
  19. use common\components\zOfficeWechat;
  20. use common\util\CtripUtil;
  21. use yii\base\Exception;
  22. use yii\web\Controller;
  23. use console\models\GroupOrder;
  24. class GroupOrderController extends Controller
  25. {
  26. public $enableCsrfValidation = false;
  27. public function actionIndex()
  28. {
  29. print_r('HELLO');
  30. }
  31. /*
  32. * 待确认订单变已确认
  33. */
  34. public function actionConfirmOrder()
  35. {
  36. $order_group_connect = new OrderGroupConnect();
  37. $order_title = new OrderTitle();
  38. //待确认订单变已确认
  39. $order_un_confirm_arr = $order_title->getOrders(1);
  40. $un_confirm = [];
  41. $un_log_str = '';
  42. $cancel_arr = [];
  43. $cancel_log_str = '';
  44. $count2 = 0;
  45. $count1 = 0;
  46. $count3 = 0;
  47. foreach ($order_un_confirm_arr as $v) {
  48. $tmp_order_arr = $order_group_connect->getStatusByTitle($v['order_title_id']);
  49. //判断确认条件
  50. $is_ok = 1;
  51. foreach ($tmp_order_arr as $val) {
  52. if ($val['order_type'] == 1 && $val['order_status'] != 146) {//车票不是已出票
  53. $is_ok = 0;
  54. }
  55. if ($val['order_type'] == 3 && $val['order_status'] != 146) {//门票不是已出票
  56. $is_ok = 0;
  57. }
  58. if ($val['order_type'] == 2 && $val['order_status'] != 314) {//酒店不是已安排
  59. $is_ok = 0;
  60. }
  61. }
  62. if ($is_ok == 1) {//状态可变已确认
  63. $un_confirm[] = $v['order_title_id'];
  64. $un_log_str .= ', ' . $v['order_title_id'];
  65. }
  66. //判断取消条件
  67. $is_cancel = 1;
  68. foreach ($tmp_order_arr as $val) {
  69. if ($val['order_type'] == 1 && $val['order_status'] != 148) {//车票不是已取消
  70. $is_cancel = 0;
  71. }
  72. if ($val['order_type'] == 2 && $val['order_status'] != 148 && $val['order_status'] != 383) {//酒店不是已取消
  73. $is_cancel = 0;
  74. }
  75. if ($val['order_type'] == 3 && $val['order_status'] != 148) {//门票不是已取消
  76. $is_cancel = 0;
  77. }
  78. }
  79. if ($is_cancel == 1) {
  80. $cancel_arr[] = $v['order_title_id'];
  81. $cancel_log_str .= ', ' . $v['order_title_id'];
  82. }
  83. }
  84. if (!empty($un_confirm)) {
  85. $count1 = $order_title->confirmGroupOrder($un_confirm);
  86. }
  87. if (!empty($cancel_arr)) {
  88. $count2 = $order_title->cancelGroupOrder($cancel_arr);
  89. }
  90. if ($count1 != 0) {
  91. 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);
  92. }
  93. //已确认的单车资源订单变已取消,或车加景,或单景
  94. $order_only_bus = $order_title->getOnlyBus();
  95. foreach ($order_only_bus as $val) {
  96. $is_only_bus_cancel = 1;
  97. $tmp_arr = $order_group_connect->getStatusByTitle($val['order_title_id']);
  98. foreach ($tmp_arr as $v) {
  99. if ($v['order_status'] != 148) {//不是已取消
  100. $is_only_bus_cancel = 0;
  101. }
  102. }
  103. if ($is_only_bus_cancel == 1) {
  104. $cancel_only_arr[] = $val['order_title_id'];
  105. $cancel_log_str .= ', ' . $val['order_title_id'];
  106. }
  107. }
  108. if (!empty($cancel_only_arr)) {
  109. $count3 = $order_title->cancelGroupOrderOnlyBus($cancel_only_arr);
  110. }
  111. if ($count2 != 0 || $count3 != 0) {
  112. 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);
  113. }
  114. }
  115. /*
  116. * 已确认订单变已完成
  117. */
  118. public function actionFinishOrder()
  119. {
  120. $order_group_connect = new OrderGroupConnect();
  121. $order_title = new OrderTitle();
  122. $order_confirm_arr = $order_title->getOrders(2);
  123. $finish_order_arr = [];
  124. $finish_order_date = array();
  125. $log_str = '';
  126. $error = [];
  127. foreach ($order_confirm_arr as $val) {
  128. $end_date = $order_group_connect->getMaxDate($val['order_title_id']);
  129. if (!empty($end_date) && strtotime($end_date['max_date']) < time()) {
  130. $finish_order_arr[] = $val['order_title_id'];
  131. $finish_order_date[$val['order_title_id']] = $end_date['max_date'];
  132. $log_str .= ', ' . $val['order_title_id'];
  133. //发送携程通知 错误不处理 记录下来
  134. try {
  135. if ($val['is_connected_order'] != 1 || empty($val['outside_order_no'])) {//非携程直连或者没有携程订单号不发送 通知
  136. continue;
  137. }
  138. $result = CtripUtil::NoticeOrderConsumed($val['outside_order_no'], $val['order_title_id'], $val['adult_num']);
  139. if ($result['flag'] == false) {
  140. $error[] = $val['order_title_id'];
  141. }
  142. } catch (Exception $e) {
  143. }
  144. }
  145. }
  146. $count = $order_title->FinishGroupOrder($finish_order_arr, $finish_order_date);
  147. if ($count != 0) {
  148. 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);
  149. }
  150. }
  151. /**
  152. * Function Description:自由行订单酒店全部取消后取消整体订单
  153. * Function Name: actionCheckTouristOrder
  154. *
  155. *
  156. * @author 娄梦宁
  157. */
  158. public function actionCheckTouristOrder()
  159. {
  160. $order_title = new OrderTitle();
  161. $order_group_connect = new OrderGroupConnect();
  162. $tourist_hotel_id = $order_title->getGroupHotelOrder();
  163. if (!empty($tourist_hotel_id)) {
  164. foreach ($tourist_hotel_id as $val) {
  165. $is_cancel = 0;
  166. $is_all_cancel = 0;
  167. $tmp_arr = $order_group_connect->getStatusByTitle($val['order_title_id']);
  168. foreach ($tmp_arr as $v) {
  169. if ($v['order_type'] == 2 && ($v['order_status'] == 148 || $v['order_status'] == 383)) {//酒店子资源有已取消的
  170. $is_cancel = 1;
  171. }
  172. if ($v['order_type'] == 2 && $v['order_status'] != 148 && $v['order_status'] != 383) {//酒店子资源有未取消的
  173. $is_all_cancel = 1;
  174. }
  175. }
  176. if ($is_cancel == 1 && $is_all_cancel == 0) {
  177. //酒店子资源全部已取消,自由行订单取消
  178. $cancel_tourist = new CancelTourist();
  179. $cancel_result = $cancel_tourist->CancelTouristById($val['order_title_id'], 2, '定时任务 酒店子资源全部取消后取消自由行订单', 0);
  180. //弱异常错误数据库记录
  181. if ($cancel_result['code'] != 0) {
  182. $error_order_info = new ErrorOrderLog();
  183. if (isset($cancel_result['info'])) {
  184. $error_msg = $cancel_result['info'];
  185. } else {
  186. $error_msg = '';
  187. }
  188. $error_order_info->istOrderLog($val['order_title_id'], '定时任务 酒店子资源全部取消后取消自由行订单失败 ' . $error_msg);
  189. }
  190. //通知微信端自由行订单取消
  191. $send_result = Util::interfaceZzcx($val['order_title_id'], 4);
  192. //推送错误记录错误
  193. if (!isset($send_result['code']) && $send_result['code'] != 0) {
  194. $error_order_info = new ErrorOrderLog();
  195. if (isset($send_result['info'])) {
  196. $error_msg = $send_result['info'];
  197. } else {
  198. $error_msg = '';
  199. }
  200. $error_order_info->istOrderLog($val['order_title_id'], '微信自由行取消订单通知微信端返回值错误 ' . $error_msg);
  201. }
  202. }
  203. }
  204. }
  205. }
  206. /**
  207. * Function Description:对自由行产品已确认订单发送预订成功短信
  208. * Function Name: actionSendBookMsg
  209. *
  210. *
  211. * @author 温依莅
  212. */
  213. public function actionSendBookMsg()
  214. {
  215. $group_obj = new GroupOrder();
  216. $group_obj->sendBookMsg();
  217. }
  218. /**
  219. * Des:携程直连
  220. * Name: actionCtripNoticeOrderCancel
  221. * @author 倪宗锋
  222. */
  223. public function actionCtripNoticeOrderCancel()
  224. {
  225. $group_obj = new GroupOrder();
  226. $group_obj->ctripNoticeOrderCancel();
  227. }
  228. /**
  229. * Function Description:取消申请通知定时任务
  230. * Function Name: actionCheckCancelRequest
  231. *
  232. *
  233. * @author 冒炎
  234. */
  235. public function actionCheckCancelRequest()
  236. {
  237. $model = new OrderTitleCancelRequest();
  238. $arr = $model->check_cancel_request();
  239. if (!empty($arr)) {
  240. $list_str = implode(',', $arr);
  241. $send_arr = array(
  242. 'agentid' => '1000004',
  243. 'title' => '【自由行订单】取消申请通知',
  244. 'msg' => '您有快过期的携程当地玩乐自由行订单取消申请未处理,订单号为' . $list_str,
  245. 'touser' => 'loumn',
  246. // 'touser' => 'gaoj|panlj|wanr|duanry|yangyf|yiy|liuel|wangbs|nizf'
  247. );
  248. zOfficeWechat::sendMsg($send_arr);
  249. }
  250. }
  251. }