HotDataServices.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\other;
  12. use app\services\activity\discounts\StoreDiscountsServices;
  13. use app\services\activity\integral\StoreIntegralServices;
  14. use app\services\activity\bargain\StoreBargainServices;
  15. use app\services\activity\combination\StoreCombinationServices;
  16. use app\services\activity\seckill\StoreSeckillServices;
  17. use app\services\BaseServices;
  18. use app\services\product\sku\StoreProductAttrValueServices;
  19. use crmeb\services\CacheService;
  20. use crmeb\traits\ServicesTrait;
  21. /**
  22. * Class HotDataServices
  23. * @package app\services\product\product
  24. */
  25. class HotDataServices extends BaseServices
  26. {
  27. use ServicesTrait;
  28. public function hot(int $type = 0)
  29. {
  30. /** @var StoreProductAttrValueServices $productAttrValueServices */
  31. $productAttrValueServices = app()->make(StoreProductAttrValueServices::class);
  32. switch ($type) {
  33. case 0://普通商品
  34. break;
  35. case 1://秒杀商品
  36. /** @var StoreSeckillServices $seckillServices */
  37. $seckillServices = app()->make(StoreSeckillServices::class);
  38. $products = $seckillServices->getListByTime(0);
  39. if ($products) {
  40. $products = array_column($products, 'id');
  41. $attrValue = $productAttrValueServices->getSkuArray([['product_id', 'IN', $products], ['type', '=', 1], ['quota', '>', 0]], 'unique,quota,quota_show');
  42. if ($attrValue) {
  43. foreach ($attrValue as $item) {
  44. CacheService::setStock($item['unique'], (int)$item['quota'], 1);
  45. }
  46. }
  47. }
  48. break;
  49. case 2://砍价商品
  50. /** @var StoreBargainServices $bargainServices */
  51. $bargainServices = app()->make(StoreBargainServices::class);
  52. $products = $bargainServices->bargainList();
  53. if ($products) {
  54. $products = array_column($products, 'id');
  55. $attrValue = $productAttrValueServices->getSkuArray([['product_id', 'IN', $products], ['type', '=', 2], ['quota', '>', 0]], 'unique,quota,quota_show');
  56. if ($attrValue) {
  57. foreach ($attrValue as $item) {
  58. CacheService::setStock($item['unique'], (int)$item['quota'], 2);
  59. }
  60. }
  61. }
  62. break;
  63. case 3://拼团商品
  64. /** @var StoreCombinationServices $combinationServices */
  65. $combinationServices = app()->make(StoreCombinationServices::class);
  66. $products = $combinationServices->combinationList(['is_del' => 0, 'is_show' => 1, 'pinkIngTime' => true, 'storeProductId' => true]);
  67. if ($products) {
  68. $products = array_column($products, 'id');
  69. $attrValue = $productAttrValueServices->getSkuArray([['product_id', 'IN', $products], ['type', '=', 3], ['quota', '>', 0]], 'unique,quota,quota_show');
  70. if ($attrValue) {
  71. foreach ($attrValue as $item) {
  72. CacheService::setStock($item['unique'], (int)$item['quota'], 3);
  73. }
  74. }
  75. }
  76. break;
  77. case 4://积分商品
  78. /** @var StoreIntegralServices $integralServices */
  79. $integralServices = app()->make(StoreIntegralServices::class);
  80. $products = $integralServices->getColumn(['is_del' => 0], 'id');
  81. if ($products) {
  82. $attrValue = $productAttrValueServices->getSkuArray([['product_id', 'IN', $products], ['type', '=', 4], ['quota', '>', 0]], 'unique,quota,quota_show');
  83. if ($attrValue) {
  84. foreach ($attrValue as $item) {
  85. CacheService::setStock($item['unique'], (int)$item['quota'], 4);
  86. }
  87. }
  88. }
  89. break;
  90. case 5://套餐
  91. /** @var StoreDiscountsServices $discountsServices */
  92. $discountsServices = app()->make(StoreDiscountsServices::class);
  93. $products = $discountsServices->getColumn([['is_del', '=', 0], ['is_limit', '>', 0]], 'id,limit_num');
  94. if ($products) {
  95. foreach ($products as $item) {
  96. CacheService::setStock(md5($item['id']), (int)$item['limit_num'], 5);
  97. }
  98. }
  99. break;
  100. }
  101. }
  102. }