Browse Source

商户(主页)详情页

master
weigang 5 years ago
parent
commit
64648b8b8d
  1. 25
      app/Constants/v3/Goods.php
  2. 44
      app/Constants/v3/Store.php
  3. 51
      app/Controller/v3/StoreController.php
  4. 6
      app/Model/v3/Goods.php
  5. 17
      app/Model/v3/Store.php
  6. 1
      app/Request/v3/SearchGoodsRequest.php
  7. 38
      app/Request/v3/StoreIndexRequest.php
  8. 16
      app/Service/v3/Implementations/CategoryService.php
  9. 25
      app/Service/v3/Implementations/CollectStoreService.php
  10. 4
      app/Service/v3/Implementations/SearchService.php
  11. 37
      app/Service/v3/Implementations/StoreService.php
  12. 1
      app/Service/v3/Interfaces/CategoryServiceInterface.php
  13. 10
      app/Service/v3/Interfaces/CollectStoreServiceInterface.php
  14. 11
      app/Service/v3/Interfaces/StoreServiceInterface.php
  15. 2
      config/autoload/dependencies.php
  16. 1
      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;
}

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

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

6
app/Model/v3/Goods.php

@ -11,6 +11,7 @@ use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Di\Annotation\Inject;
use App\Constants\v3\Goods as GoodsConstants;
/**
*/
@ -18,9 +19,6 @@ class Goods extends Model
{
use SoftDeletes;
const ON_SALE_YES = 1;
const ON_SALE_NO = 2;
/**
* @Inject
* @var ShopCartServiceInterface
@ -59,7 +57,7 @@ class Goods extends Model
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
$builder->where(['on_sale' => self::ON_SALE_YES]);
$builder->where(['on_sale' => GoodsConstants::ON_SALE_YES]);
});
}

17
app/Model/v3/Store.php

@ -5,9 +5,11 @@ namespace App\Model\v3;
use App\Constants\v3\SsdbKeys;
use App\Model\Model;
use App\TaskWorker\SSDBTask;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\Utils\ApplicationContext;
use App\Constants\v3\Store as StoreConstants;
/**
*/
@ -15,13 +17,6 @@ class Store extends Model
{
use SoftDeletes;
const IS_OPEN_YES = 1;
const IS_OPEN_NO = 2;
const STATUS_EXAMINING = 1;
const STATUS_PASS = 2;
const STATUS_REFUSE = 3;
const STATUS_EXPIRED = 4;
/**
* The table associated with the model.
*
@ -49,7 +44,7 @@ class Store extends Model
{
parent::boot();
self::addGlobalScope('normal', function (Builder $builder) {
$builder->where(['is_open' => self::IS_OPEN_YES, 'status' => self::STATUS_PASS]);
$builder->where(['is_open' => StoreConstants::IS_OPEN_YES, 'status' => StoreConstants::STATUS_PASS]);
});
}
@ -60,12 +55,12 @@ class Store extends Model
public function scopeOrderBySales($query, $sort)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
return (integer)$ssdb->exec('get', SsdbKeys::STORE_MONTH_SALES.date('YM').'_'.$this->id);
return $query->orderBy('sales', $sort);
}
public function getMonthSalesAttribute() {
return mt_rand(0,100);
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
return (integer)$ssdb->exec('get', SsdbKeys::STORE_MONTH_SALES.date('YM').'_'.$this->id);
}
public function goods()

1
app/Request/v3/SearchGoodsRequest.php

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

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

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

@ -2,6 +2,8 @@
namespace App\Service\v3\Implementations;
use App\Model\v3\Goods;
use App\Model\v3\GoodsType;
use App\Model\v3\StoreType;
use App\Service\v3\Interfaces\CategoryServiceInterface;
@ -32,4 +34,18 @@ class CategoryService implements CategoryServiceInterface
->get()
->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();
}
}

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

@ -0,0 +1,25 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
class CollectStoreService implements CollectStoreServiceInterface
{
public function do($marketId, $storeId, $userId)
{
// TODO: Implement do() method.
}
public function check($marketId, $storeId, $userId)
{
return true;
}
public function undo($marketId, $storeId, $userId)
{
// TODO: Implement undo() method.
}
}

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

@ -68,6 +68,10 @@ class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
}])
->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']]);
}

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

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

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

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

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

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

2
config/autoload/dependencies.php

@ -49,4 +49,6 @@ return [
\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\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,
];

1
config/routes.php

@ -96,6 +96,7 @@ Router::addGroup('/v3/', function () {
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('store/index', 'App\Controller\v3\StoreController@index');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由

Loading…
Cancel
Save