from_store_id; $to_store_id = $this->to_store_id; $name = $this->name[0]; foreach ($to_store_id as $store_id_item) { //同步配置 基础配置 佣金配置 推广海报 $result = $this->shareBasicConfig($from_store_id, $store_id_item, $name); //同步等级 // $levelResult = $this->shareLevel($from_store_id, $store_id_item); } } //同步等级 private function shareLevel($from_store_id, $to_store_id) { try { $shareLevelList = ShareLevel::find()->where(['store_id' => $from_store_id, 'is_delete' => 0])->asArray()->all(); foreach ($shareLevelList as $item) { //判断是否为当前商城同步过此商品 $share_level = ShareLevel::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'level' => $item['level']]); if (!$share_level) { $share_level = new ShareLevel(); } $id = $item['id']; unset($item['id']); $share_level->attributes = $item; $share_level->store_id = $to_store_id; if (!$share_level->save()) { return [ 'code' => 1, 'msg' => json_encode($share_level->errors, JSON_UNESCAPED_UNICODE) ]; }; (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $id, $share_level->id, StoreSyncExtLog::TYPE_SHARE_CONFIG); } return [ 'code' => 0, 'msg' => '同步成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //同步配置 基础配置 佣金配置 推广海报 private function shareBasicConfig($from_store_id, $to_store_id, $name) { try { if ($name === "share_basic_setting") { $share_basic_setting = Option::get('share_basic_setting', $from_store_id, OptionSetting::SHARE_GROUP_NAME)['value']; try { $share_basic_setting = json_decode($share_basic_setting, true); if (isset($share_basic_setting['share_goods_id']['value'])) { $ids = \explode(',', $share_basic_setting['share_goods_id']['value']); $arr = []; foreach ($ids as $id) { $storeSyncExtLog = StoreSyncExtLog::findOne([ 'from_store_id' => $from_store_id, 'to_store_id' => $to_store_id, 'type' => StoreSyncExtLog::TYPE_PRODUCT, 'from_id' => $id, ]); if ($storeSyncExtLog) { $arr[] = $storeSyncExtLog->to_id; } } $share_basic_setting['share_goods_id']['value'] = \implode(',', $arr); } $share_basic_setting = json_encode($share_basic_setting, JSON_UNESCAPED_UNICODE); Option::set('share_basic_setting', $share_basic_setting, $to_store_id, OptionSetting::SHARE_GROUP_NAME); } catch (Exception $e) { } } if ($name === "share_money_setting") { $share_basic_setting = Option::get('share_money_setting', $from_store_id, OptionSetting::SHARE_GROUP_NAME)['value']; try { Option::set('share_money_setting', $share_basic_setting, $to_store_id, OptionSetting::SHARE_GROUP_NAME); } catch (Exception $e) { } } if ($name === "share_qrcode") { $qrcode = Qrcode::findOne(['store_id' => $from_store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); $to_qrcode = Qrcode::findOne(['store_id' => $to_store_id, 'is_delete' => 0, 'type' => Qrcode::TYPE_SHARE]); if (!$to_qrcode) { $to_qrcode = new Qrcode(); } unset($qrcode['id']); $to_qrcode->attributes = $qrcode->attributes; $to_qrcode->store_id = $to_store_id; $to_qrcode->created_at = time(); $to_qrcode->updated_at = time(); if (!$to_qrcode->save()) { return [ 'code' => 1, 'msg' => json_encode($to_qrcode->errors, JSON_UNESCAPED_UNICODE) ]; } } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch(\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** 同步分销end **/ }