ProductStockValueTips.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\jobs\product;
  12. use app\services\product\sku\StoreProductAttrValueServices;
  13. use app\webscoket\SocketPush;
  14. use crmeb\basic\BaseJobs;
  15. use crmeb\traits\QueueTrait;
  16. /**
  17. * 库存提醒
  18. * Class ProductStockValueTips
  19. * @package app\jobs\product
  20. */
  21. class ProductStockValueTips extends BaseJobs
  22. {
  23. use QueueTrait;
  24. public function doJob($productId, $unique, $type)
  25. {
  26. /** @var StoreProductAttrValueServices $make */
  27. $make = app()->make(StoreProductAttrValueServices::class);
  28. $stock = $make->value([
  29. 'product_id' => $productId,
  30. 'unique' => $unique,
  31. 'type' => $type
  32. ], 'stock');
  33. $store_stock = sys_config('store_stock') ?? 0;//库存预警界限
  34. if ($store_stock >= $stock) {
  35. try {
  36. SocketPush::admin()->data(['id' => $productId])->push();
  37. } catch (\Exception $e) {
  38. }
  39. }
  40. return true;
  41. }
  42. }