| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\jobs;
- use app\models\Cat;
- use app\models\NewDiyTemplate;
- use yii\base\BaseObject;
- use yii\queue\JobInterface;
- class SyncDiyClassifyJob extends BaseObject implements JobInterface
- {
- public $store_id;
- public function execute($queue)
- {
- $store_id = $this->store_id;
- $fromIndex_ = NewDiyTemplate::findOne([
- 'is_delete' => 0,
- 'is_index' => 1,
- 'store_id' => $store_id,
- 'name' => 'DIY',
- ]);
- $template = \json_decode($fromIndex_->template, true);
- if ($template) {
- foreach ($template['templates'] as &$index_item) {
- if ($index_item['type'] === 'productClassify') {
- if (intval($index_item['params']['type']) === 2) {
- if (isset($index_item['params']['classifyList'])) {
- $cat_list = Cat::find()->where(['store_id' => $store_id, 'is_show' => 1, 'is_delete' => 0, 'parent_id' => 0])
- ->select('id, name')->asArray()->all();
- $classify_diy = [];
- foreach ($cat_list as $cat_item) {
- $classify_diy[] = [
- "id" => $cat_item['id'],
- "title" => $cat_item['name'],
- "subTitle" => $cat_item['name'],
- "link" => null,
- "dataFrom" => "select",
- "classifyId" => $cat_item['id'],
- "data" => []
- ];
- }
- $index_item['params']['classifyList'] = $classify_diy;
- }
- }
- }
- }
- $fromIndex_->template = json_encode($template, JSON_UNESCAPED_UNICODE);
- $fromIndex_->save();
- }
- }
- }
|