BatchDownGoodsJob.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\jobs;
  8. use yii\base\BaseObject;
  9. use yii\queue\JobInterface;
  10. use app\models\Goods;
  11. use app\models\MdGoods;
  12. use app\models\Md;
  13. /**
  14. * 用于后台审核完门店后,批量将门店商品下架
  15. */
  16. class BatchDownGoodsJob extends BaseObject implements JobInterface
  17. {
  18. public array $ids;
  19. public int $store_id;
  20. public function execute($queue)
  21. {
  22. $goods = Goods::find()->select('id, attr, virtual_sales, price, goods_num')->where([
  23. 'store_id' => $this->store_id,
  24. 'is_delete' => 0,
  25. ])->asArray()->all();
  26. foreach ($this->ids as $id) {
  27. $md = Md::findOne($id);
  28. if (!$md) {
  29. continue;
  30. }
  31. $delivery_type = $md->self_delivery_type;
  32. foreach ($goods as $value) {
  33. $md_goods = MdGoods::findOne([
  34. 'md_id' => $id,
  35. 'goods_id' => $value['id']
  36. ]);
  37. if (!$md_goods) {
  38. $md_goods = new MdGoods();
  39. $md_goods->md_id = $id;
  40. $md_goods->goods_id = $value['id'];
  41. }
  42. $md_goods->status = 0;
  43. $md_goods->virtual_sales = $value['virtual_sales'];
  44. $md_goods->attr = $value['attr'];
  45. $md_goods->goods_num = $value['goods_num'];
  46. $md_goods->price = $value['price'];
  47. $md_goods->delivery_type = $delivery_type;
  48. $md_goods->save();
  49. }
  50. }
  51. }
  52. }