You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Service\v3\Interfaces\GoodsInventoryServiceInterface;
  4. use Hyperf\Redis\Redis;
  5. use Hyperf\Utils\ApplicationContext;
  6. class GoodsInventoryService implements GoodsInventoryServiceInterface
  7. {
  8. /**
  9. * @inheritDoc
  10. */
  11. public function doSold($activityType, $goodsId, $num)
  12. {
  13. $redis = ApplicationContext::getContainer()->get(Redis::class);
  14. $hName = 'goods:inventory_sold_' . $activityType;
  15. $hKey = 'goods_id_' . $goodsId;
  16. $redis->hIncrBy($hName, $hKey, $num);
  17. }
  18. /**
  19. * @inheritDoc
  20. */
  21. public function undoSold($activityType, $goodsId, $num)
  22. {
  23. $redis = ApplicationContext::getContainer()->get(Redis::class);
  24. $hName = 'goods:inventory_sold_' . $activityType;
  25. $hKey = 'goods_id_' . $goodsId;
  26. $redis->hIncrBy($hName, $hKey, -1*$num);
  27. }
  28. /**
  29. * @inheritDoc
  30. */
  31. public function getSold($activityType, $goodsId)
  32. {
  33. $redis = ApplicationContext::getContainer()->get(Redis::class);
  34. $hName = 'goods:inventory_sold_' . $activityType;
  35. $hKey = 'goods_id_' . $goodsId;
  36. return $redis->hGet($hName, $hKey);
  37. }
  38. }