store_id)) $params['store_id'] = $this->store_id; $params['is_store'] = StatusEnum::ENABLED; // $params['store_status'] = StatusEnum::ENABLED; return (new UserService())->page($this->mall_id, $params); } /** * 待审核列表 * @param array $params * @return array|false|mixed|null */ public function applyPage(array $params) { $where = [ ['mall_id' => $this->mall_id], ['store_id' => $this->store_id], ['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]] ]; if (!empty($params['user_id'])) { $where[] = ['user_id' => $params['user_id']]; } elseif (!empty($params['keyword'])) { $uids = User::find()->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']]]) ->select('id')->column(); if (!empty($uids)) { $where[] = ['user_id' => $uids]; } else { return []; } } if (!empty($params['name'])) { $where[] = ['like', 'name', $params['name']]; } if (!empty($params['mobile'])) { $where[] = ['like', 'phone', $params['mobile']]; } if (!empty($params['date_start'])) $where[] = ['>=', 'created_at', strtotime($params['date_start'])]; if (!empty($params['date_end'])) $where[] = ['<=', 'created_at', strtotime($params['date_end'])]; $l_user = StoreStaffApply::lists([ 'where' => $where, 'order' => 'id desc', 'index' => 'user_id' ]); if (empty($l_user)) return []; $user_ids = array_column($l_user, 'user_id'); $ret = (new UserService())->page($this->mall_id, [ 'user_ids' => $user_ids, 'limit' => $params['limit'] ?? 10, 'address' => $params['address'] ?? '', 'page' => 1, ]); if (!empty($ret['list'])) { foreach ($ret['list'] as &$item) { $item['settle'] = $l_user[$item['user_id']] ?? null; } } return $ret; } /** * 审核 * @param array $params * @return string|true */ public function audit(array $params) { // 审核 /** * @var $staff StoreStaffApply */ $staff = StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['id' => $params['id']], ['store_id' => $this->store_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ]); if (empty($staff)) return '记录不存在'; if ($staff->check_status != 0) return '当前记录不可审核'; $t = \Yii::$app->db->beginTransaction(); try { $staff->check_status = $params['status']; $staff->check_remark = !empty($params['remark']) ? $params['remark'] : ''; if (!$staff->save()) throw new \Exception($staff->getErrorMessage()); /** * @var $store Store */ $store = Store::getOne([[ 'id' => $staff->store_id ]]); if (empty($store)) throw new \Exception('门店不存在'); // 那边需要绑定store_id if ($staff->check_status == StatusEnum::ENABLED) { (new UserService())->bindStore($this->mall_id, $staff->user_id, $store); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); return $e->getMessage(); } return true; } /** * 设置接单状态 * @param int $id * @return string|true */ public function setStatus(int $id) { try { return (new UserService())->setStoreStatus($this->mall_id, $id, $this->store_id); } catch (\Exception $e) { return $e->getMessage(); } } /** * 技师详情 * @param int $id * @return mixed|string */ public function detail(int $id) { // 技师详情 try { $ret = (new UserService())->detail($this->mall_id, $id, $this->store_id); if (!empty($ret)) { $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id, store_name, shop_owner, shop_mobile, logo_img'); $ret['settle'] = ['store' => $store, 'updated_at' => $ret['created_at']]; $ret['qualification_certificate'] = Json::decode($ret['qualification_certificate']); $ret['idcard_images'] = [ $ret['idcard_front'], $ret['idcard_back'], ]; } return $ret; } catch (\Exception $e) { return $e->getMessage(); } } /** * 移除数据 * @param int $id * @return string|true */ public function delete(int $id) { /** * @var $staff StoreStaffApply */ $staff = StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ]); $t = \Yii::$app->db->beginTransaction(); try { if (!empty($staff)) { $staff->status = StatusEnum::DELETE; if (!$staff->save()) throw new \Exception($staff->getErrorMessage()); } (new UserService())->removeStore($this->mall_id, $id, $this->store_id); ReservationServiceStoreGoods::updateAll(['status' => StatusEnum::DELETE], ['user_id' => $id, 'mall_id' => $this->mall_id, 'store_id' => $this->store_id]); $t->commit(); } catch (\Exception $e) { $t->rollBack(); return $e->getMessage(); } return true; } /** * 接单排行榜 * @return array */ public function orderRank() { // 单量排行榜 $params['store_id'] = $this->store_id; $params['sort'] = 'store_order_num desc'; $params['limit'] = 10; $params['page'] = 1; return (new UserService())->page($this->mall_id, $params); } /** * 服务评分排行榜 * @return array|false|mixed|null */ public function ratingRand() { $params['store_id'] = $this->store_id; $params['sort'] = 'store_service_rating desc'; $params['limit'] = 10; $params['page'] = 1; return (new UserService())->page($this->mall_id, $params); } /** * @return int[] */ public function statistics() { // 累计服务数量 // 昨日服务数量 return (new OrderService())->dataStatistics($this->mall_id, $this->store_id); } /** * 数据统计 * @param int $id * @return array */ public function statisticsByStaff(int $id) { // 累计订单 // 累计收益 // 本月收益 // 本月接单 return (new UserService())->statisticsByStaff($this->mall_id, $id, $this->store_id); } public function create(array $params) { // 需要判断是否有申请技师 try { (new UserService())->fetch($this->mall_id, $this->user_id); } catch (\Exception $e) { return $e->getMessage(); } /** * @var $staff StoreStaffApply */ $staff = StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $this->user_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ]); if (empty($staff)) { $staff = new StoreStaffApply(); $staff->mall_id = $this->mall_id; $staff->user_id = $this->user_id; } else { if ($staff->check_status == StatusEnum::ENABLED) return '您不可再次申请'; } $reservation_service_user = ReservationServiceUser::findOne(['user_id' => $this->user_id]); if (empty($reservation_service_user)) { return '请先申请成为平台技师'; } $staff->check_status = StatusEnum::DISABLED; $staff->phone = $reservation_service_user['mobile']; $staff->store_id = $params['store_id']; $staff->pic = $reservation_service_user['avatar']; $staff->name = $reservation_service_user['name']; $staff->created_at = time(); // 每次提交都是最新的时间 if (!$staff->save()) return $staff->getErrorMessage(); // 技师申请 return $staff; } /** * 获取申请详情 * @return mixed|null */ public function frontDetail() { return StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $this->user_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ], true, [], 'id asc'); } /** * 添加技师 * @param array $params * @return StoreStaffApply|mixed|string|null */ public function add(array $params) { try { $user = ReservationServiceUser::findOne(['user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]); $store = Store::findOne(['id' => $this->store_id]); if (empty($user)) throw new \Exception('请先前往总后台预约服务插件添加该技师'); if (empty($store)) throw new \Exception('门店不存在'); if (!empty($user)) { $user->store_id = $this->store_id; $user->store_lat = $store->latitude; $user->store_lng = $store->longitude; if (!$user->save()) throw new \Exception($user->getErrorMessage()); } /** * @var $staff StoreStaffApply */ $staff = StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $params['user_id']], ['store_id' => $params['store_id']], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ]); if (empty($staff)) { $staff = new StoreStaffApply(); $staff->mall_id = $this->mall_id; $staff->user_id = $params['user_id']; } else { throw new \Exception("当前技师已存在"); } $staff->phone = $user->mobile; $staff->store_id = $params['store_id']; $staff->pic = $user->avatar; $staff->name = $user->name; $staff->check_status = StatusEnum::ENABLED; if (!$staff->save()) throw new \Exception($staff->getErrorMessage()); return $staff; } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } /** * 获取技师关联的门店预约商品列表 * @param $params * @return false|mixed * @throws \Exception */ public function getAssociationStoreGoods($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $list = ReservationServiceStoreGoods::lists([ 'where' => [ ['user_id' => $params['user_id']], ['status' => StatusEnum::ENABLED] ], 'with' => [ 'goods' => function ($q) { $q->select('id,goods_name,price,cover_pic,created_at'); } ], 'select' => 'goods_id' ] ); $goods_ids = array_column($list, 'goods_id'); $list = StoreGoods::lists([ 'where' => [['id' => $goods_ids]], 'select' => 'id,goods_name,price,cover_pic,created_at' ] ); return $list; } /** * 获取门店预约商品列表 * @param $params * @return false|mixed * @throws \Exception */ public function getStoreGoods($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $where = [ ['store_id' => $this->store_id], ['status' => StatusEnum::ENABLED], ['goods_type' => GoodsTypeEnum::GoodsTypeReserved] ]; if (!empty($params['keyword'])) { $keyword = trim($params['keyword']); $where[] = [ 'or', ['like', 'goods_name', $keyword], ['id' => $keyword] ]; } $params['where'] = $where; $params['select'] = 'id,goods_name,price,cover_pic,created_at'; $list = StoreGoods::listPage($params); return $list; } /** * 操作技师关联的门店预约商品列表 * @param $params * @return false|mixed * @throws \Exception */ public function handleAssociationStoreGoods($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $params['store_id'] = $this->store_id; $params['mall_id'] = $this->mall_id; ReservationServiceStoreGoods::setData($params); return []; } public function addStallUser(array $params) { try { $user = ReservationServiceUser::findOne(['user_id' => $params['user_id'], 'status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id]); $store = Store::findOne(['id' => $this->store_id]); if (empty($user)) throw new \Exception('请先前往总后台预约服务插件添加该技师'); if (empty($store)) throw new \Exception('门店不存在'); if ($user['store_id'] && $user['store_id'] != $this->store_id) { throw new \Exception('该技师已经绑定其他门店,无法添加'); } $user->load($params, ''); if (!$user->save()) throw new \Exception($user->getErrorMessage()); $staff = StoreStaffApply::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $params['user_id']], ['store_id' => $params['store_id']], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]] ]); if (empty($staff)) { $staff = new StoreStaffApply(); $staff->mall_id = $this->mall_id; $staff->user_id = $params['user_id']; } $staff->phone = $user->mobile; $staff->store_id = $params['store_id']; $staff->pic = $user->avatar; $staff->name = $user->name; $staff->check_status = StatusEnum::ENABLED; if (!$staff->save()) throw new \Exception($staff->getErrorMessage()); return $user; } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } /** * 获取技师关联的门店预约商品列表-分页 * @param $params * @return false|mixed * @throws \Exception */ public function getAssociationStoreGoodsPage($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $list = ReservationServiceStoreGoods::lists([ 'where' => [ ['user_id' => $params['user_id']], ['status' => StatusEnum::ENABLED] ], 'select' => 'goods_id' ] ); $goods_ids = array_column($list, 'goods_id'); $where = [['id' => $goods_ids]]; $params['where'] = $where; $params['with'] = 'cats'; $params['select'] = 'id,goods_name,price,cover_pic,created_at'; $list = StoreGoods::listPage($params); if (!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['cate_name'] = ''; foreach ($item['cats'] as $val) { $item['cate_name'] .= $val['name'] . ','; } $item['cate_name'] = trim($item['cate_name'], ','); } } return $list; } /** * 获取关联的次卡 * @param $params * @return false|mixed * @throws \Exception */ public function getAssociationStoreSecondaryCard($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $list = ReservationServiceStoreSecondaryCard::lists([ 'where' => [ ['user_id' => $params['user_id']], ['status' => StatusEnum::ENABLED] ], 'select' => 'secondary_card_id' ] ); $secondary_card_ids = array_column($list, 'secondary_card_id'); $list = SecondaryCard::lists([ 'where' => [['id' => $secondary_card_ids]], 'select' => 'id,name,create_source_type,created_at' ] ); foreach ($list as &$item) { $item['create_source_type_text'] = $item['create_source_type'] == 0 ? '平台' : '门店'; } return $list; } /** * 获取门店次卡列表 * @param $params * @return array|false|mixed|null * @throws \Exception */ public function getStoreSecondaryCard($params) { $list = ReservationServiceStoreSecondaryCard::lists([ 'where' => [ ['user_id' => $params['user_id']], ['status' => StatusEnum::ENABLED] ], 'select' => 'secondary_card_id' ] ); $list = array_column($list, 'secondary_card_id'); $params['where'][] = ['not in', 'sc.id', $list]; $params['where'][] = ['sc.mall_id' => $this->mall_id]; $params['where'][] = ['sc.status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $params['where'][] = ['sc.reservation_model' => SecondaryCardEnum::RESERVATION_PEOPLE]; if (!empty($params['keyword'])) { $keyword = trim($params['keyword']); $params['where'][] = [ 'or', ['like', 'sc.name', $keyword], ['sc.id' => $keyword] ]; } $params['where'][] = [ 'or', ['sc.use_type' => 0], ['scrs.store_id' => $this->store_id, 'scrs.store_type' => 1] ]; $params['join'] = [['left join', SecondaryCardRelateStore::tableName() . ' as scrs', 'sc.id = scrs.secondary_card_id']]; $params['order'] = 'sc.id DESC'; $params['alias'] = 'sc'; $params['select'] = 'sc.id,sc.name,sc.create_source_type,sc.created_at'; $pageData = SecondaryCard::listPage($params, false); if (!empty($pageData['list'])) { foreach ($pageData['list'] as &$item) { $item['create_source_type_text'] = $item['create_source_type'] == 0 ? '平台' : '门店'; } } return $pageData; } public function handleAssociationStoreSecondaryCard($params) { if (!MallAddons::isInstall($this->mall_id, 'ReservationService')) { throw new \Exception('未安装预约服务插件'); } $params['store_id'] = $this->store_id; $params['mall_id'] = $this->mall_id; ReservationServiceStoreSecondaryCard::setData($params); return []; } }