OrderImport.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\OrderImportFromC as OIFCModel;
  4. use think\Exception;
  5. use think\facade\Cache;
  6. use think\facade\Config;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //平台订单导入及处理类
  10. class OrderImport extends Base
  11. {
  12. //订单导入
  13. public function import()
  14. {
  15. $param = $this->request->only(['token', 'list'], 'post', 'trim');
  16. $val_params = Validate::rule(['token' => 'require', 'list' => 'require|array']);
  17. if (!$val_params->check($param)) throw new Exception($val_params->getError());
  18. Db::startTrans();
  19. try {
  20. //平台订单号不允许重复
  21. //平台订单号允许重复,但是平台订单号和平台商品编号的组合不能重复(2022-05-25 10)
  22. // $all_platform_codes = array_column($param['list'], 'platform_code');
  23. //
  24. // $temp = Db::name('order_import_from_c')
  25. // ->field('id,platform_code')
  26. // ->whereIn('platform_code', $all_platform_codes)
  27. // ->find();
  28. //
  29. // if (!empty($temp)) throw new Exception('平台订单号' . $temp['platform_code'] . '重复');
  30. $userinfo = GetUserInfo($param['token']);
  31. $createrid = isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0;
  32. $creater = isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : "";
  33. $insert_data = [];
  34. foreach ($param['list'] as $key => $value) {
  35. $value['createrid'] = $createrid;
  36. $value['creater'] = $creater;
  37. $value['addtime'] = $value['updatetime'] = date('Y-m-d H:i:s');
  38. $insert_data[] = $value;
  39. }
  40. $res = Db::name('order_import_from_c')
  41. ->limit(100)
  42. ->insertAll($insert_data);
  43. if ($res) {
  44. Db::commit();
  45. return app_show(0, "导入成功,共" . (string)$res . '条记录');
  46. } else {
  47. Db::rollback();
  48. return error_show(1005, '导入失败');
  49. }
  50. } catch (Exception $exception) {
  51. Db::rollback();
  52. return error_show(1005, $exception->getMessage());
  53. }
  54. }
  55. //查看订单录入列表
  56. public function getImportList()
  57. {
  58. $param = $this->request->only([
  59. 'status' => 0,
  60. 'platform_code' => '',
  61. 'platform_id' => '',
  62. 'po_code' => '',
  63. 'platform_time_start' => '',
  64. 'platform_time_end' => '',
  65. 'addtime_start' => '',
  66. 'addtime_end' => '',
  67. 'plat_code' => '',
  68. 'orderCode' => '',
  69. 'page' => 1,
  70. 'size' => 15,
  71. 'company_name' => '',
  72. 'relaComNo' => '',
  73. ], 'post', 'trim');
  74. $where = [['c.is_del', '=', OIFCModel::$is_del_normal]];
  75. if ($param['status']) $where[] = ['c.status', '=', $param['status']];
  76. if ($param['platform_code']) $where[] = ['c.platform_code', 'like', '%' . $param['platform_code'] . '%'];
  77. if ($param['platform_id']) $where[] = ['c.platform_id', '=', $param['platform_id']];
  78. if ($param['po_code']) $where[] = ['c.po_code', 'like', '%' . $param['po_code'] . '%'];
  79. if ($param['platform_time_start'] && $param['platform_time_end']) $where[] = ['c.platform_time', 'between', [$param['platform_time_start'], $param['platform_time_end']]];
  80. if ($param['addtime_start'] && $param['addtime_end']) $where[] = ['c.addtime', 'between', [$param['addtime_start'], $param['addtime_end']]];
  81. if ($param['plat_code']) $where[] = ['c.plat_code', 'like', '%' . $param['plat_code'] . '%'];
  82. if ($param['orderCode']) $where[] = ['c.orderCode', 'like', '%' . $param['orderCode'] . '%'];
  83. if ($param['company_name']) $where[] = ['c.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
  84. $total = OIFCModel::alias('c')
  85. ->leftJoin('good_platform gp', 'gp.plat_code=c.plat_code AND gp.platform_code=c.platform_id AND gp.is_del=0 AND gp.exam_status=3')
  86. ->leftJoin('good g', 'g.spuCode=gp.spuCode AND g.is_del=0')
  87. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  88. ->where($where)
  89. ->count('c.id');
  90. $list = OIFCModel::alias('c')
  91. ->field('c.*,g.good_name,p.platform_name platform_title')
  92. ->leftJoin('good_platform gp', 'gp.plat_code=c.plat_code AND gp.platform_code=c.platform_id AND gp.is_del=0 AND gp.exam_status=3')
  93. ->leftJoin('good g', 'g.spuCode=gp.spuCode AND g.is_del=0')
  94. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  95. ->where($where)
  96. ->page($param['page'], $param['size'])
  97. ->order('id', 'desc')
  98. ->select()
  99. ->toArray();
  100. $all_createrid = array_column($list,'createrid');
  101. $item = get_company_name_by_uid($all_createrid);
  102. foreach ($list as &$value){
  103. $value['company_name']=$item[$value['createrid']]??'';
  104. }
  105. return app_show(0, "获取成功", ['list' => $list, 'count' => $total]);
  106. }
  107. //查看订单录入详情
  108. public function getImportInfo()
  109. {
  110. $id = $this->request->post('id/d', 0, 'trim');
  111. $info = OIFCModel::where('id', $id)
  112. ->withoutField('discount_price,after_price')
  113. ->where('status', '<>', OIFCModel::$status_wait_validate)
  114. ->findOrEmpty()
  115. ->toArray();
  116. if (empty($info)) return error_show(1005, '系统尚未解析完成,无法查看详情,请等待');
  117. $res = [
  118. 'id' => $info['id'],
  119. 'status' => $info['status'],
  120. 'createrid' => $info['createrid'],
  121. 'creater' => $info['creater'],
  122. 'updateid' => $info['updateid'],
  123. 'updater' => $info['updater'],
  124. 'orderCode' => $info['orderCode'],
  125. 'success_date' => $info['status'] == OIFCModel::$status_success ? $info['updatetime'] : '',//录入成功时间
  126. 'addtime' => $info['addtime'],
  127. 'error_msg' => $info['remark'],//错误原因
  128. 'platform_id' => $info['platform_id'],
  129. 'platform_title' => Db::name('platform')->where(['id' => $info['platform_id'], 'is_del' => 0])->value('platform_name', ''),
  130. ];
  131. //导入原始数据
  132. $res['import'] = $info;
  133. //解析数据
  134. $res['confirm'] = Db::name('order_import_from_c_extend')
  135. ->where(['order_import_from_c_id' => $id, 'type' => 1])
  136. ->findOrEmpty();
  137. if ($res['confirm']['addr_code']) {
  138. $addr_code = explode(',', $res['confirm']['addr_code']);
  139. $res['confirm']['addr_name'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]]));
  140. } else $res['confirm']['addr_name'] = '';
  141. //用户确认数据
  142. $res['user_update'] = Db::name('order_import_from_c_extend')
  143. ->where(['order_import_from_c_id' => $id, 'type' => 2])
  144. ->find();
  145. if ($res['user_update']) {
  146. if ($res['user_update']['addr_code']) {
  147. $addr_code = explode(',', $res['user_update']['addr_code']);
  148. $res['user_update']['addr_name'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]]));
  149. } else $res['user_update']['addr_name'] = '';
  150. } else $res['user_update'] = $res['confirm'];
  151. return app_show(0, '请求成功', $res);
  152. }
  153. //用户确认订单数据(编辑)
  154. public function confirmImportData()
  155. {
  156. //每次编辑,都新增一条记录到extend表,同时原纪录作废,确保同一个order_import_from_c_id下只有一个正常的记录
  157. $param = $this->request->only([
  158. 'id',
  159. 'platform_code',
  160. 'platform_id',
  161. 'po_code' => '',
  162. 'platform_time',
  163. 'sale_source',
  164. 'plat_code',
  165. 'price',
  166. 'num',
  167. 'before_discount_all_price',
  168. 'activity_code' => '',
  169. 'activity_name' => '',
  170. 'mode',
  171. 'order_remark',
  172. 'contactor',
  173. 'mobile',
  174. 'addr',
  175. 'addr_code' => '',
  176. 'token'
  177. ], 'post', 'trim');
  178. $val = Validate::rule([
  179. 'id' => 'require',
  180. 'platform_code' => 'require',
  181. 'platform_id' => 'require|number',
  182. 'platform_time' => 'require',
  183. 'sale_source' => 'require',
  184. 'plat_code' => 'require',
  185. 'price' => 'require',
  186. 'num' => 'require',
  187. 'before_discount_all_price' => 'require',
  188. 'mode' => 'require',
  189. 'contactor' => 'require',
  190. 'mobile' => 'require',
  191. 'addr' => 'require',
  192. ]);
  193. if (!$val->check($param)) return error_show(1004, $val->getError());
  194. Db::startTrans();
  195. try {
  196. $rs = Db::name('order_import_from_c')
  197. ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
  198. ->find();
  199. if (empty($rs)) throw new Exception('该记录不存在或不允许用户确认');
  200. $userinfo = GetUserInfo($param['token']);
  201. //更新主表
  202. Db::name('order_import_from_c')
  203. ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
  204. ->update([
  205. 'status' => OIFCModel::$status_wait_relation,
  206. 'updatetime' => date('Y-m-d H:i:s'),
  207. 'remark' => '',
  208. 'updateid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  209. 'updater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  210. ]);
  211. //组织从表数据
  212. $extend_insert_data = [
  213. 'order_import_from_c_id' => $param['id'],
  214. 'platform_code' => $param['platform_code'],
  215. 'platform_id' => $param['platform_id'],
  216. 'po_code' => $param['po_code'],
  217. 'platform_time' => $param['platform_time'],
  218. 'sale_source' => $param['sale_source'],
  219. 'price' => $param['price'],
  220. 'num' => $param['num'],
  221. 'before_discount_all_price' => $param['before_discount_all_price'],
  222. 'mode' => $param['mode'],
  223. 'order_remark' => $param['order_remark'],
  224. 'contactor' => $param['contactor'],
  225. 'mobile' => $param['mobile'],
  226. 'addr' => $param['addr'],
  227. 'discount_reason' => $param['activity_name'],//优惠原因用活动名称
  228. 'addr_code' => is_array($param['addr_code']) ? implode(',', $param['addr_code']) : $param['addr_code'],
  229. 'activity_code' => $param['activity_code'],
  230. 'activity_name' => $param['activity_name'],
  231. 'addtime' => date('Y-m-d H:i:s'),
  232. 'createrid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  233. 'creater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  234. 'type' => 2,//1系统解析,2用户确认
  235. ];
  236. $good_platform_info = Db::name('good_platform')
  237. ->field('id,spuCode,platform_code,skuCode,plat_code')
  238. ->where(['is_del' => 0, 'plat_code' => $param['plat_code'], 'platform_code' => $param['platform_id'],
  239. 'exam_status' => 3])//exam_status==6 已上线
  240. ->find();
  241. //商品信息
  242. if (!empty($good_platform_info)) {
  243. $extend_insert_data['skuCode'] = $good_platform_info['skuCode'];
  244. $extend_insert_data['platform_id'] = $good_platform_info['platform_code'];
  245. $extend_insert_data['plat_code'] = $good_platform_info['plat_code'];
  246. $good_info = Db::name('good')
  247. ->field('good_name,companyNo,supplierNo')
  248. ->where(['is_del' => 0])
  249. ->where('spuCode', $good_platform_info['spuCode'])
  250. ->find();
  251. if (!empty($good_info)) {
  252. $extend_insert_data['companyNo'] = $good_info['companyNo'];
  253. $extend_insert_data['supplierNo'] = $good_info['supplierNo'];
  254. $extend_insert_data['good_name'] = $good_info['good_name'];
  255. } else throw new Exception('该平台商品编号找不到对应商品数据');
  256. } else throw new Exception('该平台商品编号找不到对应平台的商品数据');
  257. //企业客户
  258. $co = Db::name('good_platform')
  259. ->alias('gp')
  260. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  261. ->where('gp.plat_code', $rs['plat_code'])
  262. ->where('gp.exam_status', 3)//exam_status==3已上线
  263. ->value('p.platform_name','');
  264. if ($co!='') {
  265. $itemId= Db::connect('mysql_sys')->name("customer_org1")
  266. ->where(["name"=>$co,"is_del"=>0])
  267. ->value("id",0);
  268. $customer_code =Db::connect('mysql_sys')
  269. ->name('customer_info')
  270. ->where(['itemid' => $itemId, 'companyName' => $co . '客户', 'is_del' => 0])
  271. ->value('companyNo', '');
  272. if ($customer_code) $extend_insert_data['customer_code'] = $customer_code;
  273. else throw new Exception('对应客户不存在');
  274. } else throw new Exception('对应企业客户不存在');
  275. //从表数据
  276. Db::name('order_import_from_c_extend')->insert($extend_insert_data);
  277. Db::commit();
  278. Cache::store("redis")->handler()->lPush('import_order_from_c_key', $param['id']);//校验无误,入队列
  279. return app_show(0, '修改成功');
  280. } catch (Exception $exception) {
  281. Db::rollback();
  282. return error_show(1004, $exception->getMessage());
  283. }
  284. }
  285. //批量关联库存
  286. public function relationStockBatch()
  287. {
  288. $param = $this->request->only(['ids', 'plat_code'], 'post', 'trim');
  289. $val = Validate::rule([
  290. 'ids' => 'require',
  291. 'plat_code|平台商品编号' => 'require',
  292. ]);
  293. if (!$val->check($param)) return error_show(1004, $val->getError());
  294. // $info = Db::name('order_import_from_c_extend')
  295. // ->field('id,spuCode,companyNo')
  296. // ->whereIn('order_import_from_c_id', $param['ids'])
  297. // ->order('addtime','desc')
  298. // ->find();
  299. $good_platform = Db::name('good_platform')
  300. ->field('id,spuCode')
  301. ->where(['plat_code' => $param['plat_code'], 'is_del' => 0])
  302. ->find();
  303. if (empty($good_platform)) return error_show(1005, '平台商品编号有误');
  304. //判断库存是否充足
  305. $num = Db::name('order_import_from_c')
  306. ->whereIn('id', $param['ids'])
  307. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
  308. ->sum('num');
  309. // $companyNo = Db::name('good')
  310. // ->where(['spuCode' => $good_platform['spuCode'], 'is_del' => 0])
  311. // ->value('companyNo', '');
  312. // $wsm_code = Db::name('warehouse_info')
  313. // ->where(['companyNo' => $companyNo, 'is_del' => 0])
  314. // ->value('wsm_code', '');//一个供货企业会对应多个仓库,取哪个?
  315. $usable_stock = Db::name('good_stock')
  316. ->where(['spuCode' => $good_platform['spuCode'], 'is_del' => 0])
  317. ->value('usable_stock', 0);
  318. if ($usable_stock < $num) return error_show(1005, '可用库存只有' . $usable_stock . ',库存不足,关联失败');
  319. else {
  320. $userinfo = GetUserInfo($this->post['token']);
  321. $res = Db::name('order_import_from_c')
  322. ->whereIn('id', $param['ids'])
  323. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
  324. ->update([
  325. 'status' => OIFCModel::$status_wait_relation,
  326. 'remark' => '',
  327. 'updatetime' => date('Y-m-d H:i:s'),
  328. 'updateid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  329. 'updater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  330. ]);
  331. if ($res) {
  332. foreach ($param['ids'] as $id) {
  333. Cache::store("redis")->handler()->lPush('import_order_from_c_key', $id);//校验无误,入队列
  334. }
  335. return app_show(0, '批量关联库存成功');
  336. } else return error_show(1005, '批量关联库存失败');
  337. }
  338. }
  339. //删除【待用户确认】或者【库存不足】的订单
  340. public function delImportData()
  341. {
  342. $ids = $this->request->post('ids', [], 'trim');
  343. if (empty($ids)) return error_show(1004, 'ids不能为空');
  344. $rs = OIFCModel::field('id')
  345. ->whereNotIn('status', [OIFCModel::$status_wait_confirm, OIFCModel::$status_stock_not_enough])
  346. ->whereIn('id', $ids)
  347. ->findOrEmpty()
  348. ->isEmpty();
  349. if (!$rs) return error_show(1005, '该状态下不允许删除');
  350. Db::startTrans();
  351. try {
  352. $user = GetUserInfo($this->post['token']);
  353. Db::name('order_import_from_c')
  354. ->where('is_del', OIFCModel::$is_del_normal)
  355. ->whereIn('id', $ids)
  356. ->whereIn('status', [OIFCModel::$status_wait_confirm, OIFCModel::$status_stock_not_enough])
  357. ->update([
  358. 'updatetime' => date('Y-m-d H:i:s'),
  359. 'is_del' => OIFCModel::$is_del_delete,
  360. 'updateid' => isset($user['data']['id']) ? $user['data']['id'] : 0,
  361. 'updater' => isset($user['data']['nickname']) ? $user['data']['nickname'] : '',
  362. ]);
  363. Db::name('order_import_from_c_extend')
  364. ->whereIn('order_import_from_c_id', $ids)
  365. ->where('is_del', 0)
  366. ->update(['is_del' => 1]);
  367. Db::commit();
  368. return app_show(0, '删除成功');
  369. } catch (Exception $exception) {
  370. Db::rollback();
  371. return error_show(1005, '删除失败,' . $exception->getMessage());
  372. }
  373. }
  374. //【辅助1】获取线上商品详情
  375. public function getOnlineGoodInfoByPlatcode()
  376. {
  377. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] != "" ? trim($this->post['plat_code']) : "";
  378. if ($plat_code == "") {
  379. return error_show(1005, "参数plat_code不能为空");
  380. }
  381. $where = [['plat_code', '=', $plat_code]];
  382. $platform_id = isset($this->post['platform_id']) && $this->post['platform_id'] != "" ? intval($this->post['platform_id']) : "";
  383. if ($platform_id != '') $where[] = ['platform_code', '=', $platform_id];
  384. $good_platform = Db::name("good_platform")
  385. ->where($where)
  386. ->where(['is_del' => 0])
  387. ->find();
  388. if ($good_platform == false) {
  389. return error_show(1004, "未找到商品数据");
  390. }
  391. $data = Db::name("good")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->find();
  392. if ($data == false) {
  393. return error_show(1004, "未找到商品数据");
  394. }
  395. $plat = Db::name("platform")->where(["id" => $good_platform['platform_code']])->find();
  396. $data['skuCode'] = $good_platform['skuCode'];
  397. $data['platform_code'] = $good_platform['platform_code'];
  398. $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
  399. $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  400. $data['online_reason'] = $good_platform['online_reason'];
  401. $data['online_time'] = $good_platform['online_time'];
  402. $data['online_remark'] = $good_platform['online_remark'];
  403. $data['exam_status'] = $good_platform['exam_status'];
  404. $data['is_online'] = $good_platform['is_online'];
  405. $data['plat_code'] = $good_platform['plat_code'];
  406. $data['exclusive'] = makeExcluse($data['is_exclusive']);
  407. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  408. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  409. $data['cat_info'] = made($data['cat_id'], []);
  410. $spec = Db::name("good_spec")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  411. $userCommon = \app\admin\common\User::getIns();
  412. $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $data['supplierNo']]);
  413. // $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  414. $supplier = $supplier_temp['data']??"";
  415. $data['supplierName'] = isset($supplier[$data['supplierNo']]) ? $supplier[$data['supplierNo']] : "";
  416. $noble = Config::get('noble');
  417. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $noble[$data['noble_metal']] : "";
  418. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  419. $data['company'] = isset($company['company']) ? $company['company'] : "";
  420. if ($data['brand_id'] != 0) {
  421. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  422. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  423. } else {
  424. $data["brand_name"] = "";
  425. $data["brand_id"] = "";
  426. }
  427. $data['origin_place_cn'] = "";
  428. $data['delivery_place_cn'] = "";
  429. if ($data['delivery_place'] !== "") {
  430. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  431. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
  432. $data['delivery_place_cn'] = GetAddr(json_encode($place));
  433. }
  434. if ($data['origin_place'] !== "") {
  435. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  436. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
  437. $data['origin_place_cn'] = GetAddr(json_encode($place));
  438. }
  439. $excluse = makeExcluse($data['is_exclusive']);
  440. $data['exclusive'] = $excluse;
  441. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
  442. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  443. $speclist = [];
  444. if (!empty($spec)) {
  445. foreach ($spec as $value) {
  446. $temp = [];
  447. $temp['id'] = $value['id'];
  448. $temp['spuCode'] = $value['spuCode'];
  449. $temp['spec_id'] = $value['spec_id'];
  450. $temp['spec_value_id'] = $value['spec_value_id'];
  451. $temp['is_del'] = $value['is_del'];
  452. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  453. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  454. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  455. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  456. $speclist[] = $temp;
  457. }
  458. }
  459. $data["speclist"] = empty($speclist) ? [] : $speclist;
  460. $ladder = Db::name("good_ladder")->where(['skuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  461. $data["ladderlist"] = !empty($ladder) ? $ladder : [];
  462. $nakelist = Db::name("good_nake")->where(['spuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  463. $cat_top_list = made($data['cat_id']);
  464. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  465. $nakearry = [];
  466. if (!empty($nakelist)) {
  467. //实时金价
  468. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  469. foreach ($nakelist as $value) {
  470. $value['sale_price'] = $value['nake_total'];
  471. //计算最终售价
  472. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  473. //普通商品:直接用财务提交的售价字段;
  474. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  475. $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
  476. }
  477. $nakearry[] = $value;
  478. }
  479. }
  480. $proof = Db::name("good_proof")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  481. $data['proof'] = isset($proof) && $proof != false ? $proof : [];
  482. $data["nakelist"] = $nakearry;
  483. //补充采购员字段
  484. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  485. $temp_basic_info = Db::name('good_basic')
  486. ->field('id,createrid purchase_id,creater purchase')
  487. ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
  488. ->find();
  489. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  490. $data['purchase'] = $temp_basic_info['purchase'];
  491. return app_show(0, "获取成功", $data);
  492. }
  493. //【辅助2】接口2-获取销售渠道备选数据:入参所在平台Id,响应:销售渠道备选数据
  494. public function getSourceDataByPlatformId()
  495. {
  496. $platform_id = $this->request->post('platform_id/d', 0, 'trim');
  497. $where = ['ps.is_del' => 0];
  498. if ($platform_id != 0) $where['ps.platform_id'] = $platform_id;
  499. $list = Db::name('platform_source')
  500. ->alias('ps')
  501. ->field('ps.id,ps.platform_id,ps.source,p.platform_name')
  502. ->leftJoin('platform p', 'p.id=ps.platform_id AND p.is_del=0')
  503. ->where($where)
  504. ->order('ps.id', 'desc')
  505. ->select()
  506. ->toArray();
  507. return app_show(0, '获取成功', $list);
  508. }
  509. }