request->isAjax && \Yii::$app->request->isGet) { $data = \Yii::$app->request->get(); $rules = [ [['name','address', 'mobile', 'date_start', 'date_end', 'keyword'], 'string'], [['user_id', 'page', 'limit'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->page($data); if (!empty($ret['list'])) { foreach ($ret['list'] as &$item) { $item['idcard_images'] = [ $item['idcard_front'], $item['idcard_back'], ]; $item['qualification_certificate'] = Json::decode($item['qualification_certificate']); } } $ret['custom_text'] = BackendService::getCustomText($this->mall_id); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } return $this->render('index'); } /** * 技师详情 * @return mixed|null */ public function actionDetail() { if (\Yii::$app->request->isAjax && \Yii::$app->request->isGet) { $data = \Yii::$app->request->get(); $rules = [ [['id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->detail($data['id']); $ret['custom_text'] = BackendService::getCustomText($this->mall_id); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret, ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING); } return $this->render('detail'); } /** * 移除技师 * @return mixed|void|null */ public function actionDelete() { if (\Yii::$app->request->isAjax && \Yii::$app->request->isPost) { $data = \Yii::$app->request->post(); $rules = [ [['id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->delete($data['id']); return is_string($ret) ? $this->error($ret) : $this->success('操作成功'); } } /** * 技师数据统计 * @return mixed|null */ public function actionStatistics() { $data = \Yii::$app->request->get(); $rules = [ [['id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->statisticsByStaff($data['id']); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } /** * 设置上下班状态 * @return mixed|null */ public function actionSetStatus() { $data = \Yii::$app->request->post(); $rules = [ [['id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->setStatus($data['id']); return is_string($ret) ? $this->error($ret) : $this->success('操作成功', $ret); } public function actionEdit() { $request = \Yii::$app->request; $id = $request->get('id', 0); try { if ($request->isAjax) { // 查看等级详情 if ($request->isGet) { $data = []; if (!empty($id)) { // 获取等级信息 $model = ReservationServiceUser::getOne([['id' => $id, 'mall_id' => $this->mall_id]], true, []); $data['data'] = $model; } return $this->success('操作成功', $data); } elseif ($request->isPost) { $params = \Yii::$app->request->post()['form']; $res = \Yii::$app->services->validate->validate($params, [ [['idcard', 'level', 'user_id'], 'required'], [['level', 'user_id', 'id', 'mobile'], 'integer'], [['idcard_back', 'idcard_front', 'address', 'longitude', 'latitude', 'name'], 'string'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['check_status'] = ReservationServiceEnum::CHECK_ADOPT; $params['store_id'] = $this->store_id; $res = (new StaffService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->add($params); // if ($res === false) throw new \Exception(ReservationServiceUser::getStaticCodeError()['error']); return $this->success('操作成功'); } } } catch (\Exception $e) { return $this->error($e->getMessage(), []); } return $this->render($this->action->id); } public function actionGetLevels() { return $this->success('获取成功', BackendService::getLevels($this->mall_id)); } public function actionSearchUser() { $keyword = \Yii::$app->request->get('keyword', ''); $list['list'] = User::searchUser(['keyword' => $keyword, 'mall_id' => $this->mall_id, 'no_inviter' => 1]); return $this->success('操作成功', $list); } public function actionGetAssociationStoreGoods() { try { $data = \Yii::$app->request->get(); $rules = [ [['user_id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->getAssociationStoreGoods($data); return $this->success('获取成功', $ret); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionGetStoreGoods() { try { $data = \Yii::$app->request->get(); $rules = [ [['keyword'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->getStoreGoods($data); return $this->success('获取成功', $ret); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionHandleAssociationStoreGoods() { try { $data = \Yii::$app->request->post(); $rules = [ [['user_id'], 'required'], [['goods_ids'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->handleAssociationStoreGoods($data); return $this->success('获取成功', $ret); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionGetAssociationStoreGoodsPage() { try { $data = \Yii::$app->request->get(); $rules = [ [['user_id'], 'integer'], [['page','limit'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->getAssociationStoreGoodsPage($data); return $this->success('获取成功', $ret); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionAdd() { try { if (\Yii::$app->request->isAjax) { if(\Yii::$app->request->isGet){ $ret['custom_text'] = BackendService::getCustomText($this->mall_id); return $this->success('获取成功', $ret); }elseif (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post()['form']; $res = \Yii::$app->services->validate->validate($params, [ [['idcard', 'level', 'user_id','gender','age'], 'required'], [['level', 'user_id', 'id', 'mobile'], 'integer'], [['idcard_back', 'idcard_front', 'address', 'longitude', 'latitude', 'name'], 'string'], [['qualification_certificate','avatar'], 'safe'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['check_status'] = ReservationServiceEnum::CHECK_ADOPT; $params['store_id'] = $this->store_id; if(empty($params['qualification_certificate'])){ $params['qualification_certificate'] = []; } $params['qualification_certificate'] = json_encode($params['qualification_certificate'], JSON_UNESCAPED_UNICODE); $res = (new StaffService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->addStallUser($params); return $this->success('操作成功'); } } return $this->render('add'); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionCheckStaffUser() { try { if (\Yii::$app->request->isAjax) { if(\Yii::$app->request->isGet){ $params = \Yii::$app->request->get(); $user = ReservationServiceUser::getOne( [['user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]], true, 'user' ); if (empty($user)) { return $this->error('平台不存在该技师'); } if (!empty($user['store_id'])) { return $this->error('该技师已经绑定其他门店,无法添加'); } $user['nickname'] = $user['user']['nickname']; if(!empty($user['qualification_certificate'])){ $qualification_certificate = json_decode($user['qualification_certificate'],true); $user['qualification_certificate'] = $qualification_certificate; }else{ $user['qualification_certificate'] = []; } return $this->success('获取成功',['user'=>$user]); } } }catch (\Exception $e){ return $this->error($e->getMessage()); } } //排期管理 public function actionScheduling() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [ [['user_id', 'month'], 'integer'], [['date'], 'safe'], ]); if (!$res) return $this->error('获取失败'); $config = [ 'mall_id' => $this->mall_id, 'store_id' => $this->store_id, ]; $year = date('Y'); if (!empty($get['date'])) { $year = date('Y', strtotime($get['date'])); } $get['year'] = $year; $data = (new SchedulingService($config))->getTechnicianData($get); $get['user_id'] = $data['user_detail']['user_id']; $time_data = (new SchedulingService($config))->technicianScheduling($get); $data['time_data'] = $time_data; $store = $this->store; $business_time_start = $store['business_time_start']; $business_time_end = $store['business_time_end']; $date = date('Y-m-d'); $default_start_time = $date.' '.$business_time_start.':00'; $default_end_time = $date . ' ' . $business_time_end . ':00'; $data['default_start_time'] = $default_start_time; $data['default_end_time'] = $default_end_time; return $this->success('获取成功',$data); } if (Yii::$app->request->isPost) { $post = Yii::$app->request->post(); try { $res = Yii::$app->services->validate->validate($post, [ [['user_id', 'is_all_day', 'id', 'type'], 'integer'], [['date_time'], 'string'], [['schedulingTime'], 'safe'] ]); if (!$res) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $config = [ 'mall_id' => $this->mall_id, 'store_id' => $this->store_id, ]; $post['time_data'] = $post['schedulingTime']; $ret = (new SchedulingService($config))->setTechnicianScheduling($post); if (is_string($ret)) throw new Exception($ret); return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } return $this->render('scheduling',[]); } //获取所选日期排期详情 public function actionTechnicianSchedulingDetail() { $request = Yii::$app->request; if ($request->isAjax && $request->isGet) { try{ $params = $request->get(); $res = Yii::$app->services->validate->validate($params, [ [['user_id'], 'integer'], [['date_time'], 'string'] ]); if (!$res) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $res = (new SchedulingService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]))->technicianSchedulingDetail($params); return $this->success('获取成功', $res); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } //删除排班时间 public function actionDelSchedulingTime() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { try { $post = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($post, [ [['id', 'user_id', 'status'], 'integer'], ]); if (!$res) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $config = [ 'mall_id' => $this->mall_id, 'store_id' => $this->store_id, ]; (new SchedulingService($config))->changeTechnicianSchedulingTimeStatus($post); return $this->success('删除成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } //批量设置当月排班 public function actionSetAllMonth() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $post = Yii::$app->request->post(); try { $res = Yii::$app->services->validate->validate($post, [ [['user_id', 'is_all_day', 'type'], 'integer'], [['month'], 'string'], [['schedulingTime', 'date'], 'safe'] ]); if (!$res) throw new \Exception(Yii::$app->services->validate->getErrorMessage()); $year = date('Y'); if (!empty($post['date'])) { $year = date('Y', strtotime($post['date'])); } $post['year'] = $year; //如果详细时间数据不是数组,解json格式 $config = [ 'mall_id' => $this->mall_id, 'store_id' => $this->store_id, ]; $post['time_data'] = $post['schedulingTime']; $ret = (new SchedulingService($config))->setTechnicianSchedulingMonth($post); return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } //删除当天排期 public function actionDeleteScheduling() { $request = Yii::$app->request; if ($request->isAjax && $request->isPost) { try { $post = $request->post(); $res = Yii::$app->services->validate->validate($post, [ [['id'], 'required'], [['user_id'], 'integer'], ]); if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $config = [ 'mall_id' => $this->mall_id, 'store_id' => $post['store_id'], ]; $ret = (new SchedulingService($config))->deleteScheduling($post); return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } /** * 获取关联的次卡 * @return mixed|null */ public function actionGetAssociationStoreSecondaryCard() { try { $data = \Yii::$app->request->get(); $rules = [ [['user_id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->getAssociationStoreSecondaryCard($data); return $this->success('获取成功', $ret); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 获取门店次卡列表 * @return mixed|null */ public function actionGetStoreSecondaryCard() { try { $data = \Yii::$app->request->get(); $rules = [ [['keyword'], 'safe'], [['user_id'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->getStoreSecondaryCard($data); return $this->success('获取成功', $ret); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 操作关联次卡 * @return mixed|null */ public function actionHandleAssociationStoreSecondaryCard() { try { $data = \Yii::$app->request->post(); $rules = [ [['user_id'], 'required'], [['secondary_card_ids'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['store_id' => $this->store_id, 'mall_id' => $this->mall_id]))->handleAssociationStoreSecondaryCard($data); return $this->success('获取成功', $ret); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }