Browse Source

接口规范化 优化

master
Lemon 5 years ago
parent
commit
e41801d04f
  1. 15
      app/Constants/v3/SsdbKeys.php
  2. 31
      app/Controller/v3/CollectStoreController.php
  3. 5
      app/Controller/v3/GoodsController.php
  4. 23
      app/Controller/v3/OrderOnlineController.php
  5. 14
      app/Controller/v3/ShopCartController.php
  6. 27
      app/Controller/v3/ShopCartUpdateController.php
  7. 32
      app/Controller/v3/UpdateShopCartController.php
  8. 2
      app/Model/v3/Goods.php
  9. 3
      app/Service/v3/Implementations/AppointmentTimeService.php
  10. 54
      app/Service/v3/Implementations/CollectStoreService.php
  11. 34
      app/Service/v3/Implementations/GoodsService.php
  12. 6
      app/Service/v3/Implementations/OrderOnlineService.php
  13. 9
      app/Service/v3/Implementations/ShopCartService.php
  14. 8
      app/Service/v3/Implementations/ShopCartUpdateService.php
  15. 2
      app/Service/v3/Interfaces/AppointmentTimeServiceInterface.php
  16. 16
      app/Service/v3/Interfaces/CollectStoreServiceInterface.php
  17. 2
      app/Service/v3/Interfaces/GoodsServiceInterface.php
  18. 4
      app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
  19. 6
      app/Service/v3/Interfaces/ShopCartServiceInterface.php
  20. 12
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php
  21. 12
      app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php
  22. 5
      config/autoload/dependencies.php
  23. 15
      config/routes.php

15
app/Constants/v3/SsdbKeys.php

@ -19,4 +19,19 @@ class SsdbKeys extends AbstractConstants
* @Message("商品月销")
*/
const GOODS_MONTH_SALES = 'goods_m_sales_';
/**
* @Message("收藏店铺")
*/
const COLLECT_STORE_USER = 'collect_store_user_';
/**
* @Message("用户收藏店铺数量")
*/
const COLLECT_STORE_NUM_USER = 'collect_store_num_user_';
/**
* @Message("店铺被收藏数量")
*/
const COLLECT_NUM_STORE = 'collect_num_store_';
}

31
app/Controller/v3/CollectStoreController.php

@ -0,0 +1,31 @@
<?php
namespace App\Controller\v3;
use App\Controller\BaseController;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
class CollectStoreController extends BaseController
{
/**
* @Inject
* @var CollectStoreServiceInterface
*/
protected $collectStoreService;
public function update()
{
$params = $this->request->all();
//判断是否已收藏店铺
$exists = $this->collectStoreService->check($params['user_id'],$params['store_id']);
//如果已收藏则删除
if($exists){
$res = $this->collectStoreService->undo($params['user_id'],$params['store_id']);
}else{
$res = $this->collectStoreService->do($params['user_id'],$params['store_id']);
}
return $this->success($res);
}
}

5
app/Controller/v3/GoodsController.php

@ -11,10 +11,11 @@ class GoodsController extends BaseController
* @Inject
* @var GoodsServiceInterface
*/
protected $goods;
protected $goodsService;
public function detail()
{
$res = $this->goods->detail();
$res['detail'] = $this->goodsService->do();
$res['banner'] = $this->goodsService->getBanner();
return $this->success($res);
}
}

23
app/Controller/v3/OnlineOrderController.php → app/Controller/v3/OrderOnlineController.php

@ -7,10 +7,10 @@ use App\Controller\BaseController;
use App\Exception\ErrorCodeException;
use App\Service\CouponServiceInterface;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\OnlineOrderServiceInterface;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\UserBindTelServiceInterface;
use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
class OnlineOrderController extends BaseController
class OrderOnlineController extends BaseController
{
/**
* @Inject
@ -26,7 +26,7 @@ class OnlineOrderController extends BaseController
* @Inject
* @var AppointmentTimeServiceInterface
*/
protected $appointmentTime;
protected $appointmentTimeService;
/*
* 如果没有绑手机号去绑定页面
* 收货地址接口
@ -56,12 +56,7 @@ class OnlineOrderController extends BaseController
'user_id' => '214'
];
//返回预约送达时间 数组
$res['appointment_time'] = [
'08:30 - 09:00',
'09:00 - 09:30',
'09:30 - 10:00',
'10:00 - 10:30'
];
$res['appointment_time'] = $this->appointmentTimeService->do();
//
$res['store_list'] = [
[
@ -118,14 +113,4 @@ class OnlineOrderController extends BaseController
];
return $this->success($res);
}
public function check()
{
}
public function undo()
{
}
}

14
app/Controller/v3/ShopCartController.php

@ -16,21 +16,11 @@ class ShopCartController extends BaseController
public function detail()
{
//获取购物车商品信息
$res['store_goood_lists'] = $this->shopCartService->detail();
$res['store_lists'] = $this->shopCartService->do();
//获取购物车失效商品信息
$res['store_invalid_goood_lists'] = $this->shopCartService->undo();
$res['store_lists_invalid'] = $this->shopCartService->undo();
//计算购物车价格
$res['total'] = '820.00';
return $this->success($res);
}
public function getGoodsNum()
{
}
public function undo()
{
}
}

27
app/Controller/v3/ShopCartUpdateController.php

@ -0,0 +1,27 @@
<?php
namespace App\Controller\v3;
use App\Controller\BaseController;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
class ShopCartUpdateController extends BaseController
{
/**
* @Inject
* @var ShopCartUpdateServiceInterface
*/
protected $shopCarServiceUpdate;
public function update()
{
$res = $this->shopCarServiceUpdate->do($this->request->all());
return $this->success($res);
}
public function delete()
{
$res = $this->shopCarServiceUpdate->undo($this->request->all());
return $this->success($res);
}
}

32
app/Controller/v3/UpdateShopCartController.php

@ -1,32 +0,0 @@
<?php
namespace App\Controller\v3;
use App\Controller\BaseController;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\UpdateShopCartServiceInterface;
class UpdateShopCartController extends BaseController
{
/**
* @Inject
* @var UpdateShopCartServiceInterface
*/
protected $updateShopCarService;
public function update()
{
$res = $this->updateShopCarService->update($this->request->all());
return $this->success($res);
}
public function check()
{
}
public function delete()
{
$res = $this->updateShopCarService->delete($this->request->all());
return $this->success($res);
}
}

2
app/Model/v3/Goods.php

@ -74,7 +74,7 @@ class Goods extends Model
public function getCartNumAttribute()
{
return (integer)$this->shopCartService->getGoodsNum($this->id);
return (integer)$this->shopCartService->check($this->id);
}
public function store()

3
app/Service/v3/Implementations/AppointmentTimeService.php

@ -7,9 +7,10 @@ use phpDocumentor\Reflection\Types\Object_;
class AppointmentTimeService implements AppointmentTimeServiceInterface
{
public function get()
public function do()
{
return [
'尽快送达',
'08:30 - 09:00',
'09:00 - 09:30',
'09:30 - 10:00',

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

@ -0,0 +1,54 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Constants\v3\SsdbKeys;
use App\TaskWorker\SSDBTask;
use Hyperf\Utils\ApplicationContext;
class CollectStoreService implements CollectStoreServiceInterface
{
public function do($userId,$storeId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
//收藏店铺
$userSet = $ssdb->exec('set', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time());
//用户收藏数量自增
$userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,1);
//店铺被收藏数自增
$storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$storeId,1);
return $userSet && $userIncr && $storeIncr;
}
public function check($userId,$storeId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
return $ssdb->exec('exists', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId);
}
public function undo($userId,$storeId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
//取消收藏店铺
$userDel = $ssdb->exec('del', SsdbKeys::COLLECT_STORE_USER.$userId.'_store_'.$storeId,time());
//用户收藏数量自减
$userIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_STORE_NUM_USER.$userId,'-1');
//店铺被收藏数自减
$storeIncr = $ssdb->exec('incr', SsdbKeys::COLLECT_NUM_STORE.$userId,'-1');
return $userDel && $userIncr && $storeIncr;
}
public function countByUser($userId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$num = $ssdb->exec('get',SsdbKeys::COLLECT_STORE_NUM_USER.$userId);
return $num;
}
public function countByStore($storeId)
{
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
$num = $ssdb->exec('get',SsdbKeys::COLLECT_NUM_STORE.$storeId);
return $num;
}
}

34
app/Service/v3/Implementations/GoodsService.php

@ -8,11 +8,21 @@ use App\Model\v3\Goods;
class GoodsService implements GoodsServiceInterface
{
public function detail()
public function do()
{
$res = Goods::query()->where('id',35)->get();
return $res;
}
public function check($goodsId)
{
// TODO: Implement check() method.
}
public function undo()
{
$goods['detail'] = Goods::query()->where('id',35)->get();
$goods['banner'] = $this->getBanner();
return $goods;
// TODO: Implement undo() method.
}
public function getBanner()
@ -31,20 +41,4 @@ class GoodsService implements GoodsServiceInterface
];
return $banner;
}
public function do()
{
// TODO: Implement do() method.
}
public function check($goodsId)
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
}

6
app/Service/v3/Implementations/OnlineOrderService.php → app/Service/v3/Implementations/OrderOnlineService.php

@ -3,10 +3,10 @@
namespace App\Service\v3\Implementations;
use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\OnlineOrderServiceInterface;
class OnlineOrderService implements OnlineOrderServiceInterface
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
class OrderOnlineService implements OrderOnlineServiceInterface
{
public function detail($params){
public function do($params){
return [];
}

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

@ -6,7 +6,7 @@ use App\Service\v3\Interfaces\ShopCartServiceInterface;
class ShopCartService implements ShopCartServiceInterface
{
public function detail()
public function do()
{
$res = [
[
@ -55,7 +55,7 @@ class ShopCartService implements ShopCartServiceInterface
return $res;
}
public function getGoodsNum()
public function check()
{
return mt_rand(0,6);
}
@ -108,4 +108,9 @@ class ShopCartService implements ShopCartServiceInterface
];
return $res;
}
public function countGoods()
{
return mt_rand(1,100);
}
}

8
app/Service/v3/Implementations/UpdateShopCartService.php → app/Service/v3/Implementations/ShopCartUpdateService.php

@ -4,11 +4,11 @@ namespace App\Service\v3\Implementations;
use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\UpdateShopCartServiceInterface;
use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
class UpdateShopCartService implements UpdateShopCartServiceInterface
class ShopCartUpdateService implements ShopCartUpdateServiceInterface
{
public function update($params)
public function do($params)
{
switch ($params['goods_id'])
{
@ -31,7 +31,7 @@ class UpdateShopCartService implements UpdateShopCartServiceInterface
// TODO: Implement check() method.
}
public function delete($params)
public function undo($params)
{
return true;
}

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

@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces;
interface AppointmentTimeServiceInterface
{
public function get();
public function do();
public function check();

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

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

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

@ -7,5 +7,5 @@ interface GoodsServiceInterface
public function do();
public function check($goodsId);
public function undo();
public function detail();
public function getBanner();
}

4
app/Service/v3/Interfaces/OnlineOrderServiceInterface.php → app/Service/v3/Interfaces/OrderOnlineServiceInterface.php

@ -2,9 +2,9 @@
namespace App\Service\v3\Interfaces;
interface OnlineOrderServiceInterface
interface OrderOnlineServiceInterface
{
public function detail($params);
public function do($params);
public function check();

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

@ -4,9 +4,11 @@ namespace App\Service\v3\Interfaces;
interface ShopCartServiceInterface
{
public function detail();
public function do();
public function getGoodsNum();
public function check();
public function undo();
public function countGoods();
}

12
app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php

@ -0,0 +1,12 @@
<?php
namespace App\Service\v3\Interfaces;
interface ShopCartUpdateServiceInterface
{
public function do($params);
public function check();
public function undo($params);
}

12
app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php

@ -1,12 +0,0 @@
<?php
namespace App\Service\v3\Interfaces;
interface UpdateShopCartServiceInterface
{
public function update($params);
public function check();
public function delete($params);
}

5
config/autoload/dependencies.php

@ -40,13 +40,14 @@ return [
\App\Service\v3\Interfaces\HelperServiceInterface::class => \App\Service\v3\Implementations\HelperService::class,
\App\Service\v3\Interfaces\VerifyCodeServiceInterface::class => \App\Service\v3\Implementations\VerifyCodeService::class,
\App\Service\v3\Interfaces\UserBindTelServiceInterface::class => \App\Service\v3\Implementations\UserBindTelService::class,
\App\Service\v3\Interfaces\OnlineOrderServiceInterface::class => \App\Service\v3\Implementations\OnlineOrderService::class,
\App\Service\v3\Interfaces\OrderOnlineServiceInterface::class => \App\Service\v3\Implementations\OrderOnlineService::class,
\App\Service\v3\Interfaces\DistributionPriceServiceInterface::class => \App\Service\v3\Implementations\DistributionPriceService::class,
\App\Service\v3\Interfaces\AppointmentTimeServiceInterface::class => \App\Service\v3\Implementations\AppointmentTimeService::class,
\App\Service\v3\Interfaces\CategoryServiceInterface::class => \App\Service\v3\Implementations\CategoryService::class,
\App\Service\v3\Interfaces\UpdateShopCartServiceInterface::class => \App\Service\v3\Implementations\UpdateShopCartService::class,
\App\Service\v3\Interfaces\ShopCartUpdateServiceInterface::class => \App\Service\v3\Implementations\ShopCartUpdateService::class,
\App\Service\v3\Interfaces\ShopCartServiceInterface::class => \App\Service\v3\Implementations\ShopCartService::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\SearchServiceInterface::class => \App\Service\v3\Implementations\SearchService::class,
\App\Service\v3\Interfaces\CollectStoreServiceInterface::class => \App\Service\v3\Implementations\CollectStoreService::class,
];

15
config/routes.php

@ -81,17 +81,10 @@ Router::addGroup('/v3/', function () {
Router::post('home/appletIndex', 'App\Controller\v3\HomeController@appletIndex');
Router::post('goods/detail', 'App\Controller\v3\GoodsController@detail');
Router::post('goodsRecommend/getByTabsForAppletIndex', 'App\Controller\v3\GoodsRecommendController@getByTabsForAppletIndex');
Router::post('onlineOrder/detail', 'App\Controller\v3\OnlineOrderController@detail');
Router::post('distributionPrice/get', 'App\Controller\v3\DistributionPriceController@get');
Router::post('category/all', 'App\Controller\v3\CategoryController@all');
Router::post('updateShopCart/update', 'App\Controller\v3\UpdateShopCartController@update');
Router::post('shopCart/detail', 'App\Controller\v3\ShopCartController@detail');
Router::post('login/wxLogin', 'App\Controller\v3\LoginController@wxLogin');
Router::post('location/getMarketListByLocation', 'App\Controller\v3\LocationController@getMarketListByLocation');
Router::post('userDeliveryAddress/update', 'App\Controller\v3\UserDeliveryAddressController@update');
Router::post('userDeliveryAddress/get', 'App\Controller\v3\UserDeliveryAddressController@get');
Router::post('userDeliveryAddress/delete', 'App\Controller\v3\UserDeliveryAddressController@delete');
Router::post('userDeliveryAddress/getList', 'App\Controller\v3\UserDeliveryAddressController@getList');
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');
@ -102,4 +95,12 @@ Router::addGroup('/v3/', function () {
Router::post('sms/getVerifyCode', 'App\Controller\v3\SmsController@getVerifyCode');
Router::post('user/bindTel', 'App\Controller\v3\UserController@bindTel');
Router::post('user/updateInfo', 'App\Controller\v3\UserController@updateInfo');
Router::post('orderOnline/detail', 'App\Controller\v3\OrderOnlineController@detail');
Router::post('userDeliveryAddress/update', 'App\Controller\v3\UserDeliveryAddressController@update');
Router::post('userDeliveryAddress/get', 'App\Controller\v3\UserDeliveryAddressController@get');
Router::post('userDeliveryAddress/delete', 'App\Controller\v3\UserDeliveryAddressController@delete');
Router::post('userDeliveryAddress/getList', 'App\Controller\v3\UserDeliveryAddressController@getList');
Router::post('collectStore/update', 'App\Controller\v3\CollectStoreController@update');
Router::post('shopCartUpdate/update', 'App\Controller\v3\ShopCartUpdateController@update');
Router::post('shopCart/detail', 'App\Controller\v3\ShopCartController@detail');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
Loading…
Cancel
Save