| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\jobs;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\models\GoodsFullMinus;
- use app\models\GoodsPic;
- use app\models\Md;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- /**
- * 同步独立运营门店商品
- */
- class CreatedMdGoods extends BaseObject implements JobInterface
- {
- public int $goods_id;
- public int $status;
- public function execute($queue)
- {
- try {
- $goods_id = $this->goods_id;
- $status = $this->status; // 是否删除
- $goods = Goods::findOne(['id' => $goods_id, 'md_food_id' => 0]);
- if ($goods) {
- if ($status) {
- GoodsCat::updateAll(['is_delete' => 1], ['old_goods_id' => $goods_id]);
- } else {
- $md_list = Md::find()->where(['store_id' => $goods->store_id, 'is_delete' => 0, 'is_single' => 1])
- ->select('id')->asArray()->all();
- foreach ($md_list as $item) {
- $goods_ = Goods::findOne(['md_food_id' => $item['id'], 'is_delete' => 0, 'old_goods_id' => $goods_id]);
- $status_ = $goods->status;
- if ($goods_) {
- $status_ = $goods_->status;
- }
- $goods_ = $goods_ ?? new Goods();
- $goods_->attributes = $goods;
- $goods_->old_goods_id = $goods_id;
- $goods_->status = $status_;
- if ($goods_->save()) {
- //同步分类
- $goods_cat = GoodsCat::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all();
- GoodsCat::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]);
- foreach ($goods_cat as $cat) {
- $goods_cat_ = new GoodsCat();
- $goods_cat_->attributes = $cat;
- $goods_cat_->goods_id = $goods_->id;
- $goods_cat_->save();
- }
- //同步满减
- $goods_full_minus = GoodsFullMinus::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all();
- GoodsFullMinus::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]);
- foreach ($goods_full_minus as $cat) {
- $goods_full_minus_ = new GoodsFullMinus();
- $goods_full_minus_->attributes = $cat;
- $goods_full_minus_->goods_id = $goods_->id;
- $goods_full_minus_->save();
- }
- //同步商品图片
- $goods_pic = GoodsPic::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->asArray()->all();
- GoodsPic::updateAll(['is_delete' => 1], ['goods_id' => $goods_->id, 'is_delete' => 0]);
- foreach ($goods_pic as $cat) {
- $goods_pic_ = new GoodsPic();
- $goods_pic_->attributes = $cat;
- $goods_pic_->goods_id = $goods_->id;
- $goods_pic_->save();
- }
- }
- }
- }
- }
- } catch (\Exception $e) {
- debug_log('门店同步商品处理:' . $e->getMessage() . $e->getLine() . $e->getFile(),'md_goods.log');
- }
- }
- }
|