| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- namespace addons\Store\api\modules\v1\controllers;
- use addons\ReservationService\common\enums\ReservationServiceEnum;
- use addons\ReservationService\common\models\ReservationServiceStoreGoods;
- use addons\ReservationService\common\models\ReservationServiceStoreSecondaryCard;
- use addons\ReservationService\common\models\ReservationServiceWorkTime;
- use addons\ReservationService\common\services\TechniciansService;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\services\ReserveCommentService;
- use addons\Store\common\services\ReserveGoodsService;
- use addons\Store\common\services\StaffService;
- use addons\Store\common\services\StoreReserveSettingService;
- use api\controllers\OnAuthController;
- use common\enums\GoodsTypeEnum;
- use common\enums\StatusEnum;
- use common\helpers\LocationHelper;
- use common\helpers\StringHelper;
- use common\models\order\OrderReserveComments;
- class StaffController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- /**
- * 门店技师列表
- * @return mixed|null
- */
- public function actionIndex()
- {
- $data = \Yii::$app->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());
- }
- }
- }
|