SyncDiyClassifyJob.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\jobs;
  3. use app\models\Cat;
  4. use app\models\NewDiyTemplate;
  5. use yii\base\BaseObject;
  6. use yii\queue\JobInterface;
  7. class SyncDiyClassifyJob extends BaseObject implements JobInterface
  8. {
  9. public $store_id;
  10. public function execute($queue)
  11. {
  12. $store_id = $this->store_id;
  13. $fromIndex_ = NewDiyTemplate::findOne([
  14. 'is_delete' => 0,
  15. 'is_index' => 1,
  16. 'store_id' => $store_id,
  17. 'name' => 'DIY',
  18. ]);
  19. $template = \json_decode($fromIndex_->template, true);
  20. if ($template) {
  21. foreach ($template['templates'] as &$index_item) {
  22. if ($index_item['type'] === 'productClassify') {
  23. if (intval($index_item['params']['type']) === 2) {
  24. if (isset($index_item['params']['classifyList'])) {
  25. $cat_list = Cat::find()->where(['store_id' => $store_id, 'is_show' => 1, 'is_delete' => 0, 'parent_id' => 0])
  26. ->select('id, name')->asArray()->all();
  27. $classify_diy = [];
  28. foreach ($cat_list as $cat_item) {
  29. $classify_diy[] = [
  30. "id" => $cat_item['id'],
  31. "title" => $cat_item['name'],
  32. "subTitle" => $cat_item['name'],
  33. "link" => null,
  34. "dataFrom" => "select",
  35. "classifyId" => $cat_item['id'],
  36. "data" => []
  37. ];
  38. }
  39. $index_item['params']['classifyList'] = $classify_diy;
  40. }
  41. }
  42. }
  43. }
  44. $fromIndex_->template = json_encode($template, JSON_UNESCAPED_UNICODE);
  45. $fromIndex_->save();
  46. }
  47. }
  48. }