Browse Source

商品推荐、我的页面

master
weigang 5 years ago
parent
commit
369f070956
  1. 6
      app/Constants/v3/SsdbKeys.php
  2. 5
      app/Constants/v3/Tabs.php
  3. 8
      app/Controller/v3/GoodsRecommendController.php
  4. 57
      app/Controller/v3/HomeController.php
  5. 3
      app/Model/v3/User.php
  6. 36
      app/Request/v3/UserIndexRequest.php
  7. 12
      app/Service/v3/Implementations/CollectStoreService.php
  8. 41
      app/Service/v3/Implementations/CouponService.php
  9. 10
      app/Service/v3/Implementations/UserInfoService.php
  10. 2
      app/Service/v3/Interfaces/CollectStoreServiceInterface.php
  11. 31
      app/Service/v3/Interfaces/CouponServiceInterface.php
  12. 1
      app/Service/v3/Interfaces/UserInfoServiceInterface.php
  13. 1
      config/autoload/dependencies.php
  14. 3
      config/routes.php

6
app/Constants/v3/SsdbKeys.php

@ -24,4 +24,10 @@ class SsdbKeys extends AbstractConstants
* @Message("商户月销")
*/
const STORE_MONTH_SALES = 'store_m_sales_';
/**
* @Message("用户新订单统计")
*/
const USER_ORDER_BADGE = 'user_order_badge_';
}

5
app/Constants/v3/Tabs.php

@ -39,4 +39,9 @@ class Tabs extends AbstractConstants
* @Message("搜索商户为你推荐")
*/
const RECOMMEND_FOR_SEARCH_STORE = 'recommend_search_store';
/**
* @Message("个人中心为你推荐")
*/
const RECOMMEND_FOR_USER_INDEX = 'recommend_user_index';
}

8
app/Controller/v3/GoodsRecommendController.php

@ -211,14 +211,18 @@ class GoodsRecommendController extends BaseController
/**
* 获取搜索页推荐商品列表
* 1、前端上传标识recommend_search_goods recommend_search_stores
* 1、前端上传标识
* recommend_search_goods
* recommend_search_stores
* recommend_user_index
* 2、根据标识从Elasticsearch中获取商品IDs
* 3、根据IDs获取商品数据
* 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
*/
public function getForSearch()
public function getByTab()
{
return $this->success(['tab_data' => $this->data]);
}
}

57
app/Controller/v3/HomeController.php

@ -3,8 +3,16 @@
namespace App\Controller\v3;
use App\Constants\v3\ActivityType;
use App\Constants\v3\SsdbKeys;
use App\Constants\v3\Tabs;
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
{
/**
* @Inject
* @var UserInfoServiceInterface
*/
protected $userInfoService;
/**
* @Inject
* @var CollectStoreServiceInterface
*/
protected $collectStoreService;
/**
* @Inject
* @var CouponServiceInterface
*/
protected $couponService;
/**
* 小程序首页,根据market_id
* 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);
}
}

3
app/Model/v3/User.php

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

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

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

@ -15,11 +15,21 @@ class CollectStoreService implements CollectStoreServiceInterface
public function check($marketId, $storeId, $userId)
{
return true;
return (bool)mt_rand(0,1);
}
public function undo($marketId, $storeId, $userId)
{
// TODO: Implement undo() method.
}
public function countByUser($userId)
{
return mt_rand(0,30);
}
public function countByStore($storeId)
{
// TODO: Implement countByStore() method.
}
}

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

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

@ -30,11 +30,19 @@ class UserInfoService implements UserInfoServiceInterface
public function check($userId)
{
// TODO: Implement check() method.
return User::query()->where(['status' => 1, 'id' => $userId])->exists();
}
public function undo($userId)
{
// 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();
}
}

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

@ -7,4 +7,6 @@ interface CollectStoreServiceInterface
public function do($marketId, $storeId, $userId);
public function check($marketId, $storeId, $userId);
public function undo($marketId, $storeId, $userId);
public function countByUser($userId);
public function countByStore($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);
}

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

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

1
config/autoload/dependencies.php

@ -51,4 +51,5 @@ return [
\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\CouponServiceInterface::class => \App\Service\v3\Implementations\CouponService::class,
];

3
config/routes.php

@ -95,8 +95,9 @@ Router::addGroup('/v3/', function () {
Router::post('search/hotKeywords', 'App\Controller\v3\SearchController@hotKeywords');
Router::post('search/goods', 'App\Controller\v3\SearchController@goods');
Router::post('search/stores', 'App\Controller\v3\SearchController@stores');
Router::post('goodsRecommend/getForSearch', 'App\Controller\v3\GoodsRecommendController@getForSearch');
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]]);
// 需要登录的路由

Loading…
Cancel
Save