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.
 
 
 
 
 
 

141 lines
4.7 KiB

  1. <?php
  2. namespace backend\modules\api\controllers;
  3. use backend\modules\api\logic\ChangeSeat;
  4. use backend\modules\api\logic\WxTripApi;
  5. use backend\modules\zzcs\logic\BusService;
  6. use yii\web\Controller;
  7. use Yii;
  8. class ChangeSeatController extends Controller
  9. {
  10. public $enableCsrfValidation = false;
  11. /**
  12. * Function Description:入口
  13. * Function Name: actionIndex
  14. *
  15. * @return string
  16. *
  17. * @author Redstop
  18. */
  19. public function actionIndex()
  20. {
  21. $request = Yii::$app->request;
  22. $action = $request->post('action');
  23. $func = 'action';
  24. $action = explode('_', $action);
  25. foreach ($action as $key => $vel) {
  26. $func .= ucfirst($vel);
  27. }
  28. //check 验证码
  29. if ($this->actionCheckAuthCode() == false) {
  30. $json = ['code' => 1, 'info' => '验证身份失败'];
  31. return json_encode($json);
  32. }
  33. if ($action === false || method_exists($this, $func) == false) {
  34. $json = ['code' => 1, 'info' => '必要参数缺失'];
  35. return json_encode($json);
  36. }
  37. return $this->$func();
  38. }
  39. /**
  40. * Function Description:验证验证码
  41. * Function Name: actionCheckAuthCode
  42. *
  43. * @return string
  44. *
  45. * @author Redstop
  46. */
  47. public function actionCheckAuthCode()
  48. {
  49. $user = Yii::$app->request->post('user');//用户名
  50. $user_key = Yii::$app->request->post('user_key');//用户key
  51. $request_time = Yii::$app->request->post('request_time');//用户key
  52. $auth_code = Yii::$app->request->post('auth_code');//用户key
  53. //加密规则为 request_time(linux时间戳)前三位作为种子,调用srand生成随机数 + user + user_key,进行MD5加密后,换成大写字母
  54. $real_auth_code = strtoupper(md5(substr($request_time, 0, 3) . "|" . $user . "|" . $user_key . "|" . substr($request_time, strlen($request_time) - 3, 3)));
  55. if ($real_auth_code == $auth_code) {
  56. return true;
  57. }
  58. return false;
  59. }
  60. /**
  61. * Function Description:通过订单号获取可换座位图
  62. * Function Name: actionGetSeatInfoByOrderId
  63. *
  64. * @return array
  65. *
  66. * @author 娄梦宁
  67. */
  68. public function actionGetSeatInfoByOrderId()
  69. {
  70. $order_id = Yii::$app->request->post('order_id');
  71. $change_seat = new ChangeSeat();
  72. return $change_seat->getSeatInfo($order_id);
  73. }
  74. /**
  75. * Des:车辆变更接口
  76. * Name: actionChangeBusForRunBus
  77. * @return array
  78. * @author 倪宗锋
  79. */
  80. public function actionChangeBusForRunBus()
  81. {
  82. $user_id = \Yii::$app->request->post('user_id', '');//用户ID
  83. $bus_id = \Yii::$app->request->post('bus_id', '');//车辆ID
  84. $run_bus_id = \Yii::$app->request->post('run_bus_id', '');//run_bus 主键ID
  85. $getChangeResult = BusService::init()->changeBusForRunBus($user_id, $bus_id, $run_bus_id);
  86. if ($getChangeResult['flag'] == false) {
  87. return json_encode(['code' => 1, 'info' => $getChangeResult['msg']]);
  88. } else {
  89. return json_encode(['code' => 0, 'info' => '设置成功!']);
  90. }
  91. }
  92. /**
  93. * Des:初始化选择页面接口
  94. * Name: actionInitChooseSeat
  95. * @return string
  96. * @author 倪宗锋
  97. */
  98. public function actionInitChooseSeat()
  99. {
  100. $order_id = trim(Yii::$app->request->post('order_id', ''));//选择的订单ID
  101. $wxTripApi = new WxTripApi();
  102. $getChooseSeatType = $wxTripApi->getChangeSeatType($order_id);//判断是否可以选座
  103. if ($getChooseSeatType['data']['change_seat_type'] != 0) {
  104. return json_encode(['code' => 1, 'info' => $getChooseSeatType['info']]);
  105. }
  106. $initChooseSeat = BusService::init()->initChooseSeat($order_id);//选择初始化
  107. if ($initChooseSeat['flag'] == false) {
  108. return json_encode(['code' => 1, 'info' => $initChooseSeat['msg']]);
  109. } else {
  110. return json_encode(['code' => 0, 'info' => '获取成功!','list'=> $initChooseSeat['data']]);
  111. }
  112. }
  113. /**
  114. * Des:选择座位
  115. * Name: actionChooseSeat
  116. * @return string
  117. * @author 倪宗锋
  118. */
  119. public function actionChooseSeat()
  120. {
  121. $order_id = trim(Yii::$app->request->post('order_id', ''));//选择的订单ID
  122. $seq_id = trim(Yii::$app->request->post('seq_id', ''));//座位ID
  123. $chooseSeat = BusService::init()->chooseSeat($order_id, $seq_id);
  124. if ($chooseSeat['flag'] == false) {
  125. return json_encode(['code' => 1, 'info' => $chooseSeat['msg']]);
  126. } else {
  127. return json_encode(['code' => 0, 'info' => '选座成功!']);
  128. }
  129. }
  130. }