request->get(); $rules = [ [['name', 'sort'], 'string'], // 综合,距离,单量,好评 [['age_min', 'age_max', 'gender', 'page', 'limit', 'store_id'], 'integer'], // 不限,男,女 [['lng', 'lat'], 'number'], // [['store_lng', 'store_lat'], 'required'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); // 查询门店的 $data['is_store'] = StatusEnum::ENABLED; if (!empty($data['sort'])) { switch ($data['sort']) { case 'order_num': case 'service_rating': $data['sort'] = "{$data['sort']} desc"; break; case 'distance': $data['sort'] = "{$data['sort']} asc"; } } $data['store_status'] = StatusEnum::ENABLED; $is_show_staff = 1; if(!empty($data['store_id'])){ $user_ids = []; $goods_ids = StoreGoods::find()->where(['store_id'=>$data['store_id'],'goods_type'=>GoodsTypeEnum::GoodsTypeReserved,'status'=>StatusEnum::ENABLED,'is_on_sale'=>1,'check_status'=>1]) ->select('id')->column(); if(empty($goods_ids)){ $is_show_staff = 0; }else{ //关联门店预约商品 $user_ids = ReservationServiceStoreGoods::find()->where(['store_id'=>$data['store_id'],'goods_id'=>$goods_ids,'status'=>StatusEnum::ENABLED]) ->select('user_id')->groupBy('user_id')->column(); if(empty($user_ids)){ $is_show_staff = 0; } } //关联门店次卡 $sec_user_ids = ReservationServiceStoreSecondaryCard::find()->where(['store_id' => $data['store_id'], 'status' => StatusEnum::ENABLED]) ->select('user_id')->groupBy('user_id')->column(); if (!empty($sec_user_ids)) { $user_ids = array_merge($user_ids, $sec_user_ids); $is_show_staff = 1; } $data['user_id_arr'] = $user_ids; } $ret = (new StaffService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'store_id' => $data['store_id']]))->page($data); if (!empty($ret['list'])) { foreach ($ret['list'] as &$item) { $item['gender_txt'] = ReservationServiceEnum::GENDER_MAP[$item['gender']]; $item['distance'] = LocationHelper::formatDistance((new LocationHelper()) ->getDistanceByGeo($item['latitude'], $item['longitude'], $data['lat'], $data['lng'])); $item['comment_num'] = OrderReserveComments::find()->where(['tech_user_id' => $item['user_id']]) ->andWhere(['store_id' => $item['store_id']])->count(); $item['service_rating'] = $item['comment_num'] >= 10 ? $item['store_service_rating'] : 0; } } $ret['is_show_staff'] = $is_show_staff; return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } /** * 技师入驻 * @return mixed|null */ public function actionSettle() { $service = new StaffService(['user_id' => $this->user_id, 'mall_id' => $this->mall_id]); if (\Yii::$app->request->isGet) { // 获取申请详情 // 未提交 // 审核中 // 被拒绝 // 已通过 // 0:待审核;1:已通过;2:未通过 return $this->success('获取成功', $service->frontDetail()); } else { // 申请 $data = \Yii::$app->request->post(); $rules = [ [[ 'store_id'], 'required'], // [['name','pic', 'phone'], 'string'], [['store_id'], 'integer'], // ['phone', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'], ]; $res = \Yii::$app->services->validate->validate($data, $rules, [ // 'name' => '姓名', // 'pic' => '相片', // 'phone' => '电话', 'store_id' => '门店', ]); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = $service->create($data); return is_string($ret) ? $this->error($ret) : $this->success('提交成功', $ret); } } /** * 技师详情 * @return mixed|null */ public function actionDetail() { $data = \Yii::$app->request->get(); $rules = [ [['id'], 'required'], [['id', 'store_id'], 'integer'], [['lng', 'lat'], 'number'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new StaffService(['mall_id' => $this->mall_id, 'store_id' => $data['store_id'] ?? 0]))->detail($data['id']); $ret['idcard'] = StringHelper::hideStr($ret['idcard'], 1, 16); // 距离 if (is_array($ret)) { $ret['distance'] = LocationHelper::formatDistance((new LocationHelper())->getDistanceByGeo($data['lat'], $data['lng'], $ret['store_lat'], $ret['store_lng'])); $ret['gender_txt'] = ReservationServiceEnum::GENDER_MAP[$ret['gender']]; $ret['store'] = $ret['settle']['store'] ?? []; $ret['order_num'] = $ret['store_order_num']; if (!empty($ret['is_working'])) { // 再判断是否能约/什么时候能约 $ret['reserve_text'] = ""; // 判断什么时候能约 $reserve_text = TechniciansService::getTechLatelyCanReserveAt($ret); if (empty($reserve_text)) { $ret['is_working'] = StatusEnum::DISABLED; } else { $ret['reserve_text'] = "{$reserve_text}可约"; } $ret['work_times'] = ReservationServiceWorkTime::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['user_id' => $ret['user_id']]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['week_day' => date('w')]) ->select('text')->column(); } } return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } /** * 获取技师评价列表 * @return mixed|null */ public function actionComments() { $data = \Yii::$app->request->get(); $rules = [ [['tech_id', 'page', 'limit', 'store_id'], 'integer'], [['tech_id', 'store_id'], 'required'], [['type'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new ReserveCommentService(['store_id' => $data['store_id'], 'mall_id' => $this->mall_id]))->page($data); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } /** * 技师项目 * @return mixed|void|null */ public function actionProjects() { // 获取项目 $data = \Yii::$app->request->get(); $rules = [ [['store_id', 'id'], 'required'], [['store_id', 'id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($data, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = (new ReserveGoodsService(['mall_id' => $this->mall_id, 'store_id' => $data['store_id']]))->customListByStore($data); return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret); } public function actionStoreList() { $list = Store::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], 'select'=> 'id, store_name', 'order' => 'id asc', ]); return $this->success('获取成功', $list); } /** * h5端-预约时间列表-到店分配/技师不选项 * @return mixed|null */ public function actionStoreReservationTimeList() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','store_id'], 'required'], [['date'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if(empty($params['date'])){ $params['date'] = date('Y-m-d'); } $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->toStoreReservationTimeList($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * 技师可预约时间列表 * @return mixed|null */ public function actionTechniciansReservationTimeList() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','store_id','technicians_id'], 'required'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->techniciansReservationTimeList($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionSearch() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','goods_id','store_id','lat','lng','date','time'], 'required'], [['page','limit','name','min_age','max_age','gender','sort','is_default_jishi'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->search($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionTopFourth() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id'], 'required'], [['id'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id]))->topFourth($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionGetDate() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','store_id'], 'required'], [['start'], 'safe'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id,'store_id'=>$params['store_id']]))->getDate($params); return $this->success('成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } public function actionGetTimes() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','goods_id','store_id','date'], 'required'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id,'store_id'=>$params['store_id']]))->getTimes($params); return $this->success('成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * 门店预约商品商品详情-服务时间列表 * @return mixed|null */ public function actionServiceTimeList() { try { $params = \Yii::$app->request->get(); $rules = [ [['sku_id','store_id','id'], 'required'], ]; $res = \Yii::$app->services->validate->validate($params, $rules); if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->serviceTimeList($params); return $this->success('获取成功', $list); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }