From 92fe8d81d613f26f7767bbf258e94e54d2e46163 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 9 Sep 2020 19:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E4=B8=93?= =?UTF-8?q?=E5=91=98=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/HomeController.php | 35 ++++++++++++----- app/Model/v3/ServicePersonnel.php | 30 ++++++++++++++ .../UserCenterBlockService.php | 39 ++++++++++++++----- .../v3/Implementations/UserInfoService.php | 6 +++ .../UserCenterBlockServiceInterface.php | 2 +- .../Interfaces/UserInfoServiceInterface.php | 2 + 6 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 app/Model/v3/ServicePersonnel.php diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index dd95bd9..c6c86bb 100644 --- a/app/Controller/v3/HomeController.php +++ b/app/Controller/v3/HomeController.php @@ -122,19 +122,34 @@ class HomeController extends BaseController { $params = $request->validated(); $data['user'] = $this->userInfoService->detail($params['user_id']); - $data['user']['store_info'] = $this->userInfoService->getStoreByUID($params['user_id']); - $data['user']['role'] = [ - [ + $store_info = $this->userInfoService->getStoreByUID($params['user_id']); + $sp_info = $this->userInfoService->getServicePersonnelByUID($params['user_id']); + + $data['user']['store_info'] = $store_info; + $data['user']['sp_info'] = $sp_info; + + + $roles = []; + //角色判断 + if($store_info){ + $roles[] = [ + 'key'=>'store', 'title'=>'商家', 'color'=>'#0091FF' - ], - [ - 'title'=>'骑手', - 'color'=>'#009100' - ], - ]; + ]; + } + + if($sp_info){ + $roles[] = [ + 'key'=>'sp', + 'title'=>'服务', + 'color'=>'#0091FF' + ]; + } + $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']); $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']); + $data['user']['role'] = $roles; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $data['badge'] = [ @@ -148,7 +163,7 @@ class HomeController extends BaseController $data['badge'] = array_merge($data['badge'], $badge); } - $data['block'] = $this->userCenterBlockService->all(); + $data['block'] = $this->userCenterBlockService->all($roles); return $this->success($data); } diff --git a/app/Model/v3/ServicePersonnel.php b/app/Model/v3/ServicePersonnel.php new file mode 100644 index 0000000..f862bb3 --- /dev/null +++ b/app/Model/v3/ServicePersonnel.php @@ -0,0 +1,30 @@ + 'array' + // ]; +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/UserCenterBlockService.php b/app/Service/v3/Implementations/UserCenterBlockService.php index f918fb5..72c8675 100644 --- a/app/Service/v3/Implementations/UserCenterBlockService.php +++ b/app/Service/v3/Implementations/UserCenterBlockService.php @@ -22,13 +22,14 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface // TODO: Implement undo() method. } - public function all() + public function all($roles = []) { // $img_host = config('alioss.img_host').'/'; - return [ + + $blocks = [ [ 'type' => 'user', 'title' => '常用功能', @@ -39,15 +40,35 @@ class UserCenterBlockService implements UserCenterBlockServiceInterface ['name' => '联系服务站', 'icon' => $img_host . 'user_icons/contact_fwz.png', 'type' => 'page', 'path' => '/pages/contactMarket/contactMarket','command'=>'contact_fwz'], ['name' => '关于懒族', 'icon' => $img_host . 'user_icons/about_lz.png', 'type' => 'page', 'path' => '/pages/aboutUs/aboutUs','command'=>'about'], ] - ], - [ - 'type' => 'store_user', - 'title' => '商户相关', - 'items' => [ - ['name' => '商家入口', 'icon' => $img_host . 'user_icons/shop_enter.png', 'type' => 'page', 'path' => '/pages/shopLogin/shopLogin','command'=>'store_login'] - ] ] ]; + + foreach ($roles as $key => $item) { + # code... + + if($item['key'] == 'store'){ + $blocks[] = [ + 'type' => 'store_user', + 'title' => '商户相关', + 'items' => [ + ['name' => '商家入口', 'icon' => $img_host . 'user_icons/shop_enter.png', 'type' => 'page', 'path' => '/pages/shopLogin/shopLogin','command'=>'store_login'] + ] + ]; + } + + if($item['key'] == 'sp'){ + $blocks[] = [ + 'type' => 'sp_user', + 'title' => '服务专员', + 'items' => [ + ['name' => '评价', 'icon' => $img_host . 'user_icons/shop_enter.png', 'type' => 'page', 'path' => '/zh_cjdianc/pages/appraise/index','command'=>'store_login'] + ] + ]; + } + + } + + return $blocks; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/UserInfoService.php b/app/Service/v3/Implementations/UserInfoService.php index 5a11ad2..f8df854 100644 --- a/app/Service/v3/Implementations/UserInfoService.php +++ b/app/Service/v3/Implementations/UserInfoService.php @@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode; use App\Constants\v3\SsdbKeys; use App\Exception\ErrorCodeException; use App\Model\v3\User; +use App\Model\v3\ServicePersonnel; use App\Model\v3\Store; use App\Service\v3\Interfaces\UserInfoServiceInterface; use App\TaskWorker\SSDBTask; @@ -82,5 +83,10 @@ class UserInfoService implements UserInfoServiceInterface return $store; } + public function getServicePersonnelByUID($userId) + { + $sp = ServicePersonnel::where('user_id',$userId)->select(['id'])->first(); + return $sp; + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/UserCenterBlockServiceInterface.php b/app/Service/v3/Interfaces/UserCenterBlockServiceInterface.php index c0f8769..b554273 100644 --- a/app/Service/v3/Interfaces/UserCenterBlockServiceInterface.php +++ b/app/Service/v3/Interfaces/UserCenterBlockServiceInterface.php @@ -9,5 +9,5 @@ interface UserCenterBlockServiceInterface public function do(); public function check(); public function undo(); - public function all(); + public function all($roles = []); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/UserInfoServiceInterface.php b/app/Service/v3/Interfaces/UserInfoServiceInterface.php index e591d03..3370d37 100644 --- a/app/Service/v3/Interfaces/UserInfoServiceInterface.php +++ b/app/Service/v3/Interfaces/UserInfoServiceInterface.php @@ -9,4 +9,6 @@ interface UserInfoServiceInterface public function undo($userId); public function detail($userId); public function getStoreByUID($userId); + public function getServicePersonnelByUID($userId); + } \ No newline at end of file