DiyJob.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <?php
  2. namespace app\jobs\storeSync;
  3. use app\models\NewDiyTemplate;
  4. use app\models\StoreSyncExtLog;
  5. use yii\base\BaseObject;
  6. use yii\queue\JobInterface;
  7. //同步装修
  8. class DiyJob extends BaseObject implements JobInterface
  9. {
  10. public array $to_store_id;
  11. public int $from_store_id;
  12. public array $diy_id;
  13. public function execute($queue)
  14. {
  15. $to_store_id = $this->to_store_id;
  16. $from_store_id = $this->from_store_id;
  17. $diy_id = $this->diy_id;
  18. if (is_array($to_store_id)) {
  19. if (!is_array($diy_id)) {
  20. $diy_id = [$diy_id];
  21. }
  22. foreach ($to_store_id as $store_id_item) {
  23. $this->copyHome($from_store_id, $store_id_item, $diy_id);
  24. }
  25. }
  26. }
  27. private function copyHome($from_store_id, $to_store_id, $diy_id) {
  28. try {
  29. foreach ($diy_id as $diy_item) {
  30. //判断是否为当前商城同步过此商品
  31. $fromIndex_ = NewDiyTemplate::findOne([
  32. 'id' => $diy_item,
  33. 'store_id' => $from_store_id,
  34. ]);
  35. if (intval($fromIndex_->is_index)) {
  36. NewDiyTemplate::updateAll(['is_index' => 0], ['is_delete' => 0, 'is_index' => 1, 'store_id' => $to_store_id]);
  37. }
  38. $template = \json_decode($fromIndex_->template, true);
  39. if ($template) {
  40. if ($fromIndex_->name === 'controls') {
  41. foreach ($template as &$controlsItem) {
  42. if (!empty($controlsItem['params'])) {
  43. if (!empty($controlsItem['params']['navList'])) {
  44. foreach ($controlsItem['params']['navList'] as &$nav_item) {
  45. $nav_item = $this->replaceLink($nav_item, $from_store_id, $to_store_id);
  46. }
  47. }
  48. }
  49. }
  50. } else {
  51. if (!empty($template['templates'])) {
  52. foreach ($template['templates'] as &$index_item) {
  53. $index_item = $this->diyHandleCommon($index_item, $from_store_id, $to_store_id);
  54. }
  55. }
  56. }
  57. //判断是否为当前商城同步过此商品
  58. $storeSyncExtLog = StoreSyncExtLog::findOne([
  59. 'from_store_id' => $from_store_id,
  60. 'to_store_id' => $to_store_id,
  61. 'type' => StoreSyncExtLog::TYPE_DIY,
  62. 'from_id' => $diy_item
  63. ]);
  64. $toIndex = NewDiyTemplate::findOne($storeSyncExtLog->to_id ?? 0);
  65. if ($fromIndex_->name === 'controls') {
  66. $toIndex = NewDiyTemplate::findOne(['name' => 'controls', 'is_delete' => 0, 'store_id' => $to_store_id]);
  67. }
  68. $toIndex = $toIndex ?: new NewDiyTemplate();
  69. $toIndex->store_id = $to_store_id;
  70. $toIndex->template = json_encode($template);
  71. $toIndex->addtime = time();
  72. $toIndex->name = $fromIndex_->name;
  73. $toIndex->is_index = $fromIndex_->is_index;
  74. $toIndex->type = $fromIndex_->type;
  75. $toIndex->is_delete = $fromIndex_->is_delete;
  76. if (!$toIndex->save()) {
  77. throw new \Exception(json_encode($toIndex->errors, JSON_UNESCAPED_UNICODE));
  78. }
  79. (new StoreSyncExtLog())::handleData($from_store_id, $to_store_id, $diy_item, $toIndex->id, StoreSyncExtLog::TYPE_DIY);
  80. }
  81. }
  82. } catch (\Exception $e) {
  83. }
  84. }
  85. //处理装修公用部分
  86. public function diyHandleCommon($template, $from_store_id, $to_store_id)
  87. {
  88. // 头部导航
  89. if ($template['type'] == 'fastNav') {
  90. $template = $this->replaceFastNav($template, $from_store_id, $to_store_id);
  91. }
  92. // 图片轮播
  93. if ($template['type'] == 'banner') {
  94. $template = $this->replaceBanner($template, $from_store_id, $to_store_id);
  95. }
  96. // 魔方导航
  97. if ($template['type'] == 'cubeNav') {
  98. $template = $this->replaceCubeNav($template, $from_store_id, $to_store_id);
  99. }
  100. // 魔方图片
  101. if ($template['type'] == 'container') {
  102. $template = $this->replaceContainer($template, $from_store_id, $to_store_id);
  103. }
  104. // 产品展示
  105. if ($template['type'] == 'productShow') {
  106. $template = $this->replaceProductShow($template, $from_store_id, $to_store_id);
  107. }
  108. //产品分类
  109. if ($template['type'] == 'productClassify') {
  110. $template = $this->replaceProductClassify($template, $from_store_id, $to_store_id);
  111. }
  112. // 倒计时
  113. if ($template['type'] == 'marketCountDown') {
  114. $template = $this->replaceMarketCountDown($template, $from_store_id, $to_store_id);
  115. }
  116. //图片
  117. if ($template['type'] == 'images') {
  118. $template = $this->replaceImages($template, $from_store_id, $to_store_id);
  119. }
  120. // 首页推荐
  121. if ($template['type'] == 'indexRecommend') {
  122. // Todo 该模块数据有误,后期解决
  123. $template = $this->replaceIndexRecommend($template, $from_store_id, $to_store_id);
  124. }
  125. //秒杀
  126. if ($template['type'] == 'productSeckill') {
  127. $template = $this->replaceProductSeckill($template, $from_store_id, $to_store_id);
  128. }
  129. //上门服务
  130. if ($template['type'] == 'serviceHome') {
  131. $template = $this->replaceServiceHome($template, $from_store_id, $to_store_id);
  132. }
  133. //拼团
  134. if ($template['type'] == 'ptProductShow') {
  135. $template = $this->replacePtProductShow($template, $from_store_id, $to_store_id);
  136. }
  137. //预约
  138. if ($template['type'] == 'bookingHome') {
  139. $template = $this->replaceBookingHome($template, $from_store_id, $to_store_id);
  140. }
  141. return $template;
  142. }
  143. // 替换头部导航
  144. private function replaceFastNav($data, $from_store_id, $to_store_id)
  145. {
  146. if (!empty($data['params']['list'])) {
  147. foreach ($data['params']['list'] as &$item) {
  148. $item = $this->replaceLink($item, $from_store_id, $to_store_id);
  149. }
  150. }
  151. return $data;
  152. }
  153. // 替换图片轮播
  154. private function replaceBanner($data, $from_store_id, $to_store_id)
  155. {
  156. if (!empty($data['params']['bannerList'])) {
  157. foreach ($data['params']['bannerList'] as &$item) {
  158. $item = $this->replaceLink($item, $from_store_id, $to_store_id);
  159. }
  160. }
  161. return $data;
  162. }
  163. // 替换魔方导航
  164. private function replaceCubeNav($data, $from_store_id, $to_store_id)
  165. {
  166. if (!empty($data['params']['list'])) {
  167. foreach ($data['params']['list'] as &$item) {
  168. $item = $this->replaceLink($item, $from_store_id, $to_store_id);
  169. }
  170. }
  171. return $data;
  172. }
  173. // 替换魔方图片
  174. private function replaceContainer($data, $from_store_id, $to_store_id)
  175. {
  176. debug_log('——替换魔方图片','store_sync.log');
  177. if (!empty($data['params']['cubeCoverList'])) {
  178. debug_log('替换魔方图片——','store_sync.log');
  179. foreach ($data['params']['cubeCoverList'] as &$item) {
  180. $item = $this->replaceLink($item, $from_store_id, $to_store_id);
  181. }
  182. }
  183. return $data;
  184. }
  185. // 替换产品展示
  186. private function replaceProductShow($data, $from_store_id, $to_store_id)
  187. {
  188. if (isset($data['params']['classifyData'])) {
  189. //判断是否为当前商城同步过此商品
  190. $storeSyncExtLog = StoreSyncExtLog::findOne([
  191. 'from_store_id' => $from_store_id,
  192. 'to_store_id' => $to_store_id,
  193. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  194. 'from_id' => $data['params']['classifyData']
  195. ]);
  196. // 替换分类id
  197. if (isset($storeSyncExtLog->to_id)) {
  198. $data['params']['classifyData'] = $storeSyncExtLog->to_id;
  199. }
  200. }
  201. if (isset($data['params']['classifyArr'])) {
  202. foreach ($data['params']['classifyArr'] as &$item) {
  203. $storeSyncExtLog = StoreSyncExtLog::findOne([
  204. 'from_store_id' => $from_store_id,
  205. 'to_store_id' => $to_store_id,
  206. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  207. 'from_id' => $item['id']
  208. ]);
  209. // 替换分类id
  210. if (isset($storeSyncExtLog->to_id)) {
  211. $item['id'] = $storeSyncExtLog->to_id;
  212. }
  213. }
  214. }
  215. // 替换商品id
  216. if (isset($data['params']['selectData'])) {
  217. foreach ($data['params']['selectData'] as &$select_item) {
  218. //判断是否为当前商城同步过此商品
  219. $storeSyncExtLog = StoreSyncExtLog::findOne([
  220. 'from_store_id' => $from_store_id,
  221. 'to_store_id' => $to_store_id,
  222. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  223. 'from_id' => $select_item['id']
  224. ]);
  225. if (isset($storeSyncExtLog->to_id)) {
  226. $select_item['id'] = $storeSyncExtLog->to_id;
  227. }
  228. }
  229. }
  230. $data['params'] = $this->replaceLink($data['params'], $from_store_id, $to_store_id);
  231. return $data;
  232. }
  233. //
  234. public function replaceIndexRecommend($template, $from_store_id, $to_store_id) {
  235. try {
  236. foreach ($template['params']['list'] as &$item) {
  237. foreach ($item['pics']['link'] as &$link_item) {
  238. if (!isset($link_item['link'])) {
  239. continue;
  240. }
  241. // 处理分类id
  242. if (
  243. strpos($link_item['link'], '/pages/cat/cat?cat_id=') !== false &&
  244. $link_item['params'][0]['value'] != ''
  245. ) {
  246. //判断是否为当前商城同步过此商品
  247. $storeSyncExtLog = StoreSyncExtLog::findOne([
  248. 'from_store_id' => $from_store_id,
  249. 'to_store_id' => $to_store_id,
  250. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  251. 'from_id' => $link_item['params'][0]['value']
  252. ]);
  253. $cat_id = $link_item['params'][0]['value'];
  254. // 替换分类id
  255. if (isset($storeSyncExtLog->to_id)) {
  256. $cat_id = $storeSyncExtLog->to_id;
  257. }
  258. $link_item['link'] = '/pages/cat/cat?cat_id=' . $cat_id;
  259. $link_item['params'][0]['value'] = $cat_id;
  260. }
  261. // 处理商品列表
  262. if (
  263. strpos($link_item['link'], '/other/list/list?cat_id=') !== false &&
  264. $link_item['params'][0]['value'] != ''
  265. ) {
  266. //判断是否为当前商城同步过此商品
  267. $storeSyncExtLog = StoreSyncExtLog::findOne([
  268. 'from_store_id' => $from_store_id,
  269. 'to_store_id' => $to_store_id,
  270. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  271. 'from_id' => $link_item['params'][0]['value']
  272. ]);
  273. $cat_id = $link_item['params'][0]['value'];
  274. // 替换分类id
  275. if (isset($storeSyncExtLog->to_id)) {
  276. $cat_id = $storeSyncExtLog->to_id;
  277. }
  278. $link_item['link'] = '/other/list/list?cat_id=' . $cat_id;
  279. $link_item['params'][0]['value'] = $cat_id;
  280. }
  281. // 处理商品详情
  282. if (
  283. strpos($link_item['link'], '/goods/goods/goods?id=') !== false &&
  284. $link_item['params'][0]['value'] != ''
  285. ) {
  286. //判断是否为当前商城同步过此商品
  287. $storeSyncExtLog = StoreSyncExtLog::findOne([
  288. 'from_store_id' => $from_store_id,
  289. 'to_store_id' => $to_store_id,
  290. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  291. 'from_id' => $link_item['params'][0]['value']
  292. ]);
  293. $goods_id = $link_item['params'][0]['value'];
  294. // 替换分类id
  295. if (isset($storeSyncExtLog->to_id)) {
  296. $goods_id = $storeSyncExtLog->to_id;
  297. }
  298. $link_item['link'] = '/goods/goods/goods?id=' . $goods_id;
  299. $link_item['params'][0]['value'] = $goods_id;
  300. }
  301. if (
  302. strpos($link_item['link'], '/pages/diy/diy?id=') !== false
  303. ) {
  304. //判断是否为当前商城同步过此商品
  305. $storeSyncExtLog = StoreSyncExtLog::findOne([
  306. 'from_store_id' => $from_store_id,
  307. 'to_store_id' => $to_store_id,
  308. 'type' => StoreSyncExtLog::TYPE_DIY,
  309. 'from_id' => $link_item['id']
  310. ]);
  311. $diy_id = $link_item['id'];
  312. // 替换分类id
  313. if (isset($storeSyncExtLog->to_id)) {
  314. $diy_id = $storeSyncExtLog->to_id;
  315. }
  316. $link_item['link'] = '/pages/diy/diy?id=' . $diy_id;
  317. $link_item['id'] = $diy_id;
  318. }
  319. }
  320. }
  321. return $template;
  322. } catch (\Exception $e) {
  323. return $template;
  324. }
  325. }
  326. // 替换产品分类
  327. private function replaceProductClassify($data, $from_store_id, $to_store_id)
  328. {
  329. if (!empty($data['params']['classifyList'])) {
  330. $data['params']['classifyList'] = (array)$data['params']['classifyList'];
  331. foreach ($data['params']['classifyList'] as &$item) {
  332. // 替换分类
  333. if (isset($item['classifyId'])) {
  334. $storeSyncExtLog = StoreSyncExtLog::findOne([
  335. 'from_store_id' => $from_store_id,
  336. 'to_store_id' => $to_store_id,
  337. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  338. 'from_id' => $item['classifyId']
  339. ]);
  340. if (isset($storeSyncExtLog->to_id)) {
  341. $item['id'] = $storeSyncExtLog->to_id;
  342. $item['classifyId'] = $storeSyncExtLog->to_id;
  343. }
  344. }
  345. if (!empty($item['data'])) {
  346. // 替换商品id
  347. foreach ($item['data'] as &$value) {
  348. if (isset($value['id'])) {
  349. $storeSyncExtLog = StoreSyncExtLog::findOne([
  350. 'from_store_id' => $from_store_id,
  351. 'to_store_id' => $to_store_id,
  352. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  353. 'from_id' => $value['id']
  354. ]);
  355. if (isset($storeSyncExtLog->to_id)) {
  356. $value['id'] = $storeSyncExtLog->to_id;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. return $data;
  364. }
  365. //秒杀
  366. private function replaceProductSeckill($template, $from_store_id, $to_store_id) {
  367. if (isset($template['params']['activeId'])) {
  368. $storeSyncExtLog = StoreSyncExtLog::findOne([
  369. 'from_store_id' => $from_store_id,
  370. 'to_store_id' => $to_store_id,
  371. 'type' => StoreSyncExtLog::TYPE_SECKILL,
  372. 'from_id' => $template['params']['activeId']
  373. ]);
  374. if (isset($storeSyncExtLog->to_id)) {
  375. $template['params']['activeId'] = (string)$storeSyncExtLog->to_id;
  376. }
  377. }
  378. return $template;
  379. }
  380. //上门服务
  381. private function replaceServiceHome($template, $from_store_id, $to_store_id) {
  382. if (isset($template['params']['classifyData'])) {
  383. $storeSyncExtLog = StoreSyncExtLog::findOne([
  384. 'from_store_id' => $from_store_id,
  385. 'to_store_id' => $to_store_id,
  386. 'type' => StoreSyncExtLog::TYPE_WORKER_CONFIG_CAT,
  387. 'from_id' => $template['params']['classifyData']
  388. ]);
  389. if (isset($storeSyncExtLog->to_id)) {
  390. $template['params']['classifyData'] = $storeSyncExtLog->to_id;
  391. }
  392. }
  393. if (isset($template['params']['classifyArr'])) {
  394. foreach ($template['params']['classifyArr'] as &$worker_goods_item) {
  395. $storeSyncExtLog = StoreSyncExtLog::findOne([
  396. 'from_store_id' => $from_store_id,
  397. 'to_store_id' => $to_store_id,
  398. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  399. 'from_id' => $worker_goods_item['id']
  400. ]);
  401. if (isset($storeSyncExtLog->to_id)) {
  402. $worker_goods_item['id'] = $storeSyncExtLog->to_id;
  403. }
  404. }
  405. }
  406. return $template;
  407. }
  408. //拼团
  409. private function replacePtProductShow($template, $from_store_id, $to_store_id) {
  410. if (!empty($template['params'])) {
  411. if (isset($template['params']['classifyData'])) {
  412. $storeSyncExtLog = StoreSyncExtLog::findOne([
  413. 'from_store_id' => $from_store_id,
  414. 'to_store_id' => $to_store_id,
  415. 'type' => StoreSyncExtLog::TYPE_PT_GOODS_CAT,
  416. 'from_id' => $template['params']['classifyData']
  417. ]);
  418. if (isset($storeSyncExtLog->to_id)) {
  419. $template['params']['classifyData'] = $storeSyncExtLog->to_id;
  420. }
  421. }
  422. if (!empty($template['params']['classifyArr'])) {
  423. foreach ($template['params']['classifyArr'] as &$pt_classify_goods_item) {
  424. $storeSyncExtLog = StoreSyncExtLog::findOne([
  425. 'from_store_id' => $from_store_id,
  426. 'to_store_id' => $to_store_id,
  427. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  428. 'from_id' => $pt_classify_goods_item['id']
  429. ]);
  430. if (isset($storeSyncExtLog->to_id)) {
  431. $pt_classify_goods_item['id'] = $storeSyncExtLog->to_id;
  432. }
  433. }
  434. }
  435. if (!empty($template['params']['selectData'])) {
  436. foreach ($template['params']['selectData'] as &$pt_goods_item) {
  437. $storeSyncExtLog = StoreSyncExtLog::findOne([
  438. 'from_store_id' => $from_store_id,
  439. 'to_store_id' => $to_store_id,
  440. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  441. 'from_id' => $pt_goods_item['id']
  442. ]);
  443. if (isset($storeSyncExtLog->to_id)) {
  444. $pt_goods_item['id'] = $storeSyncExtLog->to_id;
  445. }
  446. }
  447. }
  448. }
  449. return $template;
  450. }
  451. //装修预约商品
  452. private function replaceBookingHome($template, $from_store_id, $to_store_id) {
  453. try {
  454. if (!empty($template['params'])) {
  455. if (isset($template['params']['classifyData'])) {
  456. $storeSyncExtLog = StoreSyncExtLog::findOne([
  457. 'from_store_id' => $from_store_id,
  458. 'to_store_id' => $to_store_id,
  459. 'type' => StoreSyncExtLog::TYPE_BOOKING_GOODS_CAT,
  460. 'from_id' => $template['params']['classifyData']
  461. ]);
  462. if (isset($storeSyncExtLog->to_id)) {
  463. $template['params']['classifyData'] = $storeSyncExtLog->to_id;
  464. }
  465. }
  466. if (!empty($template['params']['selectData'])) {
  467. foreach ($template['params']['selectData'] as &$booking_goods_item) {
  468. $storeSyncExtLog = StoreSyncExtLog::findOne([
  469. 'from_store_id' => $from_store_id,
  470. 'to_store_id' => $to_store_id,
  471. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  472. 'from_id' => $booking_goods_item['id']
  473. ]);
  474. if (isset($storeSyncExtLog->to_id)) {
  475. $booking_goods_item['id'] = $storeSyncExtLog->to_id;
  476. }
  477. }
  478. }
  479. }
  480. return $template;
  481. } catch (\Exception $e) {
  482. return $template;
  483. }
  484. }
  485. // 替换倒计时
  486. private function replaceMarketCountDown($data, $from_store_id, $to_store_id)
  487. {
  488. $data['params'] = $this->replaceLink($data['params'], $from_store_id, $to_store_id);
  489. return $data;
  490. }
  491. // 替换图片链接
  492. private function replaceImages($data, $from_store_id, $to_store_id)
  493. {
  494. if (isset($data['params']['current'])) {
  495. $data['params']['current'] = $this->replaceLink($data['params']['current'], $from_store_id, $to_store_id);
  496. } else {
  497. if (isset($data['params'])) {
  498. $data['params'] = $this->replaceLink($data['params'], $from_store_id, $to_store_id);
  499. }
  500. }
  501. return $data;
  502. }
  503. private function replaceLink($item, $from_store_id, $to_store_id)
  504. {
  505. try {
  506. if (!isset($item['link']['link'])) {
  507. return $item;
  508. }
  509. if (isset($item['link']['params'][0]['value'])) {
  510. //判断是否为当前商城同步过此商品
  511. $storeSyncExtLog = StoreSyncExtLog::findOne([
  512. 'from_store_id' => $from_store_id,
  513. 'to_store_id' => $to_store_id,
  514. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  515. 'from_id' => $item['link']['params'][0]['value']
  516. ]);
  517. // 处理分类id
  518. if (
  519. str_contains($item['link']['link'], '/pages/cat/cat?cat_id=') &&
  520. $item['link']['params'][0]['value'] != '' &&
  521. isset($storeSyncExtLog->to_id)
  522. ) {
  523. $item['link']['link'] = '/pages/cat/cat?cat_id=' . $storeSyncExtLog->to_id;
  524. $item['link']['params'][0]['value'] = $storeSyncExtLog->to_id;
  525. }
  526. }
  527. // 处理商品列表
  528. if (strpos($item['link']['link'], '/other/list/list?cat_id=') !== false) {
  529. }
  530. if (isset($item['link']['params'][0]['value'])) {
  531. //判断是否为当前商城同步过此商品
  532. $storeSyncExtLog = StoreSyncExtLog::findOne([
  533. 'from_store_id' => $from_store_id,
  534. 'to_store_id' => $to_store_id,
  535. 'type' => StoreSyncExtLog::TYPE_PRODUCT_CAT,
  536. 'from_id' => $item['link']['params'][0]['value']
  537. ]);
  538. if (
  539. str_contains($item['link']['link'], '/other/list/list?cat_id=') &&
  540. $item['link']['params'][0]['value'] != '' &&
  541. isset($storeSyncExtLog->to_id)
  542. ) {
  543. $item['link']['link'] = '/other/list/list?cat_id=' . $storeSyncExtLog->to_id;
  544. $item['link']['params'][0]['value'] = $storeSyncExtLog->to_id;
  545. }
  546. }
  547. if (isset($item['link']['params'][0]['value'])) {
  548. //判断是否为当前商城同步过此商品
  549. $storeSyncExtLog = StoreSyncExtLog::findOne([
  550. 'from_store_id' => $from_store_id,
  551. 'to_store_id' => $to_store_id,
  552. 'type' => StoreSyncExtLog::TYPE_PRODUCT,
  553. 'from_id' => $item['link']['params'][0]['value']
  554. ]);
  555. // 处理商品详情
  556. if (
  557. str_contains($item['link']['link'], '/goods/goods/goods?id=') &&
  558. $item['link']['params'][0]['value'] != '' &&
  559. isset($storeSyncExtLog->to_id)
  560. ) {
  561. $item['link']['link'] = '/goods/goods/goods?id=' . $storeSyncExtLog->to_id;
  562. $item['link']['params'][0]['value'] = $storeSyncExtLog->to_id;
  563. }
  564. }
  565. if (isset($item['link']['id'])) {
  566. //判断是否为当前商城同步过此商品
  567. $storeSyncExtLog = StoreSyncExtLog::findOne([
  568. 'from_store_id' => $from_store_id,
  569. 'to_store_id' => $to_store_id,
  570. 'type' => StoreSyncExtLog::TYPE_DIY,
  571. 'from_id' => $item['link']['id']
  572. ]);
  573. if (
  574. str_contains($item['link']['link'], '/pages/diy/diy?id=') &&
  575. isset($storeSyncExtLog->to_id)
  576. ) {
  577. $item['link']['link'] = '/pages/diy/diy?id=' . $storeSyncExtLog->to_id;
  578. $item['link']['id'] = $storeSyncExtLog->to_id;
  579. }
  580. }
  581. } catch (\Exception $e) {
  582. debug_log([$e->getMessage()], 'syncDiy.log');
  583. }
  584. return $item;
  585. }
  586. /** 同步DIY end */
  587. }