SyncCloudGoodsPriceJob.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\jobs;
  3. use yii\base\BaseObject;
  4. use yii\queue\JobInterface;
  5. use app\models\Goods;
  6. use app\modules\admin\models\GoodsForm;
  7. //后台修改云仓溢价比例后,同步云仓商品价格
  8. class SyncCloudGoodsPriceJob extends BaseObject implements JobInterface
  9. {
  10. public $store_id;
  11. public function execute($queue)
  12. {
  13. $goods_list = Goods::find()->select(['id', 'cloud_goods_id'])->where([
  14. 'store_id' => $this->store_id,
  15. 'is_delete' => 0,
  16. 'is_wholesale' => 0
  17. ])->andWhere('cloud_goods_id > 0')->asArray()->all();
  18. foreach ($goods_list as $goods) {
  19. try {
  20. $model = new GoodsForm();
  21. $model->id = $goods['cloud_goods_id'];
  22. $model->store_id = $this->store_id;
  23. $model->saveCloudGoods();
  24. } catch (\Throwable $e) {
  25. debug_log('同步云仓商品价格失败,商品ID:' . $goods['id'] . ',错误信息:' . $e->getMessage(), 'SyncCloudGoodsPriceJob.log');
  26. continue;
  27. }
  28. }
  29. }
  30. }