[ 'class' => LoginBehavior::className(), ], ]); } /** * 球车列表 * @return array|string */ public function actionIndex() { if (\Yii::$app->request->isAjax) { $form = new BallListForm(); $form->attributes = \Yii::$app->request->get(); $data = $form->search(); return $this->responseHandler($data); } $store = Store::find()->andWhere(['is_delete' => 0])->select('id,name')->asArray()->all(); return $this->render('index', [ 'store' => $store, ]); } /** * 球车编辑 * @param int $id * @return array|string */ public function actionEdit($id = 0) { $model = BallCart::findOne([ 'id' => $id, 'is_delete' => 0 ]); if ($model == null) $model = new BallCart(); if (\Yii::$app->request->isPost) { $form = new BallEditForm(); $form->attributes = \Yii::$app->request->post(); $form->model = $model; $data = $form->edit(); return $this->responseHandler($data); } //门店 $store = Store::find()->select('id,name')->asArray()->all(); $store_list = $store ? $store : []; //球车型号 $ball_mark_list = BallMark::find()->select('id,name')->asArray()->all(); $return_url = \Yii::$app->request->referrer; return $this->render('edit', [ 'model' => $model, 'return_url' => $return_url, 'store_list' => $store_list, 'ball_mark_list' => $ball_mark_list ]); } //删除球车 public function actionDelete() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->delete(); return $this->responseHandler($data); } //启用 public function actionStatusYes() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->status_yes(); return $this->responseHandler($data); } //停用 public function actionStatusNo() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->status_no(); return $this->responseHandler($data); } public function actionMark() { if (\Yii::$app->request->isAjax) { $form = new BallMarkForm(); $form->attributes = \Yii::$app->request->get(); $data = $form->search(); return $this->responseHandler($data); } return $this->render('mark', []); } public function actionMarkEdit($id = 0) { $model = BallMark::findOne([ 'id' => $id, 'is_delete' => 0 ]); if ($model == null) $model = new BallMark(); if (\Yii::$app->request->isPost) { $form = new BallMarkEditForm(); $form->attributes = \Yii::$app->request->post(); $form->model = $model; $data = $form->edit(); return $this->responseHandler($data); } $return_url = \Yii::$app->request->referrer; return $this->render('mark-edit', [ 'model' => $model, 'return_url' => $return_url, ]); } //启用 public function actionMarkYes() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallMarkActionForm(); $form->ids = \Yii::$app->request->post(); $data = $form->status_yes(); return $this->responseHandler($data); } //停用 public function actionMarkNo() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallMarkActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->status_no(); return $this->responseHandler($data); } //删除球车型号 public function actionMarkDelete() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallMarkActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->delete(); return $this->responseHandler($data); } public function actionFindQrcode() { if (!\Yii::$app->request->isPost) { $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new BallActionForm(); $form->attributes = \Yii::$app->request->post(); $data = $form->getBallQrcode(); return $this->responseHandler($data); } public function actionBatchQrcode() { $form = new BallActionForm(); $data = $form->BatchQrcode(); return $this->responseHandler($data); } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info : 球车详情 */ public function actionQcData() { if (\Yii::$app->request->isAjax) { $form = new BallListForm(); $form->attributes = \Yii::$app->request->get(); $data = $form->actionQcData(); return $this->responseHandler($data); } return $this->render('qc_data', []); } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info : 球车变更数据 */ public function actionQcSendMqtt() { $ball_number = \Yii::$app->request->get('ball_number'); $OPERATION_ENABLE = \Yii::$app->request->get('OPERATION_ENABLE'); $OPERATION_LEVEL = \Yii::$app->request->get('OPERATION_LEVEL'); if (!empty($ball_number)) { $redis_ball_cart_status_name = "api:cxaibc:ball_cart:{$ball_number}"; $redis_value = "{$OPERATION_ENABLE}:{$OPERATION_LEVEL}"; \Yii::$app->redis->set($redis_ball_cart_status_name, $redis_value); $obj = new Mqtt(); $obj->sendOpen($ball_number, $OPERATION_ENABLE, $OPERATION_LEVEL); } return $this->responseHandler(['code' => 0, 'msg' => '']); } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info : 查询球车数据 */ public function actionQcGetInfo() { $ball_number = \Yii::$app->request->get('ball_number'); $type = \Yii::$app->request->get('type'); if (!empty($ball_number)) { $obj = new Mqtt(); $obj->getInfo($ball_number, $type); } return $this->responseHandler(['code' => 0, 'msg' => '']); } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info: 球车设置页面 */ public function actionQcSetting() { $qc_zl_kwh_min = "qc_zl_kwh_min"; // 球车最低租赁电量 $find = Option::findOne([ 'key' => $qc_zl_kwh_min, ]); $qc_zl_kwh_min_value = 100; if (!empty($find)) { $qc_zl_kwh_min_value = $find->value; } $qc_wgh_value = "qc_wgh"; // 球车超出时长报警 $find = Option::findOne([ 'key' => $qc_wgh_value, ]); $qc_wgh_value = 0; if (!empty($find)) { $qc_wgh_value = $find->value; } return $this->render('qc_setting', [ 'qc_zl_kwh_min_value' => $qc_zl_kwh_min_value, 'qc_wgh_value' => $qc_wgh_value, ]); } /** * @ Author : Lw * @ CreateTime : 2022-11-18 * @ Info : 写入球车设置 */ public function actionSetQcSetting() { $key = \Yii::$app->request->post('key'); $value = \Yii::$app->request->post('value'); if (empty($key)) { return $this->responseHandler([ 'code' => 1, 'msg' => '请求错误', ]); } $find = Option::findOne([ 'key' => $key, ]); if (empty($find)) { $find = new Option(); $find->cx_mch_id = 0; $find->group = 0; $find->is_autoload = 0; $find->desc = ''; $find->key = $key; } $find->value = strval($value); if ($find->save()) { return $this->responseHandler([ 'code' => 0, 'msg' => '保存成功', ]); } return $this->responseHandler([ 'code' => 1, 'msg' => '保存失败', ]); } }