| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\jobs;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- use app\models\Goods;
- use app\modules\admin\models\GoodsForm;
- //后台修改云仓溢价比例后,同步云仓商品价格
- class SyncCloudGoodsPriceJob extends BaseObject implements JobInterface
- {
- public $store_id;
- public function execute($queue)
- {
- $goods_list = Goods::find()->select(['id', 'cloud_goods_id'])->where([
- 'store_id' => $this->store_id,
- 'is_delete' => 0,
- 'is_wholesale' => 0
- ])->andWhere('cloud_goods_id > 0')->asArray()->all();
- foreach ($goods_list as $goods) {
- try {
- $model = new GoodsForm();
- $model->id = $goods['cloud_goods_id'];
- $model->store_id = $this->store_id;
- $model->saveCloudGoods();
- } catch (\Throwable $e) {
- debug_log('同步云仓商品价格失败,商品ID:' . $goods['id'] . ',错误信息:' . $e->getMessage(), 'SyncCloudGoodsPriceJob.log');
- continue;
- }
- }
- }
- }
|