| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- <?php
- namespace addons\Store\client\controllers;
- use addons\ReservationService\common\enums\ReservationServiceEnum;
- use addons\ReservationService\common\models\ReservationServiceUser;
- use addons\ReservationService\common\services\BackendService;
- use addons\Store\common\services\SchedulingService;
- use addons\Store\common\services\StaffService;
- use common\enums\ApiStatusEnum;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use yii\helpers\Json;
- use Yii;
- use Exception;
- class ReserveStaffController extends BaseController
- {
- /**
- * 技师列表
- * @return mixed|null
- */
- public function actionIndex()
- {
- if (\Yii::$app->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());
- }
- }
- }
|