| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\jobs\storeSync;
- use app\models\Cat;
- use app\models\StoreSyncExtLog;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- class GoodsCatJob extends BaseObject implements JobInterface
- {
- public array $cat_id;
- public array $to_store_id;
- public int $from_store_id;
- public function execute($queue)
- {
- $from_store_id = $this->from_store_id;
- $to_store_id = $this->to_store_id;
- $cat_id = $this->cat_id;
- foreach ($to_store_id as $store_id_item) {
- //商品分类
- $this->handleGoodsCat($from_store_id, $store_id_item, $cat_id);
- }
- }
- private function handleGoodsCat($from_store_id, $to_store_id, $cat_id) {
- $cats = Cat::find()->where([
- 'store_id' => $from_store_id,
- 'id' => $cat_id,
- ])->asArray()->all();
- foreach ($cats as $cat) {
- $catC = $cat;
- //判断是否为当前商城同步过此商品
- $storeSyncExtLog = StoreSyncExtLog::findOne([
- 'from_store_id' => $from_store_id,
- 'to_store_id' => $to_store_id,
- 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
- 'from_id' => $cat['id']
- ]);
- $c = Cat::findOne($storeSyncExtLog->to_id ?? 0) ?: new Cat();
- //判断是否为当前商城同步过此商品
- $storeSyncExtLogCatParent = StoreSyncExtLog::findOne([
- 'from_store_id' => $from_store_id,
- 'to_store_id' => $to_store_id,
- 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
- 'from_id' => $cat['parent_id']
- ]);
- unset($catC['id']);
- $catC['store_id'] = $to_store_id;
- $c->setAttributes($catC, false);
- $c->parent_id = $storeSyncExtLogCatParent->to_id ?? 0;
- $c->save();
- (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $cat['id'], $c->id, StoreSyncExtLog::TYPE_PRODUCT_CAT);
- }
- }
- }
|