GoodsUpdateObserverQueue.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/11/18
  8. * Time: 16:37
  9. */
  10. namespace app\common\modules\goods\queue;
  11. use app\common\models\Goods;
  12. use app\common\modules\goods\events\GoodsStockChangeEvent;
  13. use Illuminate\Bus\Queueable;
  14. use Illuminate\Queue\SerializesModels;
  15. use Illuminate\Queue\InteractsWithQueue;
  16. use Illuminate\Contracts\Queue\ShouldQueue;
  17. class GoodsUpdateObserverQueue implements ShouldQueue
  18. {
  19. use InteractsWithQueue, Queueable, SerializesModels;
  20. private $uniacid;
  21. protected $goods;
  22. protected $requestData;
  23. protected $type;
  24. public function __construct($uniacid, Goods $goods, $requestData)
  25. {
  26. $this->uniacid = $uniacid;
  27. \YunShop::app()->uniacid = $uniacid;
  28. \Setting::$uniqueAccountId = $uniacid;
  29. $this->requestData = $requestData;
  30. $this->goods = $goods;
  31. }
  32. public function handle()
  33. {
  34. \YunShop::app()->uniacid = $this->uniacid;
  35. \Setting::$uniqueAccountId = $this->uniacid;
  36. \Log::debug(\YunShop::app()->uniacid.'----库存变动--'.$this->goods->id, $this->goods->getDirty());
  37. \Log::debug('---库存变动------', $this->goods->getAttributes());
  38. \Log::debug('---库存变动------', $this->requestData);
  39. //有修改退库存
  40. $bool = $this->goods->isDirty('stock');
  41. if ($bool) {
  42. \Log::debug('----库存变动--stock'.$bool);
  43. }
  44. if ($bool) {
  45. $event = new GoodsStockChangeEvent($this->goods, $this->requestData);
  46. \Log::debug('----库存变动--触发--'.get_class($event));
  47. event($event);
  48. }
  49. }
  50. }