From 344d420e998aec3f7bf45b65c2cf228d232d50ed Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 4 Jun 2024 11:12:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/user/UserController.php | 7 +++++ app/api/lists/product/ProductLists.php | 10 +++++++- app/api/lists/store/SystemStoreLists.php | 20 +++++++++++++-- app/api/logic/user/UserLogic.php | 30 +++++++++++++++++++--- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index 055c9bd6b..31f476a3a 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -35,4 +35,11 @@ class UserController extends BaseApiController } + public function info() + { + return $this->success('success', UserLogic::info($this->userId)); + + } + + } \ No newline at end of file diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index 807434814..a7cc41cd5 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -112,13 +112,21 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface } $where[]=['store_id','=',$store_id]; - return StoreBranchProduct::where($this->searchWhere)->where($where) + $data = StoreBranchProduct::where($this->searchWhere)->where($where) ->field(['id', 'product_id','cate_id','store_name', 'store_id','price', 'bar_code','image','sales','store_info','delete_time','unit']) ->limit($this->limitOffset, $this->limitLength) ->with(['className','unitName']) ->order($order) ->select() ->toArray(); + foreach ($data as &$value){ + $value['is_default'] = 0; + if($store_id == 2){ + $value['is_default'] = 1; + } + } + return $data; + // return StoreProduct::where($this->searchWhere)->where($where) // ->field(['id', 'cate_id','store_name','unit', 'ot_price', 'bar_code','image','sales','store_info']) diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 672c7f404..2688c24cc 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -7,6 +7,8 @@ use app\admin\lists\BaseAdminDataLists; use app\common\enum\YesNoEnum; use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; +use app\MyBusinessException; +use think\Exception; /** @@ -44,15 +46,29 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function lists(): array { + $latitude = $this->request->get('latitude',''); + $longitude = $this->request->get('longitude',''); + if(empty($longitude) || empty($latitude)){ + throw new MyBusinessException('缺失经纬度'); + } $where[]=['is_show','=',YesNoEnum::YES]; - return SystemStore::where($this->searchWhere)->where($where) + $data = SystemStore::where($this->searchWhere)->where($where) ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show', - 'day_time','is_store','latitude','longitude' + 'day_time','is_store','latitude','longitude','day_start','day_end','is_store' + ,'is_send' ]) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); + + foreach ($data as &$value){ + $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); + } + usort($data, function ($a, $b) { + return $a['distance'] <=> $b['distance']; + }); + return $data; } diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index 939903a38..75ffdb475 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -3,10 +3,7 @@ namespace app\api\logic\user; -use app\common\{ - logic\BaseLogic, - model\user\User, - service\wechat\WeChatMnpService}; +use app\common\{logic\BaseLogic, model\system_store\SystemStore, model\user\User, service\wechat\WeChatMnpService}; /** * 会员逻辑层 @@ -56,4 +53,29 @@ class UserLogic extends BaseLogic } + public static function info($uid) + { + $data = User::where('id',$uid) + ->field('avatar,real_name,nickname,account,mobile,sex,login_ip,user_money') + ->find(); + + //判断是不是员工 + if($data){ + $data = $data->toArray(); + $data['is_staff'] = 0; + $data['store_id'] = 0; + if(isset($data['mobile']) && $data['mobile']){ + $check = SystemStore::where('phone',$data['mobile'])->find()??[]; + if ($check){ + $data['is_staff'] = 1; + $data['store_id'] = $check['store_id']; + } + } + }else{ + $data = []; + } + return $data; + } + + } \ No newline at end of file