Browse Source

收藏店铺 定位 优惠券数量 数据实装 店铺登录

master
Lemon 5 years ago
parent
commit
0e1c088ac0
  1. 6
      app/Controller/v3/CollectStoreController.php
  2. 8
      app/Controller/v3/HomeController.php
  3. 6
      app/Controller/v3/LocationController.php
  4. 4
      app/Controller/v3/SearchController.php
  5. 10
      app/Model/v3/StoreUsers.php
  6. 7
      app/Model/v3/UserCollection.php
  7. 37
      app/Request/v3/UserAndStoreRequest.php
  8. 36
      app/Request/v3/UserRequest.php
  9. 22
      app/Service/v3/Implementations/CollectStoreService.php
  10. 9
      app/Service/v3/Implementations/CouponRecService.php
  11. 8
      app/Service/v3/Implementations/CouponService.php
  12. 17
      app/Service/v3/Implementations/LocationService.php
  13. 15
      app/Service/v3/Implementations/StoreLoginService.php
  14. 6
      app/Service/v3/Interfaces/CouponRecServiceInterface.php
  15. 7
      app/Service/v3/Interfaces/CouponServiceInterface.php
  16. 4
      app/Service/v3/Interfaces/LocationServiceInterface.php
  17. 3
      config/config.php

6
app/Controller/v3/CollectStoreController.php

@ -3,6 +3,8 @@
namespace App\Controller\v3; namespace App\Controller\v3;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Request\v3\UserAndStoreRequest;
use App\Request\v3\UserRequest;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\CollectStoreServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface;
@ -15,7 +17,7 @@ class CollectStoreController extends BaseController
*/ */
protected $collectStoreService; protected $collectStoreService;
public function update()
public function update(UserAndStoreRequest $request)
{ {
$params = $this->request->all(); $params = $this->request->all();
//判断是否已收藏店铺 //判断是否已收藏店铺
@ -30,7 +32,7 @@ class CollectStoreController extends BaseController
return $this->success(['is_collect' => $res]); return $this->success(['is_collect' => $res]);
} }
public function getListByUser()
public function getListByUser(UserRequest $request)
{ {
$params = $this->request->all(); $params = $this->request->all();
$res = $this->collectStoreService->getListByUser($params['user_id']); $res = $this->collectStoreService->getListByUser($params['user_id']);

8
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\BannerServiceInterface;
use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface;
use App\Service\v3\Interfaces\CollectStoreServiceInterface; 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\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use App\Service\v3\Interfaces\RevenueListServiceInterface; use App\Service\v3\Interfaces\RevenueListServiceInterface;
@ -51,9 +51,9 @@ class HomeController extends BaseController
/** /**
* @Inject * @Inject
* @var CouponServiceInterface
* @var CouponRecServiceInterface
*/ */
protected $couponService;
protected $couponRecService;
/** /**
* @Inject * @Inject
@ -168,7 +168,7 @@ class HomeController extends BaseController
} }
$data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']); $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; $data['user']['role'] = $roles;
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);

6
app/Controller/v3/LocationController.php

@ -6,7 +6,6 @@ use App\Controller\BaseController;
use App\Model\v3\Market; use App\Model\v3\Market;
use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\LocationServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
/** /**
* 定位相关 * 定位相关
* Class LocationController * Class LocationController
@ -33,8 +32,9 @@ class LocationController extends BaseController
public function getMarketListByLocation() 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() public function getMarketsInfo()

4
app/Controller/v3/SearchController.php

@ -78,7 +78,9 @@ class SearchController extends BaseController
{ {
$keywords = $this->request->input('keywords',''); $keywords = $this->request->input('keywords','');
$cityId = $this->request->input('city_id',2163); $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]); return $this->success(['markets' => $data]);
} }
} }

10
app/Model/v3/StoreUsers.php

@ -0,0 +1,10 @@
<?php
namespace App\Model\v3;
use App\Model\Model;
class StoreUsers extends Model
{
protected $table = 'lanzu_store_users';
}

7
app/Model/v3/UserCollection.php

@ -11,4 +11,11 @@ class UserCollection extends Model
use SoftDeletes; use SoftDeletes;
protected $table = 'lanzu_user_collection'; protected $table = 'lanzu_user_collection';
protected $fillable = [
'id',
'user_id',
'market_id',
'store_id',
'deleted_at'
];
} }

37
app/Request/v3/UserAndStoreRequest.php

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class UserAndStoreRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'user_id' => 'required|nonempty|integer',
'store_id' => 'required|nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

36
app/Request/v3/UserRequest.php

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class UserRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'user_id' => 'required|nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

22
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); $userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,1);
//店铺被收藏数自增 //店铺被收藏数自增
$storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$storeId,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; return $userSet && $userIncr && $storeIncr;
} }
@ -39,6 +53,14 @@ class CollectStoreService implements CollectStoreServiceInterface
$userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,'-1'); $userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,'-1');
//店铺被收藏数自减 //店铺被收藏数自减
$storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$storeId,'-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; return $userDel && $userIncr && $storeIncr;
} }
//获取用户收藏店铺数量 //获取用户收藏店铺数量

9
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);
}
} }

8
app/Service/v3/Implementations/CouponService.php

@ -40,14 +40,6 @@ class CouponService implements CouponServiceInterface
// TODO: Implement undo() method. // TODO: Implement undo() method.
} }
/**
* @inheritDoc
*/
public function countAvailableByUser($userId)
{
return mt_rand(0,10);
}
/** /**
* 缓存优惠券今日使用情况 * 缓存优惠券今日使用情况
* @param $userId * @param $userId

17
app/Service/v3/Implementations/LocationService.php

@ -25,19 +25,24 @@ class LocationService implements LocationServiceInterface
// TODO: Implement undo() method. // 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(); $res = Area::query()->with('markets')->whereIn('id',$cityIds)->get();
foreach ($res as &$v){ foreach ($res as &$v){
foreach ($v->markets as &$m) 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; return $res;
} }
public function searchMarket($keywords,$cityId = 2163)
public function searchMarket($keywords,$lng,$lat,$cityId = 2163)
{ {
$res = Market::query()->where([ $res = Market::query()->where([
['name','like','%'.$keywords.'%'], ['name','like','%'.$keywords.'%'],
@ -45,7 +50,11 @@ class LocationService implements LocationServiceInterface
]) ])
->get(); ->get();
foreach ($res as &$v){ 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; return $res;
} }

15
app/Service/v3/Implementations/StoreLoginService.php

@ -4,14 +4,18 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use App\Model\v3\StoreUsers;
use App\Service\v3\Interfaces\StoreLoginServiceInterface; use App\Service\v3\Interfaces\StoreLoginServiceInterface;
class StoreLoginService implements StoreLoginServiceInterface class StoreLoginService implements StoreLoginServiceInterface
{ {
public function do($account,$password) 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{ }else{
throw new ErrorCodeException(ErrorCode::STORE_LOGIN_ERROR); throw new ErrorCodeException(ErrorCode::STORE_LOGIN_ERROR);
} }
@ -26,4 +30,11 @@ class StoreLoginService implements StoreLoginServiceInterface
{ {
// TODO: Implement undo() method. // TODO: Implement undo() method.
} }
function stringHash($password,$salt)
{
$authkey = config('lgoin.authkey');
$password = "{$password}-{$salt}-{$authkey}";
return sha1($password);
}
} }

6
app/Service/v3/Interfaces/CouponRecServiceInterface.php

@ -10,4 +10,10 @@ interface CouponRecServiceInterface
public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId);
public function getListByUser($userId,$type,$page = 1,$pagesize = 5); public function getListByUser($userId,$type,$page = 1,$pagesize = 5);
public function allForOnlineOrderAvailable($userId, $marketId); public function allForOnlineOrderAvailable($userId, $marketId);
/**
* 统计用户可使用优惠券数量
* @param $userId
* @return mixed
*/
public function countAvailableByUser($userId);
} }

7
app/Service/v3/Interfaces/CouponServiceInterface.php

@ -22,13 +22,6 @@ interface CouponServiceInterface
*/ */
public function undo(); public function undo();
/**
* 统计用户可使用优惠券数量
* @param $userId
* @return mixed
*/
public function countAvailableByUser($userId);
public function cacheTodayCouponUsed($userId, $couponId, $couponRecId); public function cacheTodayCouponUsed($userId, $couponId, $couponRecId);
public function allTodayCouponUsed($userId); public function allTodayCouponUsed($userId);

4
app/Service/v3/Interfaces/LocationServiceInterface.php

@ -9,8 +9,8 @@ interface LocationServiceInterface
public function do(); public function do();
public function check(); public function check();
public function undo(); 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 getMarketsInfo();
public function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2); public function getDistance($lng1, $lat1, $lng2, $lat2, $unit = 2, $decimal = 2);
public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2); public function getDistanceByTencent($lng1, $lat1, $lng2, $lat2);

3
config/config.php

@ -52,4 +52,7 @@ return [
'alioss' => [ 'alioss' => [
'img_host' => env('OSS_IMG_HOST', ''), 'img_host' => env('OSS_IMG_HOST', ''),
], ],
'lgoin' => [
'authkey' => env('LOGIN_AUTHKEY', ''),
],
]; ];
Loading…
Cancel
Save