6 changed files with 148 additions and 60 deletions
-
14app/Service/v3/Implementations/GoodsActivityService.php
-
47app/Service/v3/Implementations/GoodsInventoryService.php
-
12app/Service/v3/Implementations/GoodsService.php
-
101app/Service/v3/Implementations/OrderOnlineService.php
-
33app/Service/v3/Interfaces/GoodsInventoryServiceInterface.php
-
1config/autoload/dependencies.php
@ -0,0 +1,47 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Service\v3\Interfaces\GoodsInventoryServiceInterface; |
|||
use Hyperf\Redis\Redis; |
|||
use Hyperf\Utils\ApplicationContext; |
|||
|
|||
class GoodsInventoryService implements GoodsInventoryServiceInterface |
|||
{ |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function doSold($activityType, $goodsId, $num) |
|||
{ |
|||
$redis = ApplicationContext::getContainer()->get(Redis::class); |
|||
$hName = 'goods_inventory_sold_' . $activityType; |
|||
$hKey = 'goods_id_' . $goodsId; |
|||
|
|||
$redis->hIncrBy($hName, $hKey, $num); |
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function undoSold($activityType, $goodsId, $num) |
|||
{ |
|||
$redis = ApplicationContext::getContainer()->get(Redis::class); |
|||
$hName = 'goods_inventory_sold_' . $activityType; |
|||
$hKey = 'goods_id_' . $goodsId; |
|||
|
|||
$redis->hIncrBy($hName, $hKey, -1*$num); |
|||
} |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function getSold($activityType, $goodsId) |
|||
{ |
|||
$redis = ApplicationContext::getContainer()->get(Redis::class); |
|||
$hName = 'goods_inventory_sold_' . $activityType; |
|||
$hKey = 'goods_id_' . $goodsId; |
|||
|
|||
return $redis->hGet($hName, $hKey); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
interface GoodsInventoryServiceInterface |
|||
{ |
|||
/** |
|||
* 压已售库存(冻结的) |
|||
* @param $activityType |
|||
* @param $goodsId |
|||
* @param $num |
|||
* @return mixed |
|||
*/ |
|||
public function doSold($activityType, $goodsId, $num); |
|||
|
|||
/** |
|||
* 释已售库存(冻结的) |
|||
* @param $activityType |
|||
* @param $goodsId |
|||
* @param $num |
|||
* @return mixed |
|||
*/ |
|||
public function undoSold($activityType, $goodsId, $num); |
|||
|
|||
/** |
|||
* 获取当前商品冻结库存 |
|||
* @param $activityType |
|||
* @param $goodsId |
|||
* @return mixed |
|||
*/ |
|||
public function getSold($activityType, $goodsId); |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue