From 0e1c088ac0bbb64e39adebe0efb384ff7c2dbd8b Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sat, 12 Sep 2020 14:28:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=BA=97=E9=93=BA=20?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=20=E4=BC=98=E6=83=A0=E5=88=B8=E6=95=B0?= =?UTF-8?q?=E9=87=8F=20=E6=95=B0=E6=8D=AE=E5=AE=9E=E8=A3=85=20=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CollectStoreController.php | 6 ++- app/Controller/v3/HomeController.php | 8 ++-- app/Controller/v3/LocationController.php | 6 +-- app/Controller/v3/SearchController.php | 4 +- app/Model/v3/StoreUsers.php | 10 +++++ app/Model/v3/UserCollection.php | 7 ++++ app/Request/v3/UserAndStoreRequest.php | 37 +++++++++++++++++++ app/Request/v3/UserRequest.php | 36 ++++++++++++++++++ .../Implementations/CollectStoreService.php | 22 +++++++++++ .../v3/Implementations/CouponRecService.php | 9 +++++ .../v3/Implementations/CouponService.php | 8 ---- .../v3/Implementations/LocationService.php | 17 +++++++-- .../v3/Implementations/StoreLoginService.php | 15 +++++++- .../Interfaces/CouponRecServiceInterface.php | 6 +++ .../v3/Interfaces/CouponServiceInterface.php | 7 ---- .../Interfaces/LocationServiceInterface.php | 4 +- config/config.php | 3 ++ 17 files changed, 172 insertions(+), 33 deletions(-) create mode 100644 app/Model/v3/StoreUsers.php create mode 100644 app/Request/v3/UserAndStoreRequest.php create mode 100644 app/Request/v3/UserRequest.php diff --git a/app/Controller/v3/CollectStoreController.php b/app/Controller/v3/CollectStoreController.php index 8dffdd9..453144c 100644 --- a/app/Controller/v3/CollectStoreController.php +++ b/app/Controller/v3/CollectStoreController.php @@ -3,6 +3,8 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use App\Request\v3\UserAndStoreRequest; +use App\Request\v3\UserRequest; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\CollectStoreServiceInterface; @@ -15,7 +17,7 @@ class CollectStoreController extends BaseController */ protected $collectStoreService; - public function update() + public function update(UserAndStoreRequest $request) { $params = $this->request->all(); //判断是否已收藏店铺 @@ -30,7 +32,7 @@ class CollectStoreController extends BaseController return $this->success(['is_collect' => $res]); } - public function getListByUser() + public function getListByUser(UserRequest $request) { $params = $this->request->all(); $res = $this->collectStoreService->getListByUser($params['user_id']); diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index ce46208..41c1bc8 100644 --- a/app/Controller/v3/HomeController.php +++ b/app/Controller/v3/HomeController.php @@ -16,7 +16,7 @@ use App\Service\v3\Interfaces\ActivityServiceInterface; use App\Service\v3\Interfaces\BannerServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface; -use App\Service\v3\Interfaces\CouponServiceInterface; +use App\Service\v3\Interfaces\CouponRecServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\RevenueListServiceInterface; @@ -51,9 +51,9 @@ class HomeController extends BaseController /** * @Inject - * @var CouponServiceInterface + * @var CouponRecServiceInterface */ - protected $couponService; + protected $couponRecService; /** * @Inject @@ -168,7 +168,7 @@ class HomeController extends BaseController } $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']); - $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']); + $data['user']['coupon_count'] = $this->couponRecService->countAvailableByUser($params['user_id']); $data['user']['role'] = $roles; $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); diff --git a/app/Controller/v3/LocationController.php b/app/Controller/v3/LocationController.php index d139be8..18ab8f6 100644 --- a/app/Controller/v3/LocationController.php +++ b/app/Controller/v3/LocationController.php @@ -6,7 +6,6 @@ use App\Controller\BaseController; use App\Model\v3\Market; use App\Service\v3\Interfaces\LocationServiceInterface; use Hyperf\Di\Annotation\Inject; - /** * 定位相关 * Class LocationController @@ -33,8 +32,9 @@ class LocationController extends BaseController public function getMarketListByLocation() { - $cityIds = [2163,2189]; - return $this->success($this->locationService->getMarketListByLocation($cityIds)); + $lng = $this->request->input('lng',0); + $lat = $this->request->input('lat',0); + return $this->success($this->locationService->getMarketListByLocation($lng,$lat)); } public function getMarketsInfo() diff --git a/app/Controller/v3/SearchController.php b/app/Controller/v3/SearchController.php index 626ce70..9e0c92b 100644 --- a/app/Controller/v3/SearchController.php +++ b/app/Controller/v3/SearchController.php @@ -78,7 +78,9 @@ class SearchController extends BaseController { $keywords = $this->request->input('keywords',''); $cityId = $this->request->input('city_id',2163); - $data = $this->locationService->searchMarket($keywords,$cityId); + $lng = $this->request->input('lng',0); + $lat = $this->request->input('lat',0); + $data = $this->locationService->searchMarket($keywords,$lng,$lat,$cityId); return $this->success(['markets' => $data]); } } \ No newline at end of file diff --git a/app/Model/v3/StoreUsers.php b/app/Model/v3/StoreUsers.php new file mode 100644 index 0000000..0098f79 --- /dev/null +++ b/app/Model/v3/StoreUsers.php @@ -0,0 +1,10 @@ + 'required|nonempty|integer', + 'store_id' => 'required|nonempty|integer', + ]; + } + + /** + * @return array + */ + public function messages(): array + { + return [ + '*.*' => ':attribute无效', + ]; + } + + public function attributes(): array + { + return parent::attributes(); + } +} diff --git a/app/Request/v3/UserRequest.php b/app/Request/v3/UserRequest.php new file mode 100644 index 0000000..d7bc540 --- /dev/null +++ b/app/Request/v3/UserRequest.php @@ -0,0 +1,36 @@ + 'required|nonempty|integer', + ]; + } + + /** + * @return array + */ + public function messages(): array + { + return [ + '*.*' => ':attribute无效', + ]; + } + + public function attributes(): array + { + return parent::attributes(); + } +} diff --git a/app/Service/v3/Implementations/CollectStoreService.php b/app/Service/v3/Implementations/CollectStoreService.php index 169021b..8ecbe1d 100644 --- a/app/Service/v3/Implementations/CollectStoreService.php +++ b/app/Service/v3/Implementations/CollectStoreService.php @@ -21,6 +21,20 @@ class CollectStoreService implements CollectStoreServiceInterface $userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,1); //店铺被收藏数自增 $storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$storeId,1); + //起线程记录到数据库 + go(function () use ($userId,$storeId){ + $marketId = Store::query()->where('id',$storeId)->value('market_id'); + UserCollection::query()->withTrashed()->updateOrCreate( + [ + 'store_id' => $storeId, + 'market_id' => $marketId, + 'user_id' => $userId + ], + [ + 'deleted_at' => null + ] + ); + }); return $userSet && $userIncr && $storeIncr; } @@ -39,6 +53,14 @@ class CollectStoreService implements CollectStoreServiceInterface $userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,'-1'); //店铺被收藏数自减 $storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$storeId,'-1'); + //起线程删除数据库 + go(function () use ($userId,$storeId){ + UserCollection::query()->where([ + ['user_id','=',$userId], + ['store_id','=',$storeId], + ]) + ->delete(); + }); return $userDel && $userIncr && $storeIncr; } //获取用户收藏店铺数量 diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index 3fb3d95..c987326 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -284,4 +284,13 @@ class CouponRecService implements CouponRecServiceInterface } + /** + * @inheritDoc + */ + public function countAvailableByUser($userId) + { + $coupons = $this->getListByUser($userId,'unused',1,9999); + $numberRemain= (array_column($coupons['coupon_list'], 'number_remain')); + return array_sum($numberRemain); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/CouponService.php b/app/Service/v3/Implementations/CouponService.php index c1b432b..8924015 100644 --- a/app/Service/v3/Implementations/CouponService.php +++ b/app/Service/v3/Implementations/CouponService.php @@ -40,14 +40,6 @@ class CouponService implements CouponServiceInterface // TODO: Implement undo() method. } - /** - * @inheritDoc - */ - public function countAvailableByUser($userId) - { - return mt_rand(0,10); - } - /** * 缓存优惠券今日使用情况 * @param $userId diff --git a/app/Service/v3/Implementations/LocationService.php b/app/Service/v3/Implementations/LocationService.php index a80a062..d6181a6 100644 --- a/app/Service/v3/Implementations/LocationService.php +++ b/app/Service/v3/Implementations/LocationService.php @@ -25,19 +25,24 @@ class LocationService implements LocationServiceInterface // TODO: Implement undo() method. } - public function getMarketListByLocation($cityIds) + public function getMarketListByLocation($lng,$lat) { + $cityIds = Market::query()->pluck('city_id'); $res = Area::query()->with('markets')->whereIn('id',$cityIds)->get(); foreach ($res as &$v){ foreach ($v->markets as &$m) { - $m->Distance = $this->getDistance($m->lng,$m->lat,108.370333,22.813527); + if(!empty($lng) && !empty($lat)){ + $m->Distance = ($this->getDistance($m->lng,$m->lat,$lng,$lat)).' km'; + }else{ + $m->Distance = ''; + } } } return $res; } - public function searchMarket($keywords,$cityId = 2163) + public function searchMarket($keywords,$lng,$lat,$cityId = 2163) { $res = Market::query()->where([ ['name','like','%'.$keywords.'%'], @@ -45,7 +50,11 @@ class LocationService implements LocationServiceInterface ]) ->get(); foreach ($res as &$v){ - $v->Distance = $this->getDistance($v->lng,$v->lat,108.370333,22.813527); + if(!empty($lng) && !empty($lat)){ + $v->Distance = ($this->getDistance($v->lng,$v->lat,$lng,$lat)).' km'; + }else{ + $v->Distance = ''; + } } return $res; } diff --git a/app/Service/v3/Implementations/StoreLoginService.php b/app/Service/v3/Implementations/StoreLoginService.php index 244ecef..ceb4357 100644 --- a/app/Service/v3/Implementations/StoreLoginService.php +++ b/app/Service/v3/Implementations/StoreLoginService.php @@ -4,14 +4,18 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; +use App\Model\v3\StoreUsers; use App\Service\v3\Interfaces\StoreLoginServiceInterface; class StoreLoginService implements StoreLoginServiceInterface { public function do($account,$password) { - if($account == $password){ - return true; + $storeUsersModel = StoreUsers::query()->where('username',$account)->first(); + $password = $this->stringHash($password,$storeUsersModel->salt); + var_dump($storeUsersModel,$password); + if($storeUsersModel->password === $password){ + return $storeUsersModel; }else{ throw new ErrorCodeException(ErrorCode::STORE_LOGIN_ERROR); } @@ -26,4 +30,11 @@ class StoreLoginService implements StoreLoginServiceInterface { // TODO: Implement undo() method. } + + function stringHash($password,$salt) + { + $authkey = config('lgoin.authkey'); + $password = "{$password}-{$salt}-{$authkey}"; + return sha1($password); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/CouponRecServiceInterface.php b/app/Service/v3/Interfaces/CouponRecServiceInterface.php index bb37912..c6d1b53 100644 --- a/app/Service/v3/Interfaces/CouponRecServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponRecServiceInterface.php @@ -10,4 +10,10 @@ interface CouponRecServiceInterface public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); public function getListByUser($userId,$type,$page = 1,$pagesize = 5); public function allForOnlineOrderAvailable($userId, $marketId); + /** + * 统计用户可使用优惠券数量 + * @param $userId + * @return mixed + */ + public function countAvailableByUser($userId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/CouponServiceInterface.php b/app/Service/v3/Interfaces/CouponServiceInterface.php index 4482b4e..3391538 100644 --- a/app/Service/v3/Interfaces/CouponServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponServiceInterface.php @@ -22,13 +22,6 @@ interface CouponServiceInterface */ public function undo(); - /** - * 统计用户可使用优惠券数量 - * @param $userId - * @return mixed - */ - public function countAvailableByUser($userId); - public function cacheTodayCouponUsed($userId, $couponId, $couponRecId); public function allTodayCouponUsed($userId); diff --git a/app/Service/v3/Interfaces/LocationServiceInterface.php b/app/Service/v3/Interfaces/LocationServiceInterface.php index 68e659e..6acab97 100644 --- a/app/Service/v3/Interfaces/LocationServiceInterface.php +++ b/app/Service/v3/Interfaces/LocationServiceInterface.php @@ -9,8 +9,8 @@ interface LocationServiceInterface public function do(); public function check(); public function undo(); - public function getMarketListByLocation($cityIds); - public function searchMarket($key,$cityId = 2163); + public function getMarketListByLocation($lng,$lat); + public function searchMarket($key,$lng,$lat,$cityId = 2163); public function getMarketsInfo(); public function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2); public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2); diff --git a/config/config.php b/config/config.php index ad49d28..68575fa 100644 --- a/config/config.php +++ b/config/config.php @@ -52,4 +52,7 @@ return [ 'alioss' => [ 'img_host' => env('OSS_IMG_HOST', ''), ], + 'lgoin' => [ + 'authkey' => env('LOGIN_AUTHKEY', ''), + ], ];