| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\jobs\storeSync;
- use app\models\PostageRules;
- use app\models\StoreSyncExtLog;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- class DeliveryRulesJob extends BaseObject implements JobInterface
- {
- public array $to_store_id;
- public int $from_store_id;
- public array $delivery_rules_id;
- public function execute($queue)
- {
- $to_store_id = $this->to_store_id;
- $from_store_id = $this->from_store_id;
- $delivery_rules_id = $this->delivery_rules_id;
- $postageRulesArr = PostageRules::find()->where(['id' => $delivery_rules_id])->all();
- if ($postageRulesArr) {
- foreach ($to_store_id as $store_id_item) {
- $this->handle($from_store_id, $store_id_item, $postageRulesArr);
- }
- }
- }
- private function handle($from_store_id, $to_store_id, $postageRulesArr) {
- foreach ($postageRulesArr as $postageRules) {
- //判断是否为当前商城同步过此商品
- $storeSyncExtLog = StoreSyncExtLog::findOne([
- 'from_store_id' => $from_store_id,
- 'to_store_id' => $to_store_id,
- 'type' => StoreSyncExtLog::TYPE_POSTAGE_RULES,
- 'from_id' => $postageRules->id
- ]);
- if (intval($postageRules->is_enable)) {
- PostageRules::updateAll(['is_enable' => 0], ['is_delete' => 0, 'store_id' => $to_store_id]);
- }
- $toPostageRules = PostageRules::findOne($storeSyncExtLog->to_id ?? 0) ?: new PostageRules();
- $toPostageRules->attributes = $postageRules->attributes;
- $toPostageRules->store_id = $to_store_id;
- $toPostageRules->mch_id = 0;
- if ($toPostageRules->save()) {
- (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $postageRules->id, $toPostageRules->id, StoreSyncExtLog::TYPE_POSTAGE_RULES);
- }
- }
- }
- }
|