OrderImport.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. * $info = OIFCModel::alias('c')
  154. * ->field('c.*,ce.*,b.company,ci.companyName CustomerCompanyName,s.name supplierName,a.activity_code')
  155. * ->leftJoin('order_import_from_c_extend ce', 'ce.order_import_from_c_id=c.id')
  156. * ->leftJoin('business b', 'b.companyNo=ce.companyNo AND b.is_del=0')
  157. * ->leftJoin('customer_info ci', 'ci.companyNo=ce.customer_code AND ci.is_del=0')
  158. * ->leftJoin('supplier s', 's.code=ce.supplierNo AND s.is_del=0')
  159. * ->leftJoin('activity_info a', 'a.activity_code=ce.activity_code AND a.is_del=0')
  160. * ->where('c.id', $id)
  161. * ->where('c.status', '<>', OIFCModel::$status_wait_validate)
  162. * ->findOrEmpty()
  163. * ->toArray();//因为这里用的是模型,查询结果是一个对象
  164. *
  165. * if (!empty($info)) {
  166. * $info['platform_names'] = Db::name('platform')
  167. * ->where('platform_code', $info['platform_id'])
  168. * ->where(['is_del' => 0, 'status' => 1])
  169. * ->column('platform_name');
  170. *
  171. * if ($info['addr_code']) {
  172. * $addr_code = explode(',', $info['addr_code']);
  173. * $info['addr_name'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]]));
  174. * } else $info['addr_name'] = '';
  175. *
  176. * $res['id'] = $info['id'];
  177. * $res['status'] = $info['status'];
  178. * $res['createrid'] = $info['createrid'];
  179. * $res['creater'] = $info['creater'];
  180. * $res['updateid'] = $info['updateid'];
  181. * $res['updater'] = $info['updater'];
  182. *
  183. * //导入字段
  184. * $res['import'] = [
  185. * 'platform_code' => $info['platform_code'],
  186. * 'platform_time' => $info['platform_time'],
  187. * 'plat_code' => $info['plat_code'],
  188. * 'sale_source' => $info['sale_source'],
  189. * 'price' => $info['price'],
  190. * 'num' => $info['num'],
  191. * 'before_discount_all_price' => $info['before_discount_all_price'],
  192. * 'activity_name' => $info['activity_name'],
  193. * 'mode' => $info['mode'],
  194. * 'order_remark' => $info['order_remark'],
  195. * 'contactor' => $info['contactor'],
  196. * 'mobile' => $info['mobile'],
  197. * 'addr' => $info['addr'],
  198. * ];
  199. * //确认字段
  200. * $res['confirm'] = $info;
  201. *
  202. * //用户编辑字段
  203. * $user_update = Db::name('order_import_from_c_extend')
  204. * ->alias('ce')
  205. * ->field('ce.*,b.company,ci.companyName CustomerCompanyName,s.name supplierName,a.activity_code')
  206. * ->leftJoin('business b', 'b.companyNo=ce.companyNo AND b.is_del=0')
  207. * ->leftJoin('customer_info ci', 'ci.companyNo=ce.customer_code AND ci.is_del=0')
  208. * ->leftJoin('supplier s', 's.code=ce.supplierNo AND s.is_del=0')
  209. * ->leftJoin('activity_info a', 'a.activity_code=ce.activity_code AND a.is_del=0')
  210. * ->where(['ce.order_import_from_c_id' => $id, 'ce.is_del' => 1])
  211. * ->order('ce.addtime', 'desc')
  212. * ->find();
  213. *
  214. * if (empty($user_update)) $res['user_update'] = $res['confirm'];
  215. * else {
  216. * if ($user_update['addr_code']) {
  217. * $addr_code = explode(',', $user_update['addr_code']);
  218. * $user_update['addr_name'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]]));
  219. * } else $user_update['addr_name'] = '';
  220. * $res['user_update'] = array_merge($res['confirm'], $user_update);
  221. * }
  222. *
  223. * return app_show(0, '请求成功', $res);
  224. *
  225. * } else return error_show(1005, '系统尚未解析完成,无法查看详情,请等待');
  226. **/
  227. }
  228. //用户确认订单数据(编辑)
  229. public function confirmImportData()
  230. {
  231. //每次编辑,都新增一条记录到extend表,同时原纪录作废,确保同一个order_import_from_c_id下只有一个正常的记录
  232. $param = $this->request->only([
  233. 'id',
  234. 'platform_code',
  235. 'platform_id',
  236. 'po_code' => '',
  237. 'platform_time',
  238. 'sale_source',
  239. 'plat_code',
  240. 'price',
  241. 'num',
  242. 'before_discount_all_price',
  243. 'activity_code' => '',
  244. 'activity_name' => '',
  245. 'mode',
  246. 'order_remark',
  247. 'contactor',
  248. 'mobile',
  249. 'addr',
  250. 'addr_code' => '',
  251. 'token'
  252. ], 'post', 'trim');
  253. $val = Validate::rule([
  254. 'id' => 'require',
  255. 'platform_code' => 'require',
  256. 'platform_id' => 'require|number',
  257. 'platform_time' => 'require',
  258. 'sale_source' => 'require',
  259. 'plat_code' => 'require',
  260. 'price' => 'require',
  261. 'num' => 'require',
  262. 'before_discount_all_price' => 'require',
  263. 'mode' => 'require',
  264. 'contactor' => 'require',
  265. 'mobile' => 'require',
  266. 'addr' => 'require',
  267. ]);
  268. if (!$val->check($param)) return error_show(1004, $val->getError());
  269. Db::startTrans();
  270. try {
  271. $rs = Db::name('order_import_from_c')
  272. ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
  273. ->find();
  274. if (empty($rs)) throw new Exception('该记录不存在或不允许用户确认');
  275. $userinfo = GetUserInfo($param['token']);
  276. //更新主表
  277. Db::name('order_import_from_c')
  278. ->where(['id' => $param['id'], 'is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_confirm])
  279. ->update([
  280. 'status' => OIFCModel::$status_wait_relation,
  281. 'updatetime' => date('Y-m-d H:i:s'),
  282. 'remark' => '',
  283. 'updateid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  284. 'updater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  285. ]);
  286. //组织从表数据
  287. $extend_insert_data = [
  288. 'order_import_from_c_id' => $param['id'],
  289. 'platform_code' => $param['platform_code'],
  290. 'platform_id' => $param['platform_id'],
  291. 'po_code' => $param['po_code'],
  292. 'platform_time' => $param['platform_time'],
  293. 'sale_source' => $param['sale_source'],
  294. 'price' => $param['price'],
  295. 'num' => $param['num'],
  296. 'before_discount_all_price' => $param['before_discount_all_price'],
  297. 'mode' => $param['mode'],
  298. 'order_remark' => $param['order_remark'],
  299. 'contactor' => $param['contactor'],
  300. 'mobile' => $param['mobile'],
  301. 'addr' => $param['addr'],
  302. 'discount_reason' => $param['activity_name'],//优惠原因用活动名称
  303. 'addr_code' => is_array($param['addr_code']) ? implode(',', $param['addr_code']) : $param['addr_code'],
  304. 'activity_code' => $param['activity_code'],
  305. 'activity_name' => $param['activity_name'],
  306. 'addtime' => date('Y-m-d H:i:s'),
  307. 'createrid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  308. 'creater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  309. 'type' => 2,//1系统解析,2用户确认
  310. ];
  311. $good_platform_info = Db::name('good_platform')
  312. ->field('id,spuCode,platform_code,skuCode,plat_code')
  313. ->where(['is_del' => 0, 'plat_code' => $param['plat_code'], 'platform_code' => $param['platform_id'],
  314. 'exam_status' => 3])//exam_status==6 已上线
  315. ->find();
  316. //商品信息
  317. if (!empty($good_platform_info)) {
  318. $extend_insert_data['skuCode'] = $good_platform_info['skuCode'];
  319. $extend_insert_data['platform_id'] = $good_platform_info['platform_code'];
  320. $extend_insert_data['plat_code'] = $good_platform_info['plat_code'];
  321. $good_info = Db::name('good')
  322. ->field('good_name,companyNo,supplierNo')
  323. ->where(['is_del' => 0])
  324. ->where('spuCode', $good_platform_info['spuCode'])
  325. ->find();
  326. if (!empty($good_info)) {
  327. $extend_insert_data['companyNo'] = $good_info['companyNo'];
  328. $extend_insert_data['supplierNo'] = $good_info['supplierNo'];
  329. $extend_insert_data['good_name'] = $good_info['good_name'];
  330. } else throw new Exception('该平台商品编号找不到对应商品数据');
  331. } else throw new Exception('该平台商品编号找不到对应平台的商品数据');
  332. //企业客户
  333. $co = Db::name('good_platform')
  334. ->alias('gp')
  335. ->leftJoin('platform p', 'p.id=gp.platform_code AND p.is_del=0')
  336. ->leftJoin('customer_org1 co', 'co.name=p.platform_name AND co.is_del=0')
  337. ->where('gp.plat_code', $rs['plat_code'])
  338. ->field('co.id,co.name')
  339. ->find();
  340. if ($co) {
  341. $customer_code = Db::name('customer_info')
  342. ->where(['itemid' => $co['id'], 'companyName' => $co['name'] . '客户', 'is_del' => 0])
  343. ->value('companyNo', '');
  344. if ($customer_code) $extend_insert_data['customer_code'] = $customer_code;
  345. else throw new Exception('对应客户不存在');
  346. } else throw new Exception('对应企业客户不存在');
  347. //从表数据
  348. Db::name('order_import_from_c_extend')->insert($extend_insert_data);
  349. Db::commit();
  350. Cache::store("redis")->handler()->lPush('import_order_from_c_key', $param['id']);//校验无误,入队列
  351. return app_show(0, '修改成功');
  352. } catch (Exception $exception) {
  353. Db::rollback();
  354. return error_show(1004, $exception->getMessage());
  355. }
  356. }
  357. //批量关联库存
  358. public function relationStockBatch()
  359. {
  360. $param = $this->request->only(['ids', 'plat_code'], 'post', 'trim');
  361. $val = Validate::rule([
  362. 'ids' => 'require',
  363. 'plat_code|平台商品编号' => 'require',
  364. ]);
  365. if (!$val->check($param)) return error_show(1004, $val->getError());
  366. // $info = Db::name('order_import_from_c_extend')
  367. // ->field('id,spuCode,companyNo')
  368. // ->whereIn('order_import_from_c_id', $param['ids'])
  369. // ->order('addtime','desc')
  370. // ->find();
  371. $good_platform = Db::name('good_platform')
  372. ->field('id,spuCode')
  373. ->where(['plat_code' => $param['plat_code'], 'is_del' => 0])
  374. ->find();
  375. if (empty($good_platform)) return error_show(1005, '平台商品编号有误');
  376. //判断库存是否充足
  377. $num = Db::name('order_import_from_c')
  378. ->whereIn('id', $param['ids'])
  379. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
  380. ->sum('num');
  381. // $companyNo = Db::name('good')
  382. // ->where(['spuCode' => $good_platform['spuCode'], 'is_del' => 0])
  383. // ->value('companyNo', '');
  384. // $wsm_code = Db::name('warehouse_info')
  385. // ->where(['companyNo' => $companyNo, 'is_del' => 0])
  386. // ->value('wsm_code', '');//一个供货企业会对应多个仓库,取哪个?
  387. $usable_stock = Db::name('good_stock')
  388. ->where(['spuCode' => $good_platform['spuCode'], 'is_del' => 0])
  389. ->value('usable_stock', 0);
  390. if ($usable_stock < $num) return error_show(1005, '可用库存只有' . $usable_stock . ',库存不足,关联失败');
  391. else {
  392. $userinfo = GetUserInfo($this->post['token']);
  393. $res = Db::name('order_import_from_c')
  394. ->whereIn('id', $param['ids'])
  395. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_stock_not_enough])
  396. ->update([
  397. 'status' => OIFCModel::$status_wait_relation,
  398. 'remark' => '',
  399. 'updatetime' => date('Y-m-d H:i:s'),
  400. 'updateid' => isset($userinfo["data"]['id']) ? $userinfo["data"]['id'] : 0,
  401. 'updater' => isset($userinfo["data"]['nickname']) ? $userinfo["data"]['nickname'] : '',
  402. ]);
  403. if ($res) {
  404. foreach ($param['ids'] as $id) {
  405. Cache::store("redis")->handler()->lPush('import_order_from_c_key', $id);//校验无误,入队列
  406. }
  407. return app_show(0, '批量关联库存成功');
  408. } else return error_show(1005, '批量关联库存失败');
  409. }
  410. }
  411. //删除【待用户确认】或者【库存不足】的订单
  412. public function delImportData()
  413. {
  414. $ids = $this->request->post('ids', [], 'trim');
  415. if (empty($ids)) return error_show(1004, 'ids不能为空');
  416. $rs = OIFCModel::field('id')
  417. ->whereNotIn('status', [OIFCModel::$status_wait_confirm, OIFCModel::$status_stock_not_enough])
  418. ->whereIn('id', $ids)
  419. ->findOrEmpty()
  420. ->isEmpty();
  421. if (!$rs) return error_show(1005, '该状态下不允许删除');
  422. Db::startTrans();
  423. try {
  424. $user = GetUserInfo($this->post['token']);
  425. Db::name('order_import_from_c')
  426. ->where('is_del', OIFCModel::$is_del_normal)
  427. ->whereIn('id', $ids)
  428. ->whereIn('status', [OIFCModel::$status_wait_confirm, OIFCModel::$status_stock_not_enough])
  429. ->update([
  430. 'updatetime' => date('Y-m-d H:i:s'),
  431. 'is_del' => OIFCModel::$is_del_delete,
  432. 'updateid' => isset($user['data']['id']) ? $user['data']['id'] : 0,
  433. 'updater' => isset($user['data']['nickname']) ? $user['data']['nickname'] : '',
  434. ]);
  435. Db::name('order_import_from_c_extend')
  436. ->whereIn('order_import_from_c_id', $ids)
  437. ->where('is_del', 0)
  438. ->update(['is_del' => 1]);
  439. Db::commit();
  440. return app_show(0, '删除成功');
  441. } catch (Exception $exception) {
  442. Db::rollback();
  443. return error_show(1005, '删除失败,' . $exception->getMessage());
  444. }
  445. }
  446. //【辅助1】获取线上商品详情
  447. public function getOnlineGoodInfoByPlatcode()
  448. {
  449. $plat_code = isset($this->post['plat_code']) && $this->post['plat_code'] != "" ? trim($this->post['plat_code']) : "";
  450. if ($plat_code == "") {
  451. return error_show(1005, "参数plat_code不能为空");
  452. }
  453. $where = [['plat_code', '=', $plat_code]];
  454. $platform_id = isset($this->post['platform_id']) && $this->post['platform_id'] != "" ? intval($this->post['platform_id']) : "";
  455. if ($platform_id != '') $where[] = ['platform_code', '=', $platform_id];
  456. $good_platform = Db::name("good_platform")
  457. ->where($where)
  458. ->where(['is_del' => 0])
  459. ->find();
  460. if ($good_platform == false) {
  461. return error_show(1004, "未找到商品数据");
  462. }
  463. $data = Db::name("good")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->find();
  464. if ($data == false) {
  465. return error_show(1004, "未找到商品数据");
  466. }
  467. $plat = Db::name("platform")->where(["id" => $good_platform['platform_code']])->find();
  468. $data['skuCode'] = $good_platform['skuCode'];
  469. $data['platform_code'] = $good_platform['platform_code'];
  470. $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
  471. $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  472. $data['online_reason'] = $good_platform['online_reason'];
  473. $data['online_time'] = $good_platform['online_time'];
  474. $data['online_remark'] = $good_platform['online_remark'];
  475. $data['exam_status'] = $good_platform['exam_status'];
  476. $data['is_online'] = $good_platform['is_online'];
  477. $data['plat_code'] = $good_platform['plat_code'];
  478. $data['exclusive'] = makeExcluse($data['is_exclusive']);
  479. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  480. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  481. $data['cat_info'] = made($data['cat_id'], []);
  482. $spec = Db::name("good_spec")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  483. $userCommon = \app\admin\common\User::getIns();
  484. $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $data['supplierNo']]);
  485. // $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  486. $supplier = $supplier_temp['data']??"";
  487. $data['supplierName'] = isset($supplier[$data['supplierNo']]) ? $supplier[$data['supplierNo']] : "";
  488. $noble = Config::get('noble');
  489. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $noble[$data['noble_metal']] : "";
  490. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  491. $data['company'] = isset($company['company']) ? $company['company'] : "";
  492. if ($data['brand_id'] != 0) {
  493. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  494. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  495. } else {
  496. $data["brand_name"] = "";
  497. $data["brand_id"] = "";
  498. }
  499. $data['origin_place_cn'] = "";
  500. $data['delivery_place_cn'] = "";
  501. if ($data['delivery_place'] !== "") {
  502. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  503. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
  504. $data['delivery_place_cn'] = GetAddr(json_encode($place));
  505. }
  506. if ($data['origin_place'] !== "") {
  507. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  508. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
  509. $data['origin_place_cn'] = GetAddr(json_encode($place));
  510. }
  511. $excluse = makeExcluse($data['is_exclusive']);
  512. $data['exclusive'] = $excluse;
  513. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
  514. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  515. $speclist = [];
  516. if (!empty($spec)) {
  517. foreach ($spec as $value) {
  518. $temp = [];
  519. $temp['id'] = $value['id'];
  520. $temp['spuCode'] = $value['spuCode'];
  521. $temp['spec_id'] = $value['spec_id'];
  522. $temp['spec_value_id'] = $value['spec_value_id'];
  523. $temp['is_del'] = $value['is_del'];
  524. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  525. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  526. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  527. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  528. $speclist[] = $temp;
  529. }
  530. }
  531. $data["speclist"] = empty($speclist) ? [] : $speclist;
  532. $ladder = Db::name("good_ladder")->where(['skuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  533. $data["ladderlist"] = !empty($ladder) ? $ladder : [];
  534. $nakelist = Db::name("good_nake")->where(['spuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  535. $cat_top_list = made($data['cat_id']);
  536. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  537. $nakearry = [];
  538. if (!empty($nakelist)) {
  539. //实时金价
  540. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  541. foreach ($nakelist as $value) {
  542. $value['sale_price'] = $value['nake_total'];
  543. //计算最终售价
  544. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  545. //普通商品:直接用财务提交的售价字段;
  546. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  547. $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']);
  548. }
  549. $nakearry[] = $value;
  550. }
  551. }
  552. $proof = Db::name("good_proof")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  553. $data['proof'] = isset($proof) && $proof != false ? $proof : [];
  554. $data["nakelist"] = $nakearry;
  555. //补充采购员字段
  556. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  557. $temp_basic_info = Db::name('good_basic')
  558. ->field('id,createrid purchase_id,creater purchase')
  559. ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
  560. ->find();
  561. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  562. $data['purchase'] = $temp_basic_info['purchase'];
  563. return app_show(0, "获取成功", $data);
  564. }
  565. //【辅助2】接口2-获取销售渠道备选数据:入参所在平台Id,响应:销售渠道备选数据
  566. public function getSourceDataByPlatformId()
  567. {
  568. $platform_id = $this->request->post('platform_id/d', 0, 'trim');
  569. $where = ['ps.is_del' => 0];
  570. if ($platform_id != 0) $where['ps.platform_id'] = $platform_id;
  571. $list = Db::name('platform_source')
  572. ->alias('ps')
  573. ->field('ps.id,ps.platform_id,ps.source,p.platform_name')
  574. ->leftJoin('platform p', 'p.id=ps.platform_id AND p.is_del=0')
  575. ->where($where)
  576. ->order('ps.id', 'desc')
  577. ->select()
  578. ->toArray();
  579. return app_show(0, '获取成功', $list);
  580. }
  581. }