Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

# Conflicts:
#	app/Constants/v3/SsdbKeys.php
#	app/Service/v3/Implementations/CollectStoreService.php
#	app/Service/v3/Implementations/ShopCartService.php
#	app/Service/v3/Interfaces/CollectStoreServiceInterface.php
#	app/Service/v3/Interfaces/ShopCartServiceInterface.php
#	config/autoload/dependencies.php
master
Lemon 5 years ago
parent
commit
2b601039f0
  1. 25
      app/Constants/v3/Goods.php
  2. 20
      app/Constants/v3/LogLabel.php
  3. 11
      app/Constants/v3/SsdbKeys.php
  4. 44
      app/Constants/v3/Store.php
  5. 15
      app/Constants/v3/Tabs.php
  6. 106
      app/Controller/v3/GoodsRecommendController.php
  7. 57
      app/Controller/v3/HomeController.php
  8. 15
      app/Controller/v3/SearchController.php
  9. 51
      app/Controller/v3/StoreController.php
  10. 16
      app/Exception/Handler/ErrorCodeExceptionHandler.php
  11. 12
      app/Model/v3/Goods.php
  12. 35
      app/Model/v3/Store.php
  13. 3
      app/Model/v3/User.php
  14. 1
      app/Request/v3/SearchGoodsRequest.php
  15. 42
      app/Request/v3/SearchStoreRequest.php
  16. 38
      app/Request/v3/StoreIndexRequest.php
  17. 36
      app/Request/v3/UserIndexRequest.php
  18. 16
      app/Service/v3/Implementations/CategoryService.php
  19. 20
      app/Service/v3/Implementations/CollectStoreService.php
  20. 41
      app/Service/v3/Implementations/CouponService.php
  21. 38
      app/Service/v3/Implementations/SearchService.php
  22. 2
      app/Service/v3/Implementations/ShopCartService.php
  23. 37
      app/Service/v3/Implementations/StoreService.php
  24. 10
      app/Service/v3/Implementations/UserInfoService.php
  25. 1
      app/Service/v3/Interfaces/CategoryServiceInterface.php
  26. 31
      app/Service/v3/Interfaces/CouponServiceInterface.php
  27. 2
      app/Service/v3/Interfaces/SearchServiceInterface.php
  28. 2
      app/Service/v3/Interfaces/ShopCartServiceInterface.php
  29. 11
      app/Service/v3/Interfaces/StoreServiceInterface.php
  30. 1
      app/Service/v3/Interfaces/UserInfoServiceInterface.php
  31. 2
      config/autoload/dependencies.php
  32. 3
      config/routes.php

25
app/Constants/v3/Goods.php

@ -0,0 +1,25 @@
<?php
namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
*/
class Goods extends AbstractConstants
{
/**
* @Message("售卖中")
*/
const ON_SALE_YES = 1;
/**
* @Message("已下架")
*/
const ON_SALE_NO = 2;
}

20
app/Constants/v3/LogLabel.php

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
*/
class LogLabel extends AbstractConstants
{
/**
* @Message("Error Code Log")
*/
const ERROR_CODE_EXCEPTION = 'error_code_exception';
}

11
app/Constants/v3/SsdbKeys.php

@ -19,7 +19,12 @@ class SsdbKeys extends AbstractConstants
* @Message("商品月销") * @Message("商品月销")
*/ */
const GOODS_MONTH_SALES = 'goods_m_sales_'; const GOODS_MONTH_SALES = 'goods_m_sales_';
/**
* @Message("用户新订单统计")
*/
const USER_ORDER_BADGE = 'user_order_badge_';
/** /**
* @Message("收藏店铺") * @Message("收藏店铺")
*/ */
@ -28,10 +33,10 @@ class SsdbKeys extends AbstractConstants
/** /**
* @Message("用户收藏店铺数量") * @Message("用户收藏店铺数量")
*/ */
const COLLECT_STORE_NUM_USER = 'collect_store_num_user_';
const COUNT_COLLECT_STORE_USER = 'count_collect_store_user_';
/** /**
* @Message("店铺被收藏数量") * @Message("店铺被收藏数量")
*/ */
const COLLECT_NUM_STORE = 'collect_num_store_';
const COUNT_COLLECT_STORE = 'count_collect_store_';
} }

44
app/Constants/v3/Store.php

@ -0,0 +1,44 @@
<?php
namespace App\Constants\v3;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
*/
class Store extends AbstractConstants
{
/**
* @Message("营业中")
*/
const IS_OPEN_YES = 1;
/**
* @Message("歇业中")
*/
const IS_OPEN_NO = 2;
/**
* @Message("入驻审核中")
*/
const STATUS_EXAMINING = 1;
/**
* @Message("入驻成功")
*/
const STATUS_PASS = 2;
/**
* @Message("入驻被拒")
*/
const STATUS_REFUSE = 3;
/**
* @Message("入驻已过期")
*/
const STATUS_EXPIRED = 4;
}

15
app/Constants/v3/Tabs.php

@ -29,4 +29,19 @@ class Tabs extends AbstractConstants
* @Message("小程序首页上班带餐") * @Message("小程序首页上班带餐")
*/ */
const APPLET_INDEX_OFFICE = 'applet_index_office'; const APPLET_INDEX_OFFICE = 'applet_index_office';
/**
* @Message("搜索商品为你推荐")
*/
const RECOMMEND_FOR_SEARCH_GOODS = 'recommend_search_goods';
/**
* @Message("搜索商户为你推荐")
*/
const RECOMMEND_FOR_SEARCH_STORE = 'recommend_search_store';
/**
* @Message("个人中心为你推荐")
*/
const RECOMMEND_FOR_USER_INDEX = 'recommend_user_index';
} }

106
app/Controller/v3/GoodsRecommendController.php

@ -13,6 +13,95 @@ use App\Controller\BaseController;
class GoodsRecommendController extends BaseController class GoodsRecommendController extends BaseController
{ {
protected $data;
public function __construct()
{
$this->data = [
[
'goods' => [
'id' => 1,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 111, 'logo' => '', 'name' => '我是一个商家']
],
[
'goods' => [
'id' => 2,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 222, 'logo' => '', 'name' => '我是一个商家222']
],
[
'goods' => [
'id' => 3,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 333, 'logo' => '', 'name' => '我是一个商家333']
],
[
'goods' => [
'id' => 4,
'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
'name' => '【优质】大白菜11',
'spec' => [
['key' => '净含量', 'value' => '500g']
],
'tags' => ['限时', '折扣'],
'original_price' => 50.5,
'price' => 25.25,
'inventory' => 10,
'month_sales' => 20,
'total_sales' => 20,
'cart_num' => 0,
'is_effective' => 2,
'noneffective_note' => '已卖完',
],
'store' => ['id' => 444, 'logo' => '', 'name' => '我是一个商家444']
]
];
parent::__construct();
}
/** /**
* 获取首页tabs推荐商品列表 * 获取首页tabs推荐商品列表
* 1、前端上传tab标识 * 1、前端上传tab标识
@ -119,4 +208,21 @@ class GoodsRecommendController extends BaseController
'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')] 'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')]
]); ]);
} }
/**
* 获取搜索页推荐商品列表
* 1、前端上传标识
* recommend_search_goods
* recommend_search_stores
* recommend_user_index
* 2、根据标识从Elasticsearch中获取商品IDs
* 3、根据IDs获取商品数据
* 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
*/
public function getByTab()
{
return $this->success(['tab_data' => $this->data]);
}
} }

57
app/Controller/v3/HomeController.php

@ -3,8 +3,16 @@
namespace App\Controller\v3; namespace App\Controller\v3;
use App\Constants\v3\ActivityType; use App\Constants\v3\ActivityType;
use App\Constants\v3\SsdbKeys;
use App\Constants\v3\Tabs; use App\Constants\v3\Tabs;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Request\v3\UserIndexRequest;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use App\TaskWorker\SSDBTask;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
/** /**
* 首页相关 * 首页相关
@ -13,6 +21,25 @@ use App\Controller\BaseController;
*/ */
class HomeController extends BaseController class HomeController extends BaseController
{ {
/**
* @Inject
* @var UserInfoServiceInterface
*/
protected $userInfoService;
/**
* @Inject
* @var CollectStoreServiceInterface
*/
protected $collectStoreService;
/**
* @Inject
* @var CouponServiceInterface
*/
protected $couponService;
/** /**
* 小程序首页,根据market_id * 小程序首页,根据market_id
* 1.banner数据 * 1.banner数据
@ -154,4 +181,34 @@ class HomeController extends BaseController
]); ]);
} }
/**
* 用户首页,我的页面
* 1、用户信息,id、昵称、名字、头像
* 2、收藏、红包、积分
* 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
* 4、为你推荐的商品列表
* @param UserIndexRequest $request
*/
public function userIndex(UserIndexRequest $request)
{
$params = $request->validated();
$data['user'] = $this->userInfoService->detail($params['user_id']);
$data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
$data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$data['badge'] = [
'unpaid' => 0,
'receiving' => 0,
'completed' => 0,
'refund' => 0,
];
$badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
if (!empty($badge)) {
$data['badge'] = array_merge($data['badge'], $badge);
}
return $this->success($data);
}
} }

15
app/Controller/v3/SearchController.php

@ -4,6 +4,7 @@ namespace App\Controller\v3;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Request\v3\SearchGoodsRequest; use App\Request\v3\SearchGoodsRequest;
use App\Request\v3\SearchStoreRequest;
use App\Service\v3\Interfaces\SearchServiceInterface; use App\Service\v3\Interfaces\SearchServiceInterface;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -40,15 +41,25 @@ class SearchController extends BaseController
*/ */
public function goods(SearchGoodsRequest $request) public function goods(SearchGoodsRequest $request)
{ {
$params = $request->validated(); $params = $request->validated();
$data = $this->searchService->doForGoods($params); $data = $this->searchService->doForGoods($params);
return $this->success(['goods' => $data]); return $this->success(['goods' => $data]);
} }
public function stores()
/**
* 商户搜索
* 1、筛选条件:商户分类、商户关键词
* 2、排序:综合排序、销量最多
* 3、返回数据格式,大购物车统计+商品数据含有id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
* @param SearchStoreRequest $request
* @return ResponseInterface
*/
public function stores(SearchStoreRequest $request)
{ {
$params = $request->validated();
$data = $this->searchService->doForStores($params);
return $this->success(['stores' => $data]);
} }
} }

51
app/Controller/v3/StoreController.php

@ -0,0 +1,51 @@
<?php
namespace App\Controller\v3;
use App\Controller\BaseController;
use App\Request\v3\StoreIndexRequest;
use App\Service\v3\Interfaces\CategoryServiceInterface;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\StoreServiceInterface;
use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
class StoreController extends BaseController
{
/**
* @Inject
* @var StoreServiceInterface
*/
protected $storeService;
/**
* @Inject
* @var CategoryServiceInterface
*/
protected $categoryService;
/**
* @Inject
* @var CollectStoreServiceInterface
*/
protected $collectService;
/**
* 商户详情页
* 1、商户id用来查询的,还要有user_id
* 2、返回数据,id、logo、name、收藏状态、简介、地址、营业状态、营业时间、联系电话
* 3、返回数据,商品推荐的分类,需要经过商户商品反查
* 4、分类下的商品,则复用商品搜索接口
* @param StoreIndexRequest $request
* @return ResponseInterface
*/
public function index(StoreIndexRequest $request)
{
$params = $request->validated();
$data = $this->storeService->detail($params['store_id'], $params['market_id']);
$data['is_collected'] = (bool)$this->collectService->check($params['market_id'], $params['store_id'], $params['user_id']);
$data['goods_types'] = $this->categoryService->allForStore($params['store_id']);
return $this->success(['store' => $data]);
}
}

16
app/Exception/Handler/ErrorCodeExceptionHandler.php

@ -2,15 +2,23 @@
namespace App\Exception\Handler; namespace App\Exception\Handler;
use App\Commons\Log;
use App\Constants\v3\LogLabel;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\HttpMessage\Stream\SwooleStream;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Throwable; use Throwable;
use Hyperf\Di\Annotation\Inject;
class ErrorCodeExceptionHandler extends ExceptionHandler class ErrorCodeExceptionHandler extends ExceptionHandler
{ {
/**
* @Inject
* @var Log
*/
protected $log;
/** /**
* @var StdoutLoggerInterface * @var StdoutLoggerInterface
@ -29,16 +37,18 @@ class ErrorCodeExceptionHandler extends ExceptionHandler
$this->stopPropagation(); $this->stopPropagation();
$content = json_encode([
$content = [
"status" => 'error', "status" => 'error',
"code" => $throwable->getCode(), "code" => $throwable->getCode(),
"result" => [], "result" => [],
"message" => $throwable->getMessage() "message" => $throwable->getMessage()
]);
];
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION, $content);
return $response->withHeader('Content-Type', 'application/json') return $response->withHeader('Content-Type', 'application/json')
->withStatus(200) ->withStatus(200)
->withBody(new SwooleStream($content));
->withBody(new SwooleStream(json_encode($content)));
} }
public function isValid(Throwable $throwable): bool public function isValid(Throwable $throwable): bool

12
app/Model/v3/Goods.php

@ -7,9 +7,11 @@ use App\Constants\v3\SsdbKeys;
use App\Model\Model; use App\Model\Model;
use App\Service\v3\Interfaces\ShopCartServiceInterface; use App\Service\v3\Interfaces\ShopCartServiceInterface;
use App\TaskWorker\SSDBTask; use App\TaskWorker\SSDBTask;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes; use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Utils\ApplicationContext; use Hyperf\Utils\ApplicationContext;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use App\Constants\v3\Goods as GoodsConstants;
/** /**
*/ */
@ -51,9 +53,17 @@ class Goods extends Model
'cart_num', 'cart_num',
]; ];
protected function boot(): void
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
$builder->where(['on_sale' => GoodsConstants::ON_SALE_YES]);
});
}
public function scopeOrderByDefault($query, $sort) public function scopeOrderByDefault($query, $sort)
{ {
return $query->orderBy('id', $sort);
return $query->orderBy('sort', $sort)->orderBy('id', $sort);
} }
public function scopeOrderBySales($query, $sort) public function scopeOrderBySales($query, $sort)

35
app/Model/v3/Store.php

@ -3,8 +3,13 @@
declare (strict_types=1); declare (strict_types=1);
namespace App\Model\v3; namespace App\Model\v3;
use App\Constants\v3\SsdbKeys;
use App\Model\Model; use App\Model\Model;
use App\TaskWorker\SSDBTask;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes; use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Utils\ApplicationContext;
use App\Constants\v3\Store as StoreConstants;
/** /**
*/ */
@ -31,7 +36,35 @@ class Store extends Model
*/ */
protected $casts = []; protected $casts = [];
protected $appends = [];
protected $appends = [
'month_sales'
];
protected function boot(): void
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
$builder->where(['is_open' => StoreConstants::IS_OPEN_YES, 'status' => StoreConstants::STATUS_PASS]);
});
}
public function scopeOrderByDefault($query, $sort)
{
return $query->orderBy('sort', $sort)->orderBy('id', $sort);
}
public function scopeOrderBySales($query, $sort)
{
return $query->orderBy('sales', $sort);
}
public function getMonthSalesAttribute() {
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
return (integer)$ssdb->exec('get', SsdbKeys::STORE_MONTH_SALES.date('YM').'_'.$this->id);
}
public function goods()
{
return $this->hasMany(Goods::class, 'store_id', 'id');
}
} }

3
app/Model/v3/User.php

@ -3,9 +3,12 @@
namespace App\Model\v3; namespace App\Model\v3;
use App\Model\Model; use App\Model\Model;
use Hyperf\Database\Model\SoftDeletes;
class User extends Model class User extends Model
{ {
use SoftDeletes;
protected $table = 'lanzu_user'; protected $table = 'lanzu_user';
protected $fillable = [ protected $fillable = [

1
app/Request/v3/SearchGoodsRequest.php

@ -17,6 +17,7 @@ class SearchGoodsRequest extends BaseFormRequest
return [ return [
'market_id' => 'required|nonempty|integer', 'market_id' => 'required|nonempty|integer',
'type_id' => 'nonempty|integer', 'type_id' => 'nonempty|integer',
'store_id' => 'nonempty|integer',
'keyword' => 'nonempty', 'keyword' => 'nonempty',
'order_by' => 'nonempty|in:default,sales,price', 'order_by' => 'nonempty|in:default,sales,price',
'sort' => 'nonempty|in:asc,desc', 'sort' => 'nonempty|in:asc,desc',

42
app/Request/v3/SearchStoreRequest.php

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class SearchStoreRequest extends BaseFormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'market_id' => 'required|nonempty|integer',
'type_id' => 'nonempty|integer',
'keyword' => 'nonempty',
'order_by' => 'nonempty|in:default,sales',
'sort' => 'nonempty|in:asc,desc',
'page' => 'nonempty|integer',
'pagesize' => 'nonempty|integer',
];
}
/**
* @return array
*/
public function messages(): array
{
return [
'*.*' => ':attribute无效',
];
}
public function attributes(): array
{
return parent::attributes();
}
}

38
app/Request/v3/StoreIndexRequest.php

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

36
app/Request/v3/UserIndexRequest.php

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Request\v3;
use App\Request\BaseFormRequest;
class UserIndexRequest 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();
}
}

16
app/Service/v3/Implementations/CategoryService.php

@ -2,6 +2,8 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Model\v3\Goods;
use App\Model\v3\GoodsType;
use App\Model\v3\StoreType; use App\Model\v3\StoreType;
use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface;
@ -32,4 +34,18 @@ class CategoryService implements CategoryServiceInterface
->get() ->get()
->toArray(); ->toArray();
} }
public function allForStore($storeId)
{
$goodsTypeIds = Goods::query()->select('goods_type_id')
->where(['store_id' => $storeId])
->groupBy(['goods_type_id'])
->get()->toArray();
return GoodsType::query()
->whereIn('id', array_column($goodsTypeIds, 'goods_type_id'))
->orderBy('sort', 'DESC')
->orderBy('id', 'DESC')
->get()->toArray();
}
} }

20
app/Service/v3/Implementations/CollectStoreService.php

@ -14,9 +14,9 @@ class CollectStoreService implements CollectStoreServiceInterface
//收藏店铺 //收藏店铺
$userSet = $ssdb->exec('set', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time()); $userSet = $ssdb->exec('set', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time());
//用户收藏数量自增 //用户收藏数量自增
$userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,1);
$userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,1);
//店铺被收藏数自增 //店铺被收藏数自增
$storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$storeId,1);
$storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$storeId,1);
return $userSet && $userIncr && $storeIncr; return $userSet && $userIncr && $storeIncr;
} }
@ -32,23 +32,23 @@ class CollectStoreService implements CollectStoreServiceInterface
//取消收藏店铺 //取消收藏店铺
$userDel = $ssdb->exec('del', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time()); $userDel = $ssdb->exec('del', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time());
//用户收藏数量自减 //用户收藏数量自减
$userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,'-1');
$userIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE_USER.$userId,'-1');
//店铺被收藏数自减 //店铺被收藏数自减
$storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$userId,'-1');
$storeIncr = $ssdb->exec('incr', SsdbKeys::COUNT_COLLECT_STORE.$userId,'-1');
return $userDel && $userIncr && $storeIncr; return $userDel && $userIncr && $storeIncr;
} }
//获取用户收藏店铺数量
public function countByUser($userId) public function countByUser($userId)
{ {
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$num = $ssdb->exec('get',SsdbKeys::COLLECT_STORE_NUM_USER.$userId);
return $num;
$count = $ssdb->exec('get',SsdbKeys::COUNT_COLLECT_STORE_USER.$userId);
return $count;
} }
//获取店铺被收藏数量
public function countByStore($storeId) public function countByStore($storeId)
{ {
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$num = $ssdb->exec('get',SsdbKeys::COLLECT_NUM_STORE.$storeId);
return $num;
$count = $ssdb->exec('get',SsdbKeys::COUNT_COLLECT_STORE.$storeId);
return $count;
} }
} }

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

@ -0,0 +1,41 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\CouponServiceInterface;
class CouponService implements CouponServiceInterface
{
/**
* @inheritDoc
*/
public function do()
{
// TODO: Implement do() method.
}
/**
* @inheritDoc
*/
public function check()
{
// TODO: Implement check() method.
}
/**
* @inheritDoc
*/
public function undo()
{
// TODO: Implement undo() method.
}
/**
* @inheritDoc
*/
public function countAvailableByUser($userId)
{
return mt_rand(0,10);
}
}

38
app/Service/v3/Implementations/SearchService.php

@ -5,6 +5,7 @@ namespace App\Service\v3\Implementations;
use App\Model\v3\Goods; use App\Model\v3\Goods;
use App\Model\v3\Store;
class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
{ {
@ -58,9 +59,42 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
return $data; return $data;
} }
public function doForStores()
public function doForStores($params)
{ {
// TODO: Implement doForStores() method.
$builder = Store::query()
->with(['goods' => function($query) {
return $query->limit(5)
->select(['id', 'store_id', 'cover_img', 'name', 'spec', 'tags', 'original_price', 'price', 'inventory', 'sales as total_sales']);
}])
->where(['market_id' => $params['market_id']]);
if (isset($params['store_id']) && $params['store_id']) {
$builder->where(['store_id' => $params['store_id']]);
}
if (isset($params['type_id']) && $params['type_id']) {
$builder->where(['store_type_id' => $params['type_id']]);
}
if (isset($params['keyword']) && $params['keyword']) {
$builder->where('name', 'like', '%'.$params['keyword'].'%');
}
if (isset($params['order_by']) && $params['order_by']) {
$sort = $params['sort'] ?? 'desc';
switch ($params['order_by']) {
case 'sales':
$builder->orderBySales($sort);
break;
default:
$builder->orderByDefault($sort);
break;
}
}
$builder->select(['id', 'logo', 'name']);
$stores = $builder->forPage($params['page'], $params['pagesize'])->get()->toArray();
return $stores;
} }
public function getHotKeywords($type) public function getHotKeywords($type)

2
app/Service/v3/Implementations/ShopCartService.php

@ -55,7 +55,7 @@ class ShopCartService implements ShopCartServiceInterface
return $res; return $res;
} }
public function check()
public function check($goodsId)
{ {
return mt_rand(0,6); return mt_rand(0,6);
} }

37
app/Service/v3/Implementations/StoreService.php

@ -0,0 +1,37 @@
<?php
namespace App\Service\v3\Implementations;
use App\Model\v3\Store;
use App\Service\v3\Interfaces\StoreServiceInterface;
class StoreService implements StoreServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function detail($storeId, $marketId)
{
return Store::query()
->select([
'id', 'name', 'logo', 'introduction', 'announcement', 'address', 'tel', 'stall_info',
'is_rest','time1', 'time2', 'time3', 'time4',
])
->where(['id' => $storeId, 'market_id' => $marketId])
->first()->toArray();
}
}

10
app/Service/v3/Implementations/UserInfoService.php

@ -30,11 +30,19 @@ class UserInfoService implements UserInfoServiceInterface
public function check($userId) public function check($userId)
{ {
// TODO: Implement check() method.
return User::query()->where(['status' => 1, 'id' => $userId])->exists();
} }
public function undo($userId) public function undo($userId)
{ {
// TODO: Implement undo() method. // TODO: Implement undo() method.
} }
public function detail($userId)
{
return User::query()
->select(['id', 'nick_name', 'avatar', 'openid', 'total_score', 'real_name'])
->where(['status' => 1, 'id' => $userId])
->first()->toArray();
}
} }

1
app/Service/v3/Interfaces/CategoryServiceInterface.php

@ -9,5 +9,6 @@ interface CategoryServiceInterface
public function check(); public function check();
public function undo(); public function undo();
public function all(); public function all();
public function allForStore($storeId);
} }

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

@ -0,0 +1,31 @@
<?php
namespace App\Service\v3\Interfaces;
interface CouponServiceInterface
{
/**
* 领取
* @return mixed
*/
public function do();
/**
* 是否已经领取
* @return mixed
*/
public function check();
/**
* 退还优惠券
* @return mixed
*/
public function undo();
/**
* 统计用户可使用优惠券数量
* @param $userId
* @return mixed
*/
public function countAvailableByUser($userId);
}

2
app/Service/v3/Interfaces/SearchServiceInterface.php

@ -5,7 +5,7 @@ namespace App\Service\v3\Interfaces;
interface SearchServiceInterface interface SearchServiceInterface
{ {
public function doForGoods($params); public function doForGoods($params);
public function doForStores();
public function doForStores($params);
public function getHotKeywords($type); public function getHotKeywords($type);
public function do(); public function do();
public function check(); public function check();

2
app/Service/v3/Interfaces/ShopCartServiceInterface.php

@ -6,7 +6,7 @@ interface ShopCartServiceInterface
{ {
public function do(); public function do();
public function check();
public function check($goodsId);
public function undo(); public function undo();

11
app/Service/v3/Interfaces/StoreServiceInterface.php

@ -0,0 +1,11 @@
<?php
namespace App\Service\v3\Interfaces;
interface StoreServiceInterface
{
public function do();
public function check();
public function undo();
public function detail($storeId, $marketId);
}

1
app/Service/v3/Interfaces/UserInfoServiceInterface.php

@ -7,4 +7,5 @@ interface UserInfoServiceInterface
public function do($userId, $data); public function do($userId, $data);
public function check($userId); public function check($userId);
public function undo($userId); public function undo($userId);
public function detail($userId);
} }

2
config/autoload/dependencies.php

@ -49,5 +49,7 @@ return [
\App\Service\v3\Interfaces\WxLoginServiceInterface::class => \App\Service\v3\Implementations\WxLoginService::class, \App\Service\v3\Interfaces\WxLoginServiceInterface::class => \App\Service\v3\Implementations\WxLoginService::class,
\App\Service\v3\Interfaces\UserInfoServiceInterface::class => \App\Service\v3\Implementations\UserInfoService::class, \App\Service\v3\Interfaces\UserInfoServiceInterface::class => \App\Service\v3\Implementations\UserInfoService::class,
\App\Service\v3\Interfaces\SearchServiceInterface::class => \App\Service\v3\Implementations\SearchService::class, \App\Service\v3\Interfaces\SearchServiceInterface::class => \App\Service\v3\Implementations\SearchService::class,
\App\Service\v3\Interfaces\StoreServiceInterface::class => \App\Service\v3\Implementations\StoreService::class,
\App\Service\v3\Interfaces\CollectStoreServiceInterface::class => \App\Service\v3\Implementations\CollectStoreService::class, \App\Service\v3\Interfaces\CollectStoreServiceInterface::class => \App\Service\v3\Implementations\CollectStoreService::class,
\App\Service\v3\Interfaces\CouponServiceInterface::class => \App\Service\v3\Implementations\CouponService::class,
]; ];

3
config/routes.php

@ -88,6 +88,9 @@ Router::addGroup('/v3/', function () {
Router::post('search/hotKeywords', 'App\Controller\v3\SearchController@hotKeywords'); Router::post('search/hotKeywords', 'App\Controller\v3\SearchController@hotKeywords');
Router::post('search/goods', 'App\Controller\v3\SearchController@goods'); Router::post('search/goods', 'App\Controller\v3\SearchController@goods');
Router::post('search/stores', 'App\Controller\v3\SearchController@stores'); Router::post('search/stores', 'App\Controller\v3\SearchController@stores');
Router::post('goodsRecommend/getByTab', 'App\Controller\v3\GoodsRecommendController@getByTab');
Router::post('store/index', 'App\Controller\v3\StoreController@index');
Router::post('home/userIndex', 'App\Controller\v3\HomeController@userIndex');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由 // 需要登录的路由

Loading…
Cancel
Save