23 changed files with 214 additions and 123 deletions
-
15app/Constants/v3/SsdbKeys.php
-
31app/Controller/v3/CollectStoreController.php
-
5app/Controller/v3/GoodsController.php
-
23app/Controller/v3/OrderOnlineController.php
-
14app/Controller/v3/ShopCartController.php
-
27app/Controller/v3/ShopCartUpdateController.php
-
32app/Controller/v3/UpdateShopCartController.php
-
2app/Model/v3/Goods.php
-
3app/Service/v3/Implementations/AppointmentTimeService.php
-
54app/Service/v3/Implementations/CollectStoreService.php
-
34app/Service/v3/Implementations/GoodsService.php
-
6app/Service/v3/Implementations/OrderOnlineService.php
-
9app/Service/v3/Implementations/ShopCartService.php
-
8app/Service/v3/Implementations/ShopCartUpdateService.php
-
2app/Service/v3/Interfaces/AppointmentTimeServiceInterface.php
-
16app/Service/v3/Interfaces/CollectStoreServiceInterface.php
-
2app/Service/v3/Interfaces/GoodsServiceInterface.php
-
4app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
-
6app/Service/v3/Interfaces/ShopCartServiceInterface.php
-
12app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php
-
12app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php
-
5config/autoload/dependencies.php
-
15config/routes.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); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
interface ShopCartUpdateServiceInterface |
|||
{ |
|||
public function do($params); |
|||
|
|||
public function check(); |
|||
|
|||
public function undo($params); |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
interface UpdateShopCartServiceInterface |
|||
{ |
|||
public function update($params); |
|||
|
|||
public function check(); |
|||
|
|||
public function delete($params); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue