|
- <?php
-
- namespace backend\modules\api\controllers;
-
- use backend\modules\api\logic\ChangeSeat;
- use backend\modules\api\logic\WxTripApi;
- use backend\modules\zzcs\logic\BusService;
- use yii\web\Controller;
- use Yii;
-
- class ChangeSeatController extends Controller
- {
- public $enableCsrfValidation = false;
-
- /**
- * Function Description:入口
- * Function Name: actionIndex
- *
- * @return string
- *
- * @author Redstop
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- $action = $request->post('action');
- $func = 'action';
- $action = explode('_', $action);
- foreach ($action as $key => $vel) {
- $func .= ucfirst($vel);
- }
- //check 验证码
- if ($this->actionCheckAuthCode() == false) {
- $json = ['code' => 1, 'info' => '验证身份失败'];
- return json_encode($json);
- }
-
- if ($action === false || method_exists($this, $func) == false) {
- $json = ['code' => 1, 'info' => '必要参数缺失'];
- return json_encode($json);
- }
- return $this->$func();
- }
-
- /**
- * Function Description:验证验证码
- * Function Name: actionCheckAuthCode
- *
- * @return string
- *
- * @author Redstop
- */
- public function actionCheckAuthCode()
- {
- $user = Yii::$app->request->post('user');//用户名
- $user_key = Yii::$app->request->post('user_key');//用户key
- $request_time = Yii::$app->request->post('request_time');//用户key
- $auth_code = Yii::$app->request->post('auth_code');//用户key
- //加密规则为 request_time(linux时间戳)前三位作为种子,调用srand生成随机数 + user + user_key,进行MD5加密后,换成大写字母
- $real_auth_code = strtoupper(md5(substr($request_time, 0, 3) . "|" . $user . "|" . $user_key . "|" . substr($request_time, strlen($request_time) - 3, 3)));
- if ($real_auth_code == $auth_code) {
- return true;
- }
- return false;
- }
-
- /**
- * Function Description:通过订单号获取可换座位图
- * Function Name: actionGetSeatInfoByOrderId
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function actionGetSeatInfoByOrderId()
- {
- $order_id = Yii::$app->request->post('order_id');
- $change_seat = new ChangeSeat();
- return $change_seat->getSeatInfo($order_id);
- }
-
- /**
- * Des:车辆变更接口
- * Name: actionChangeBusForRunBus
- * @return array
- * @author 倪宗锋
- */
- public function actionChangeBusForRunBus()
- {
- $user_id = \Yii::$app->request->post('user_id', '');//用户ID
- $bus_id = \Yii::$app->request->post('bus_id', '');//车辆ID
- $run_bus_id = \Yii::$app->request->post('run_bus_id', '');//run_bus 主键ID
- $getChangeResult = BusService::init()->changeBusForRunBus($user_id, $bus_id, $run_bus_id);
- if ($getChangeResult['flag'] == false) {
- return json_encode(['code' => 1, 'info' => $getChangeResult['msg']]);
- } else {
- return json_encode(['code' => 0, 'info' => '设置成功!']);
- }
- }
-
- /**
- * Des:初始化选择页面接口
- * Name: actionInitChooseSeat
- * @return string
- * @author 倪宗锋
- */
- public function actionInitChooseSeat()
- {
- $order_id = trim(Yii::$app->request->post('order_id', ''));//选择的订单ID
- $wxTripApi = new WxTripApi();
- $getChooseSeatType = $wxTripApi->getChangeSeatType($order_id);//判断是否可以选座
- if ($getChooseSeatType['data']['change_seat_type'] != 0) {
- return json_encode(['code' => 1, 'info' => $getChooseSeatType['info']]);
- }
- $initChooseSeat = BusService::init()->initChooseSeat($order_id);//选择初始化
- if ($initChooseSeat['flag'] == false) {
- return json_encode(['code' => 1, 'info' => $initChooseSeat['msg']]);
- } else {
- return json_encode(['code' => 0, 'info' => '获取成功!','list'=> $initChooseSeat['data']]);
- }
- }
-
- /**
- * Des:选择座位
- * Name: actionChooseSeat
- * @return string
- * @author 倪宗锋
- */
- public function actionChooseSeat()
- {
- $order_id = trim(Yii::$app->request->post('order_id', ''));//选择的订单ID
- $seq_id = trim(Yii::$app->request->post('seq_id', ''));//座位ID
- $chooseSeat = BusService::init()->chooseSeat($order_id, $seq_id);
- if ($chooseSeat['flag'] == false) {
- return json_encode(['code' => 1, 'info' => $chooseSeat['msg']]);
- } else {
- return json_encode(['code' => 0, 'info' => '选座成功!']);
- }
- }
-
- }
|