StaffController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <?php
  2. namespace addons\Store\api\modules\v1\controllers;
  3. use addons\ReservationService\common\enums\ReservationServiceEnum;
  4. use addons\ReservationService\common\models\ReservationServiceStoreGoods;
  5. use addons\ReservationService\common\models\ReservationServiceStoreSecondaryCard;
  6. use addons\ReservationService\common\models\ReservationServiceWorkTime;
  7. use addons\ReservationService\common\services\TechniciansService;
  8. use addons\Store\common\models\Store;
  9. use addons\Store\common\models\StoreGoods;
  10. use addons\Store\common\services\ReserveCommentService;
  11. use addons\Store\common\services\ReserveGoodsService;
  12. use addons\Store\common\services\StaffService;
  13. use addons\Store\common\services\StoreReserveSettingService;
  14. use api\controllers\OnAuthController;
  15. use common\enums\GoodsTypeEnum;
  16. use common\enums\StatusEnum;
  17. use common\helpers\LocationHelper;
  18. use common\helpers\StringHelper;
  19. use common\models\order\OrderReserveComments;
  20. class StaffController extends OnAuthController
  21. {
  22. public $modelClass = '';
  23. /**
  24. * 不用进行登录验证的方法
  25. *
  26. * 例如: ['index', 'update', 'create', 'view', 'delete']
  27. * 默认全部需要验证
  28. *
  29. * @var array
  30. */
  31. protected $authOptional = [];
  32. /**
  33. * 门店技师列表
  34. * @return mixed|null
  35. */
  36. public function actionIndex()
  37. {
  38. $data = \Yii::$app->request->get();
  39. $rules = [
  40. [['name', 'sort'], 'string'], // 综合,距离,单量,好评
  41. [['age_min', 'age_max', 'gender', 'page', 'limit', 'store_id'], 'integer'], // 不限,男,女
  42. [['lng', 'lat'], 'number'],
  43. // [['store_lng', 'store_lat'], 'required'],
  44. ];
  45. $res = \Yii::$app->services->validate->validate($data, $rules);
  46. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  47. // 查询门店的
  48. $data['is_store'] = StatusEnum::ENABLED;
  49. if (!empty($data['sort'])) {
  50. switch ($data['sort']) {
  51. case 'order_num':
  52. case 'service_rating':
  53. $data['sort'] = "{$data['sort']} desc";
  54. break;
  55. case 'distance':
  56. $data['sort'] = "{$data['sort']} asc";
  57. }
  58. }
  59. $data['store_status'] = StatusEnum::ENABLED;
  60. $is_show_staff = 1;
  61. if(!empty($data['store_id'])){
  62. $user_ids = [];
  63. $goods_ids = StoreGoods::find()->where(['store_id'=>$data['store_id'],'goods_type'=>GoodsTypeEnum::GoodsTypeReserved,'status'=>StatusEnum::ENABLED,'is_on_sale'=>1,'check_status'=>1])
  64. ->select('id')->column();
  65. if(empty($goods_ids)){
  66. $is_show_staff = 0;
  67. }else{
  68. //关联门店预约商品
  69. $user_ids = ReservationServiceStoreGoods::find()->where(['store_id'=>$data['store_id'],'goods_id'=>$goods_ids,'status'=>StatusEnum::ENABLED])
  70. ->select('user_id')->groupBy('user_id')->column();
  71. if(empty($user_ids)){
  72. $is_show_staff = 0;
  73. }
  74. }
  75. //关联门店次卡
  76. $sec_user_ids = ReservationServiceStoreSecondaryCard::find()->where(['store_id' => $data['store_id'], 'status' => StatusEnum::ENABLED])
  77. ->select('user_id')->groupBy('user_id')->column();
  78. if (!empty($sec_user_ids)) {
  79. $user_ids = array_merge($user_ids, $sec_user_ids);
  80. $is_show_staff = 1;
  81. }
  82. $data['user_id_arr'] = $user_ids;
  83. }
  84. $ret = (new StaffService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'store_id' => $data['store_id']]))->page($data);
  85. if (!empty($ret['list'])) {
  86. foreach ($ret['list'] as &$item) {
  87. $item['gender_txt'] = ReservationServiceEnum::GENDER_MAP[$item['gender']];
  88. $item['distance'] = LocationHelper::formatDistance((new LocationHelper())
  89. ->getDistanceByGeo($item['latitude'], $item['longitude'], $data['lat'], $data['lng']));
  90. $item['comment_num'] = OrderReserveComments::find()->where(['tech_user_id' => $item['user_id']])
  91. ->andWhere(['store_id' => $item['store_id']])->count();
  92. $item['service_rating'] = $item['comment_num'] >= 10 ? $item['store_service_rating'] : 0;
  93. }
  94. }
  95. $ret['is_show_staff'] = $is_show_staff;
  96. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  97. }
  98. /**
  99. * 技师入驻
  100. * @return mixed|null
  101. */
  102. public function actionSettle()
  103. {
  104. $service = new StaffService(['user_id' => $this->user_id, 'mall_id' => $this->mall_id]);
  105. if (\Yii::$app->request->isGet) {
  106. // 获取申请详情
  107. // 未提交
  108. // 审核中
  109. // 被拒绝
  110. // 已通过
  111. // 0:待审核;1:已通过;2:未通过
  112. return $this->success('获取成功', $service->frontDetail());
  113. } else { // 申请
  114. $data = \Yii::$app->request->post();
  115. $rules = [
  116. [[ 'store_id'], 'required'],
  117. // [['name','pic', 'phone'], 'string'],
  118. [['store_id'], 'integer'],
  119. // ['phone', 'match', 'pattern' => '/^1\d{10}$/', 'message' => '请输入正确的手机号码'],
  120. ];
  121. $res = \Yii::$app->services->validate->validate($data, $rules, [
  122. // 'name' => '姓名',
  123. // 'pic' => '相片',
  124. // 'phone' => '电话',
  125. 'store_id' => '门店',
  126. ]);
  127. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  128. $ret = $service->create($data);
  129. return is_string($ret) ? $this->error($ret) : $this->success('提交成功', $ret);
  130. }
  131. }
  132. /**
  133. * 技师详情
  134. * @return mixed|null
  135. */
  136. public function actionDetail()
  137. {
  138. $data = \Yii::$app->request->get();
  139. $rules = [
  140. [['id'], 'required'],
  141. [['id', 'store_id'], 'integer'],
  142. [['lng', 'lat'], 'number'],
  143. ];
  144. $res = \Yii::$app->services->validate->validate($data, $rules);
  145. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  146. $ret = (new StaffService(['mall_id' => $this->mall_id, 'store_id' => $data['store_id'] ?? 0]))->detail($data['id']);
  147. $ret['idcard'] = StringHelper::hideStr($ret['idcard'], 1, 16);
  148. // 距离
  149. if (is_array($ret)) {
  150. $ret['distance'] = LocationHelper::formatDistance((new LocationHelper())->getDistanceByGeo($data['lat'], $data['lng'], $ret['store_lat'], $ret['store_lng']));
  151. $ret['gender_txt'] = ReservationServiceEnum::GENDER_MAP[$ret['gender']];
  152. $ret['store'] = $ret['settle']['store'] ?? [];
  153. $ret['order_num'] = $ret['store_order_num'];
  154. if (!empty($ret['is_working'])) {
  155. // 再判断是否能约/什么时候能约
  156. $ret['reserve_text'] = "";
  157. // 判断什么时候能约
  158. $reserve_text = TechniciansService::getTechLatelyCanReserveAt($ret);
  159. if (empty($reserve_text)) {
  160. $ret['is_working'] = StatusEnum::DISABLED;
  161. } else {
  162. $ret['reserve_text'] = "{$reserve_text}可约";
  163. }
  164. $ret['work_times'] = ReservationServiceWorkTime::find()->where(['mall_id' => $this->mall_id])
  165. ->andWhere(['user_id' => $ret['user_id']])
  166. ->andWhere(['status' => StatusEnum::ENABLED])
  167. ->andWhere(['week_day' => date('w')])
  168. ->select('text')->column();
  169. }
  170. }
  171. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  172. }
  173. /**
  174. * 获取技师评价列表
  175. * @return mixed|null
  176. */
  177. public function actionComments()
  178. {
  179. $data = \Yii::$app->request->get();
  180. $rules = [
  181. [['tech_id', 'page', 'limit', 'store_id'], 'integer'],
  182. [['tech_id', 'store_id'], 'required'],
  183. [['type'], 'safe'],
  184. ];
  185. $res = \Yii::$app->services->validate->validate($data, $rules);
  186. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  187. $ret = (new ReserveCommentService(['store_id' => $data['store_id'], 'mall_id' => $this->mall_id]))->page($data);
  188. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  189. }
  190. /**
  191. * 技师项目
  192. * @return mixed|void|null
  193. */
  194. public function actionProjects()
  195. {
  196. // 获取项目
  197. $data = \Yii::$app->request->get();
  198. $rules = [
  199. [['store_id', 'id'], 'required'],
  200. [['store_id', 'id'], 'integer'],
  201. ];
  202. $res = \Yii::$app->services->validate->validate($data, $rules);
  203. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  204. $ret = (new ReserveGoodsService(['mall_id' => $this->mall_id, 'store_id' => $data['store_id']]))->customListByStore($data);
  205. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  206. }
  207. public function actionStoreList()
  208. {
  209. $list = Store::lists([
  210. 'where' => [
  211. ['mall_id' => $this->mall_id],
  212. ['status' => StatusEnum::ENABLED]
  213. ],
  214. 'select'=> 'id, store_name',
  215. 'order' => 'id asc',
  216. ]);
  217. return $this->success('获取成功', $list);
  218. }
  219. /**
  220. * h5端-预约时间列表-到店分配/技师不选项
  221. * @return mixed|null
  222. */
  223. public function actionStoreReservationTimeList()
  224. {
  225. try {
  226. $params = \Yii::$app->request->get();
  227. $rules = [
  228. [['sku_id','store_id'], 'required'],
  229. [['date'], 'safe'],
  230. ];
  231. $res = \Yii::$app->services->validate->validate($params, $rules);
  232. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  233. if(empty($params['date'])){
  234. $params['date'] = date('Y-m-d');
  235. }
  236. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->toStoreReservationTimeList($params);
  237. return $this->success('获取成功', $list);
  238. }catch (\Exception $e){
  239. return $this->error($e->getMessage());
  240. }
  241. }
  242. /**
  243. * 技师可预约时间列表
  244. * @return mixed|null
  245. */
  246. public function actionTechniciansReservationTimeList()
  247. {
  248. try {
  249. $params = \Yii::$app->request->get();
  250. $rules = [
  251. [['sku_id','store_id','technicians_id'], 'required'],
  252. ];
  253. $res = \Yii::$app->services->validate->validate($params, $rules);
  254. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  255. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->techniciansReservationTimeList($params);
  256. return $this->success('获取成功', $list);
  257. }catch (\Exception $e){
  258. return $this->error($e->getMessage());
  259. }
  260. }
  261. public function actionSearch()
  262. {
  263. try {
  264. $params = \Yii::$app->request->get();
  265. $rules = [
  266. [['sku_id','goods_id','store_id','lat','lng','date','time'], 'required'],
  267. [['page','limit','name','min_age','max_age','gender','sort','is_default_jishi'], 'safe'],
  268. ];
  269. $res = \Yii::$app->services->validate->validate($params, $rules);
  270. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  271. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->search($params);
  272. return $this->success('获取成功', $list);
  273. }catch (\Exception $e){
  274. return $this->error($e->getMessage());
  275. }
  276. }
  277. public function actionTopFourth()
  278. {
  279. try {
  280. $params = \Yii::$app->request->get();
  281. $rules = [
  282. [['sku_id'], 'required'],
  283. [['id'], 'safe'],
  284. ];
  285. $res = \Yii::$app->services->validate->validate($params, $rules);
  286. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  287. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id]))->topFourth($params);
  288. return $this->success('获取成功', $list);
  289. }catch (\Exception $e){
  290. return $this->error($e->getMessage());
  291. }
  292. }
  293. public function actionGetDate()
  294. {
  295. try {
  296. $params = \Yii::$app->request->get();
  297. $rules = [
  298. [['sku_id','store_id'], 'required'],
  299. [['start'], 'safe'],
  300. ];
  301. $res = \Yii::$app->services->validate->validate($params, $rules);
  302. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  303. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id,'store_id'=>$params['store_id']]))->getDate($params);
  304. return $this->success('成功', $list);
  305. }catch (\Exception $e){
  306. return $this->error($e->getMessage());
  307. }
  308. }
  309. public function actionGetTimes()
  310. {
  311. try {
  312. $params = \Yii::$app->request->get();
  313. $rules = [
  314. [['sku_id','goods_id','store_id','date'], 'required'],
  315. ];
  316. $res = \Yii::$app->services->validate->validate($params, $rules);
  317. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  318. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id,'store_id'=>$params['store_id']]))->getTimes($params);
  319. return $this->success('成功', $list);
  320. }catch (\Exception $e){
  321. return $this->error($e->getMessage());
  322. }
  323. }
  324. /**
  325. * 门店预约商品商品详情-服务时间列表
  326. * @return mixed|null
  327. */
  328. public function actionServiceTimeList()
  329. {
  330. try {
  331. $params = \Yii::$app->request->get();
  332. $rules = [
  333. [['sku_id','store_id','id'], 'required'],
  334. ];
  335. $res = \Yii::$app->services->validate->validate($params, $rules);
  336. if (!$res) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  337. $list = (new StoreReserveSettingService(['mall_id' => $this->mall_id, 'store_id' => $params['store_id']]))->serviceTimeList($params);
  338. return $this->success('获取成功', $list);
  339. }catch (\Exception $e){
  340. return $this->error($e->getMessage());
  341. }
  342. }
  343. }