GoodsGatherLogic.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\goods;
  20. use app\common\enum\GoodsEnum;
  21. use app\common\enum\YesNoEnum;
  22. use app\common\logic\BaseLogic;
  23. use app\common\model\GoodsGather;
  24. use app\common\model\GoodsGatherGoods;
  25. use app\common\model\GoodsGatherLog;
  26. use app\common\service\ConfigService;
  27. use app\common\service\FileService;
  28. use think\facade\Db;
  29. class GoodsGatherLogic extends BaseLogic
  30. {
  31. /**
  32. * @notes 采集
  33. * @param $params
  34. * @return bool|string
  35. * @author ljj
  36. * @date 2023/3/13 6:35 下午
  37. */
  38. public function gather($params)
  39. {
  40. set_time_limit(600);
  41. Db::startTrans();
  42. try {
  43. $apikey = ConfigService::get('goods_gather', 'key_99api', '');
  44. //添加采集记录
  45. $gather_log = GoodsGatherLog::create([
  46. 'goods_type' => $params['goods_type'],
  47. 'goods_category' => $params['goods_category'],
  48. 'delivery_content' => $params['delivery_content'] ?? '',
  49. ]);
  50. $gather_goods_data = [];
  51. foreach ($params['gather_url'] as $url) {
  52. //分解采集连接
  53. $url_arr = parse_url($url);
  54. if (!isset($url_arr['host'])) {
  55. $gather_data[] = [
  56. 'log_id' => $gather_log->id,
  57. 'gather_url' => $url,
  58. 'gather_status' => YesNoEnum::NO,
  59. ];
  60. continue;
  61. }
  62. //判断域名归属
  63. $url_host_arr = explode('.',$url_arr['host']);
  64. if (in_array('taobao',$url_host_arr)) { //淘宝
  65. //分解请求参数
  66. parse_str($url_arr['query'],$url_query_arr);
  67. if (isset($url_query_arr['id'])) {
  68. $query_url = 'https://api09.99api.com/taobao/detail?apikey='.$apikey.'&itemid='.$url_query_arr['id'];
  69. $result = \Requests::post($query_url, [], [], [ 'timeout' => 600 ]);
  70. $result = json_decode($result->body,true);
  71. if ($result['retcode'] == 4016) {
  72. throw new \think\Exception('余额不足', 10006);
  73. }
  74. } else {
  75. $result = '';
  76. }
  77. $channel = 1;
  78. $gather_status = (isset($result['retcode']) && $result['retcode'] == '0000') ? 1 : 0;
  79. } elseif (in_array('tmall',$url_host_arr)) { //天猫
  80. //分解请求参数
  81. parse_str($url_arr['query'],$url_query_arr);
  82. if (isset($url_query_arr['id'])) {
  83. $query_url = 'https://api09.99api.com/tmall/detail?apikey='.$apikey.'&itemid='.$url_query_arr['id'];
  84. $result = \Requests::post($query_url, [], [], [ 'timeout' => 600 ]);
  85. $result = json_decode($result->body,true);
  86. if ($result['retcode'] == 4016) {
  87. throw new \think\Exception('余额不足', 10006);
  88. }
  89. } else {
  90. $result = '';
  91. }
  92. $channel = 2;
  93. $gather_status = (isset($result['retcode']) && $result['retcode'] == '0000') ? 1 : 0;
  94. } elseif (in_array('jd',$url_host_arr)) { //京东
  95. //分解请求参数
  96. $url_query_arr = pathinfo($url);
  97. if (isset($url_query_arr['filename'])) {
  98. $query_url = 'https://api09.99api.com/jd/detail?apikey='.$apikey.'&itemid='.$url_query_arr['filename'];
  99. $result = \Requests::post($query_url, [], [], [ 'timeout' => 600 ]);
  100. $result = json_decode($result->body,true);
  101. if ($result['retcode'] == 4016) {
  102. throw new \think\Exception('余额不足', 10006);
  103. }
  104. } else {
  105. $result = '';
  106. }
  107. $channel = 3;
  108. $gather_status = (isset($result['retcode']) && $result['retcode'] == '0000') ? 1 : 0;
  109. } elseif (in_array('1688',$url_host_arr)) { //1688
  110. //分解请求参数
  111. $url_query_arr = pathinfo($url);
  112. $url_query_arr = explode('?',$url_query_arr['filename']);
  113. $url_query_arr = explode('.',$url_query_arr[0]);
  114. if (isset($url_query_arr[0])) {
  115. $query_url = 'https://api09.99api.com/alibaba/detail?apikey='.$apikey.'&itemid='.$url_query_arr[0];
  116. $result = \Requests::post($query_url, [], [], [ 'timeout' => 600 ]);
  117. $result = json_decode($result->body,true);
  118. if ($result['retcode'] == 4016) {
  119. throw new \think\Exception('余额不足', 10006);
  120. }
  121. } else {
  122. $result = '';
  123. }
  124. $channel = 4;
  125. $gather_status = (isset($result['retcode']) && $result['retcode'] == '0000') ? 1 : 0;
  126. } else {
  127. $result = '';
  128. $gather_status = 0;
  129. $channel = 0;
  130. }
  131. $gather = GoodsGather::create([
  132. 'log_id' => $gather_log->id,
  133. 'gather_url' => $url,
  134. 'gather_info' => $result,
  135. 'gather_status' => $gather_status,
  136. 'channel' => $channel,
  137. ]);
  138. if ($gather_status == 1) {
  139. $gather_goods_data[] = $this->makeGoods($gather_log,$gather);
  140. }
  141. }
  142. (new GoodsGatherGoods())->saveAll($gather_goods_data);
  143. // 提交事务
  144. Db::commit();
  145. return true;
  146. } catch (\Exception $e) {
  147. // 回滚事务
  148. Db::rollback();
  149. return '采集失败:' . $e->getMessage() . ' 请稍后再试';
  150. }
  151. }
  152. /**
  153. * @notes 处理商品数据
  154. * @param $gather_log
  155. * @param $gather
  156. * @return array
  157. * @author ljj
  158. * @date 2023/3/16 10:09 上午
  159. */
  160. public function makeGoods($gather_log,$gather)
  161. {
  162. $goods_data['gather_id'] = $gather['id'];
  163. $goods_data['type'] = $gather_log['goods_type'];
  164. $goods_data['code'] = create_code();
  165. $goods_data['category_id'][] = $gather_log['goods_category'];
  166. $goods_data['delivery_content'] = $gather_log['delivery_content'];
  167. switch ($gather['channel']) {
  168. case GoodsEnum::GATHER_CHANNEL_TMALL:
  169. case GoodsEnum::GATHER_CHANNEL_TAOBAO:
  170. $goods_data['name'] = $gather['gather_info']['data']['item']['title'];
  171. $goods_data['content'] = $gather['gather_info']['data']['item']['desc'];
  172. //处理轮播图
  173. $goods_image = $gather['gather_info']['data']['item']['images'];
  174. foreach ($goods_image as $key=>$image_val) {
  175. $goods_image[$key] = checkHttp($image_val);
  176. }
  177. //处理商品规格
  178. $spec_type = 1;
  179. $sku = $gather['gather_info']['data']['item']['sku'];
  180. $props = $gather['gather_info']['data']['item']['props'];
  181. if (count($sku) > 1) {
  182. unset($sku[0]);
  183. $sku = array_values($sku);
  184. $spec_type = 2;
  185. }
  186. if ($spec_type == 1) {
  187. $spec_value = '';
  188. $spec_value_list[] = [
  189. 'image' => '',
  190. 'sell_price' => $sku[0]['price'],
  191. 'lineation_price' => '',
  192. 'cost_price' => '',
  193. 'stock' => $sku[0]['quantity'],
  194. 'volume' => '',
  195. 'weight' => '',
  196. 'bar_code' => '',
  197. ];
  198. } else {
  199. //多规格
  200. //处理规格项数据
  201. foreach ($props as $props_val) {
  202. $has_image = '';
  203. $spec_list = [];
  204. foreach ($props_val['values'] as $val) {
  205. if (isset($val['image'])) {
  206. $has_image = 1;
  207. }
  208. $spec_list[] = [
  209. 'vid' => $val['vid'],
  210. 'value' => $val['name'],
  211. 'image' => $val['image'] ?? '',
  212. ];
  213. }
  214. $spec_value[] = [
  215. 'pid' => $props_val['pid'],
  216. 'has_image' => $has_image,
  217. 'name' => $props_val['name'],
  218. 'spec_list' => $spec_list,
  219. ];
  220. }
  221. //处理规格项信息数据
  222. foreach ($sku as $sku_val) {
  223. $prop_path_arr = explode(';',$sku_val['propPath']);
  224. foreach ($prop_path_arr as $key=>$val) {
  225. $prop_path_arr[$key] = explode(':',$val);
  226. }
  227. $spec_value_list[] = [
  228. 'ids' => "",
  229. 'prop_path' => $prop_path_arr,
  230. 'value' => [],
  231. 'spec_value_str' => [],
  232. 'image' => $sku_val['image'] ?? '',
  233. 'sell_price' => $sku_val['price'],
  234. 'lineation_price' => '',
  235. 'cost_price' => '',
  236. 'stock' => $sku_val['quantity'],
  237. 'volume' => '',
  238. 'weight' => '',
  239. 'bar_code' => '',
  240. ];
  241. }
  242. $spec_list = array_column($spec_value,null,'pid');
  243. foreach ($spec_value_list as $key=>$val) {
  244. $ids = [];
  245. $value = [];
  246. foreach ($val['prop_path'] as $path_val) {
  247. $spec_list_arr = $spec_list[$path_val[0]];
  248. foreach ($spec_list_arr['spec_list'] as $spec_list_key=>$spec_list_val) {
  249. if ($spec_list_val['vid'] == $path_val[1]) {
  250. $ids[] = $spec_list_key;
  251. $value[] = $spec_list_val['value'];
  252. }
  253. }
  254. }
  255. $spec_value_list[$key]['ids'] = implode(',',$ids);
  256. $spec_value_list[$key]['value'] = $value;
  257. $spec_value_list[$key]['spec_value_str'] = implode(',',$value);
  258. }
  259. }
  260. break;
  261. case GoodsEnum::GATHER_CHANNEL_JD:
  262. $goods_data['name'] = $gather['gather_info']['data']['item']['name'];
  263. $goods_data['content'] = $gather['gather_info']['data']['item']['desc'];
  264. //处理轮播图
  265. $goods_image = $gather['gather_info']['data']['item']['images'];
  266. foreach ($goods_image as $key=>$image_val) {
  267. $goods_image[$key] = checkHttp($image_val);
  268. }
  269. //处理商品规格
  270. $spec_type = 1;
  271. $sku = $gather['gather_info']['data']['item']['sku'];
  272. $sale_prop = $gather['gather_info']['data']['item']['saleProp'];
  273. $sku_prop = $gather['gather_info']['data']['item']['skuProps'];
  274. if (count($sku) > 1) {
  275. $spec_type = 2;
  276. }
  277. if ($spec_type == 1) {
  278. $spec_value = '';
  279. $spec_value_list[] = [
  280. 'image' => '',
  281. 'sell_price' => $sku[0]['price'] ?? $gather['gather_info']['data']['item']['price'] ?? 0,
  282. 'lineation_price' => '',
  283. 'cost_price' => '',
  284. 'stock' => $sku[0]['stockState'] ?? 0,
  285. 'volume' => '',
  286. 'weight' => '',
  287. 'bar_code' => '',
  288. ];
  289. } else {
  290. //多规格
  291. //处理规格项数据
  292. $spec_value = [];
  293. foreach ($sale_prop as $sale_prop_key=>$sale_prop_val) {
  294. $spec_list = [];
  295. if (empty($sale_prop_val)) {
  296. break;
  297. }
  298. foreach ($sku_prop[$sale_prop_key] as $sku_prop_val_key=>$sku_prop_val) {
  299. if (empty($sku_prop_val)) {
  300. continue;
  301. }
  302. $spec_list[] = [
  303. 'key' => $sale_prop_key,
  304. 'value' => $sku_prop_val,
  305. 'image' => '',
  306. ];
  307. }
  308. if (empty($spec_list)) {
  309. continue;
  310. }
  311. $spec_value[] = [
  312. 'has_image' => '',
  313. 'name' => $sale_prop_val,
  314. 'spec_list' => $spec_list,
  315. ];
  316. }
  317. //处理规格项信息数据
  318. $spec_list = array_column($spec_value,'spec_list');
  319. foreach ($sku as $sku_val) {
  320. $ids = [];
  321. $value = [];
  322. foreach ($spec_list as $spec_list_val) {
  323. foreach ($spec_list_val as $spec_list_val_key=>$spec_list_val_val) {
  324. if ($spec_list_val_val['value'] == $sku_val[$spec_list_val_val['key']]) {
  325. $ids[] = $spec_list_val_key;
  326. $value[] = $spec_list_val_val['value'];
  327. }
  328. }
  329. }
  330. $spec_value_list[] = [
  331. 'ids' => implode(',',$ids),
  332. 'value' => $value,
  333. 'spec_value_str' => implode(',',$value),
  334. 'image' => '',
  335. 'sell_price' => $sku_val['price'] ?? 0,
  336. 'lineation_price' => '',
  337. 'cost_price' => '',
  338. 'stock' => $sku_val['stockState'] ?? 0,
  339. 'volume' => '',
  340. 'weight' => '',
  341. 'bar_code' => '',
  342. ];
  343. }
  344. }
  345. break;
  346. case GoodsEnum::GATHER_CHANNEL_1688:
  347. $goods_data['name'] = $gather['gather_info']['data']['title'];
  348. $goods_data['content'] = $gather['gather_info']['data']['desc'];
  349. //处理轮播图
  350. $goods_image = $gather['gather_info']['data']['images'];
  351. foreach ($goods_image as $key=>$image_val) {
  352. $goods_image[$key] = checkHttp($image_val);
  353. }
  354. //处理商品规格
  355. $spec_type = 1;
  356. $sku = $gather['gather_info']['data']['skuMap'];
  357. $props = $gather['gather_info']['data']['skuProps'];
  358. if (count($sku) > 1) {
  359. $spec_type = 2;
  360. }
  361. if ($spec_type == 1) {
  362. $spec_value = '';
  363. $sku = array_values($sku);
  364. $spec_value_list[] = [
  365. 'image' => '',
  366. 'sell_price' => $sku[0]['discountPrice'] ?? 0,
  367. 'lineation_price' => '',
  368. 'cost_price' => '',
  369. 'stock' => $sku[0]['canBookCount'],
  370. 'volume' => '',
  371. 'weight' => '',
  372. 'bar_code' => '',
  373. ];
  374. } else {
  375. //多规格
  376. //处理规格项数据
  377. foreach ($props as $props_val) {
  378. $has_image = '';
  379. $spec_list = [];
  380. foreach ($props_val['value'] as $val) {
  381. if (isset($val['imageUrl']) && $val['imageUrl'] != '') {
  382. $has_image = 1;
  383. }
  384. $spec_list[] = [
  385. 'value' => $val['name'],
  386. 'image' => $val['imageUrl'] ?? '',
  387. ];
  388. }
  389. $spec_value[] = [
  390. 'has_image' => $has_image,
  391. 'name' => $props_val['prop'],
  392. 'spec_list' => $spec_list,
  393. ];
  394. }
  395. //处理规格项信息数据
  396. foreach ($sku as $sku_val) {
  397. $spec_attrs = explode('&gt;',$sku_val['specAttrs']);
  398. $spec_value_list[] = [
  399. 'ids' => "",
  400. 'spec_attrs' => $spec_attrs,
  401. 'value' => [],
  402. 'spec_value_str' => [],
  403. 'image' => '',
  404. 'sell_price' => $sku_val['discountPrice'] ?? 0,
  405. 'lineation_price' => '',
  406. 'cost_price' => '',
  407. 'stock' => $sku_val['canBookCount'],
  408. 'volume' => '',
  409. 'weight' => '',
  410. 'bar_code' => '',
  411. ];
  412. }
  413. $spec_list = array_column($spec_value,'spec_list');
  414. foreach ($spec_value_list as $key=>$val) {
  415. $ids = [];
  416. $value = [];
  417. foreach ($val['spec_attrs'] as $spec_attrs_key=>$spec_attrs_val) {
  418. $spec_list_arr = $spec_list[$spec_attrs_key];
  419. foreach ($spec_list_arr as $spec_list_key=>$spec_list_val) {
  420. if ($spec_list_val['value'] == $spec_attrs_val) {
  421. $ids[] = $spec_list_key;
  422. $value[] = $spec_list_val['value'];
  423. }
  424. }
  425. }
  426. $spec_value_list[$key]['ids'] = implode(',',$ids);
  427. $spec_value_list[$key]['value'] = $value;
  428. $spec_value_list[$key]['spec_value_str'] = implode(',',$value);
  429. }
  430. }
  431. break;
  432. }
  433. $goods_data['goods_image'] = $goods_image;
  434. $goods_data['spec_type'] = $spec_type;
  435. $goods_data['spec_value'] = $spec_value;
  436. $goods_data['spec_value_list'] = $spec_value_list;
  437. return $goods_data;
  438. }
  439. /**
  440. * @notes 删除采集记录
  441. * @param $params
  442. * @return bool
  443. * @author ljj
  444. * @date 2023/3/14 9:41 上午
  445. */
  446. public function del($params)
  447. {
  448. GoodsGatherLog::destroy($params['log_id']);
  449. return true;
  450. }
  451. /**
  452. * @notes 采集商品详情
  453. * @param $params
  454. * @return array
  455. * @author ljj
  456. * @date 2023/3/16 10:56 上午
  457. */
  458. public function gatherGoodsDetail($params)
  459. {
  460. $result = GoodsGatherGoods::where(['gather_id'=>$params['id']])->findOrEmpty()->toArray();
  461. return $result;
  462. }
  463. /**
  464. * @notes 编辑采集商品
  465. * @param $params
  466. * @return bool
  467. * @author ljj
  468. * @date 2023/3/16 11:38 上午
  469. */
  470. public function gatherGoodsEdit($params)
  471. {
  472. GoodsGatherGoods::update([
  473. 'type' => $params['type'],
  474. 'code' => $params['code'],
  475. 'name' => $params['name'],
  476. 'category_id' => $params['category_id'],
  477. 'goods_image' => $params['goods_image'],
  478. 'video_source' => $params['video_source'],
  479. 'video_cover' => $params['video_cover'],
  480. 'video' => $params['video'],
  481. 'brand_id' => $params['brand_id'],
  482. 'unit_id' => $params['unit_id'],
  483. 'supplier_id' => $params['supplier_id'],
  484. 'poster' => $params['poster'] ?? '',
  485. 'is_express' => $params['is_express'],
  486. 'is_selffetch' => $params['is_selffetch'],
  487. 'express_type' => $params['express_type'],
  488. 'express_money' => $params['express_money'],
  489. 'express_template_id' => $params['express_template_id'],
  490. 'is_virtualdelivery' => $params['is_virtualdelivery'] ?? 1,
  491. 'after_pay' => $params['after_pay'] ?? 1,
  492. 'after_delivery' => $params['after_delivery'] ?? 1,
  493. 'delivery_content' => $params['delivery_content'] ?? '',
  494. 'content' => $params['content'] ?? '',
  495. 'stock_warning' => $params['stock_warning'],
  496. 'virtual_sales_num' => $params['virtual_sales_num'],
  497. 'virtual_click_num' => $params['virtual_click_num'],
  498. 'spec_type' => $params['spec_type'],
  499. 'spec_value' => $params['spec_value'],
  500. 'spec_value_list' => $params['spec_value_list'],
  501. 'is_address' => $params['is_address'] ?? 0,
  502. 'limit_type' => $params['limit_type'],
  503. 'limit_value' => $params['limit_value'],
  504. ],['gather_id'=>$params['gather_id']]);
  505. return true;
  506. }
  507. /**
  508. * @notes 创建商品
  509. * @param $params
  510. * @return bool|string
  511. * @author ljj
  512. * @date 2023/3/16 12:09 下午
  513. */
  514. public function createGoods($params)
  515. {
  516. Db::startTrans();
  517. try {
  518. foreach ($params['ids'] as $id) {
  519. $gather_goods = GoodsGatherGoods::where(['gather_id'=>$id])->withoutField('id,gather_id,goods_id,create_time,update_time,delete_time')->findOrEmpty()->toArray();
  520. $gather_goods['status'] = $params['status'];
  521. //处理轮播图
  522. foreach ($gather_goods['goods_image'] as $key=>$val) {
  523. $val = checkHttp($val);
  524. $file = saveImageToLocal(md5($val).'.jpg',$val);
  525. if (!empty($file)) {
  526. $gather_goods['goods_image'][$key] = $file['uri'];
  527. } else {
  528. unset($gather_goods['goods_image'][$key]);
  529. }
  530. }
  531. $gather_goods['goods_image'] = array_values($gather_goods['goods_image']);
  532. //处理详情图片
  533. $content = getContentImage($gather_goods['content']);
  534. if (isset($content[1]) && is_array($content[1])) {
  535. foreach ($content[1] as $key=>$val) {
  536. $val = checkHttp($val);
  537. $file = saveImageToLocal(md5($val).'.jpg',$val);
  538. $img = (isset($file['uri']) && !empty($file['uri'])) ? FileService::getFileUrl($file['uri']) : '';
  539. $gather_goods['content'] = str_replace($content[1][$key],$img,$gather_goods['content']);
  540. }
  541. }
  542. //处理规格项图片
  543. if ($gather_goods['spec_value']) {
  544. foreach ($gather_goods['spec_value'] as $key=>$val) {
  545. foreach ($val['spec_list'] as $key_son=>$val_son) {
  546. if (empty($val_son['image'])) {
  547. continue;
  548. }
  549. $val_son['image'] = checkHttp($val_son['image']);
  550. $file = saveImageToLocal(md5($val_son['image']).'.jpg',$val_son['image']);
  551. $gather_goods['spec_value'][$key]['spec_list'][$key_son]['image'] = $file['uri'] ?? '';
  552. }
  553. }
  554. }
  555. //处理规格项信息图片
  556. foreach ($gather_goods['spec_value_list'] as $key=>$val) {
  557. if (empty($val['image'])) {
  558. continue;
  559. }
  560. $val['image'] = checkHttp($val['image']);
  561. $file = saveImageToLocal(md5($val['image']).'.jpg',$val['image']);
  562. $gather_goods['spec_value_list'][$key]['image'] = $file['uri'] ?? '';
  563. }
  564. //添加商品
  565. if (GoodsEnum::SEPC_TYPE_MORE == $gather_goods['spec_type']) {
  566. $gather_goods['server_spec_value_list'] = cartesian_product(array_converting(array_column($gather_goods['spec_value'],'spec_list')));
  567. $spec_value_list = array_column($gather_goods['spec_value_list'], null, 'ids');
  568. foreach ($gather_goods['server_spec_value_list'] as $serverKey=>$serverValue) {
  569. if (!isset($spec_value_list[$serverValue['ids']])) {
  570. unset($gather_goods['server_spec_value_list'][$serverKey]);
  571. }
  572. }
  573. }
  574. $goods = (new GoodsLogic)->setBase($gather_goods);
  575. (new GoodsLogic)->addGoodsItem($goods,$gather_goods);
  576. //更新商品采集商品信息表
  577. GoodsGatherGoods::update(['goods_id'=>$goods->id],['gather_id'=>$id]);
  578. //更新商品采集表
  579. GoodsGather::update(['status'=>1],['id'=>$id]);
  580. }
  581. // 提交事务
  582. Db::commit();
  583. return true;
  584. } catch (\Exception $e) {
  585. // 回滚事务
  586. Db::rollback();
  587. return $e->getMessage();
  588. }
  589. }
  590. }