AfterChild.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\DataGroup as DataGroupModel;
  4. use think\Exception;
  5. use think\facade\Db;
  6. use think\facade\Validate;
  7. //退货工单
  8. class AfterChild extends Base
  9. {
  10. //退货工单列表
  11. public function getList()
  12. {
  13. $param = $this->request->only(['page' => 1, 'size' => 10, 'returnCode' => '', 'status' => '', 'orderCode' => '', 'outCode' => '', 'order_type' => '', 'supplierNo' => ''], 'post', 'trim');
  14. $db = Db::name('order_return_child')
  15. ->alias('a')
  16. ->leftJoin('warehouse_info b', 'b.wsm_code=a.send_wsm_code')
  17. ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
  18. ->leftJoin('order_return d', 'd.returnCode=a.returnCode and d.is_del=0')
  19. ->where('a.is_del', 0);
  20. if ($param['returnCode'] != '') $db->whereLike('a.returnCode', '%' . $param['returnCode'] . '%');
  21. if ($param['status'] !== '') $db->where('a.status', $param['status']);
  22. if ($param['orderCode'] != '') $db->whereLike('a.orderCode', '%' . $param['orderCode'] . '%');
  23. if ($param['outCode'] != '') $db->whereLike('a.outCode', '%' . $param['outCode'] . '%');
  24. if ($param['order_type'] !== '') $db->where('d.order_type', $param['order_type']);
  25. if ($param['supplierNo'] != '') $db->whereLike('d.supplierNo', '%' . $param['supplierNo'] . '%');
  26. //数据权限相关
  27. //供应商账号,只查询该供应商下所有数据
  28. if ($this->level == 3 && $param['supplierNo'] == '') return json_show(1004, '供应商账号时供应商编码不能为空');
  29. //1.超管,查看全部;
  30. //2.业务公司账号-申请人,初始状态只查看自己创建的;
  31. //3.业务公司账号-退回仓库负责人,只查看自己负责仓库的数据;
  32. //4.业务公司账号-数据共享接受人,共享给自己的数据;
  33. if ($this->level == 2) {
  34. //是否仓库负责人
  35. $is_contactor = Db::name('warehouse_info')
  36. ->field('id')
  37. ->where(['is_del' => 0, 'contactor' => $this->uid])
  38. ->findOrEmpty();
  39. if (empty($is_contactor)) {
  40. $role = $this->checkDataShare();
  41. $hand = resign_hand_user($this->uid, 0);
  42. $db->whereIn('d.apply_id', array_unique(array_merge($role[DataGroupModel::$type_全部], $hand)));
  43. } else {
  44. $db->where('`a`.`return_wsm_code` in ' . Db::name('warehouse_info')->field('wsm_code')->where(['is_del' => 0, 'contactor' => $this->uid])->buildSql());
  45. }
  46. }
  47. $count = $db
  48. ->count('a.id');
  49. $list = $db
  50. ->field('a.id,a.returnCode,a.orderCode,a.outCode,a.order_out_child_status,a.outChildCode,b.supplierName send_supplierName,b.supplierNo send_supplierNo,b.name send_wsm_name,a.send_wsm_code,b.contactor_name send_contactor_name,a.send_num,a.return_num,c.supplierName return_supplierName,c.supplierNo return_supplierNo,c.name return_wsm_name,a.return_wsm_code,c.contactor_name return_contactor_name,a.status,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.apply_id,d.apply_name')
  51. ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
  52. ->page($param['page'], $param['size'])
  53. ->select()
  54. ->toArray();
  55. return json_show(0, '获取列表成功', ['count' => $count, 'list' => $list]);
  56. }
  57. //设置退货工单
  58. public function setOrderReturnChild()
  59. {
  60. $param = $this->request->only(['returnCode', 'list'], 'post', 'trim');
  61. $val = Validate::rule([
  62. 'returnCode|售后申请单编码' => 'require',
  63. 'list|工单集合' => 'require|array|max:100',
  64. ]);
  65. if ($val->check($param) == false) return json_show(1004, $val->getError());
  66. $info = Db::name('order_return')
  67. ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
  68. ->findOrEmpty();
  69. if (empty($info)) return json_show(1004, '售后申请单不存在');
  70. if ($info['status'] != 11) return json_show(1004, '售后申请单状态错误');
  71. if ($info['is_receive'] != 1) return json_show(1004, '未收到货,无需设置退货工单');
  72. $order_out = Db::name('order_out')
  73. ->field('id,status order_out_status,orderCode')
  74. ->where(['is_del' => 0, 'outCode' => $info['outCode']])
  75. ->findOrEmpty();
  76. if (empty($order_out)) return json_show(1004, '未找到对应的发货单');
  77. $val_child = Validate::rule([
  78. 'outChildCode|发货工单号' => 'require',
  79. 'return_num|退货数量' => 'require|number|gt:0|max:999999999999',
  80. 'return_wsm_code|退货仓库编码' => 'require'
  81. ]);
  82. //发货工单详情
  83. $order_out_child = Db::name('order_out_child')
  84. ->where(['is_del' => 0, 'outCode' => $info['outCode'], 'outChildCode' => array_column($param['list'], 'outChildCode')])
  85. ->column('num,wsm_code,status', 'outChildCode');
  86. //所有仓库详情
  87. $wsm_info = Db::name('warehouse_info')
  88. ->where(['is_del' => 0, 'wsm_code' => array_unique(array_merge(array_column($order_out_child, 'wsm_code'), array_column($param['list'], 'return_wsm_code')))])
  89. ->column('id', 'wsm_code');
  90. if (array_sum(array_column($param['list'], 'return_num')) != $info['error_num']) return json_show(1004, '数量错误');
  91. Db::startTrans();
  92. try {
  93. $insert = [];
  94. $date = date('Y-m-d H:i:s');
  95. foreach ($param['list'] as $value) {
  96. if ($val_child->check($value) == false) throw new Exception($val_child->getError());
  97. if (!isset($order_out_child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '发货工单不存在');
  98. if (!isset($wsm_info[$value['return_wsm_code']])) throw new Exception($value['return_wsm_code'] . '退货仓库不存在');
  99. $insert[] = [
  100. 'returnCode' => $param['returnCode'],
  101. 'orderCode' => $order_out['orderCode'],
  102. 'outCode' => $info['outCode'],
  103. 'order_out_child_status' => $order_out_child[$value['outChildCode']]['status'],
  104. 'outChildCode' => $value['outChildCode'],
  105. 'send_wsm_code' => $order_out_child[$value['outChildCode']]['wsm_code'],
  106. 'send_num' => $order_out_child[$value['outChildCode']]['num'],
  107. 'return_num' => $value['return_num'],
  108. 'return_wsm_code' => $value['return_wsm_code'],
  109. 'can_sell_num' => 0,
  110. 'defective_num' => 0,
  111. 'loss_num' => 0,
  112. 'apply_id' => $this->uid,
  113. 'apply_name' => $this->uname,
  114. 'status' => 1,
  115. 'is_del' => 0,
  116. 'remark' => '',
  117. 'addtime' => $date,
  118. 'updatetime' => $date,
  119. ];
  120. }
  121. if ($insert) Db::name('order_return_child')->insertAll($insert);
  122. Db::name('order_return')
  123. ->where(['is_del' => 0, 'id' => $info['id'], 'status' => 11])
  124. ->update(['status' => 4, 'updatetime' => $date]);
  125. Db::commit();
  126. return json_show(0, '设置退货工单成功');
  127. } catch (Exception $exception) {
  128. Db::rollback();
  129. return json_show(1004, $exception->getMessage());
  130. }
  131. }
  132. //库管收货
  133. public function deliveryOrderReturnChild()
  134. {
  135. $param = $this->request->only(['returnCode', 'list'], 'post', 'trim');
  136. $val = Validate::rule([
  137. 'returnCode|退货申请单号' => 'require',
  138. 'list|退货工单集合' => 'require|array|max:100',
  139. ]);
  140. if ($val->check($param) == false) return json_show(1004, $val->getError());
  141. $order_return = Db::name('order_return')
  142. ->alias('a')
  143. ->field('a.id,a.good_code,a.outCode,b.orderCode,c.is_stock,c.order_type,a.status')
  144. ->leftJoin('order_out b', 'b.outCode=a.outCode AND b.is_del=0')
  145. ->leftJoin('sale c', 'c.orderCode=b.orderCode AND c.is_del=0')
  146. ->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode']])
  147. ->findOrEmpty();
  148. if (empty($order_return)) return json_show(1004, '售后申请单不存在');
  149. if ($order_return['status'] != 12) return json_show(1004, '售后申请单状态有误');
  150. $info = Db::name('order_return_child')
  151. ->alias('a')
  152. ->leftJoin('order_out_child b', 'b.outChildCode=a.outChildCode')
  153. ->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode'], 'a.id' => array_column($param['list'], 'id')])
  154. ->column('a.id,a.return_wsm_code,a.outChildCode,b.wsm_code,a.status,a.return_num', 'a.id');
  155. if (empty($info)) return json_show(1004, '退货工单不存在');
  156. $val_child = Validate::rule([
  157. 'id|退货工单id' => 'require|gt:0|max:999999999',
  158. 'can_sell_num|销售仓入库数量' => 'require|number|egt:0|max:999999999999',
  159. 'defective_num|次品仓入库数量' => 'require|number|egt:0|max:999999999999',
  160. 'loss_num|丢失数量' => 'require|number|egt:0|max:999999999999',
  161. 'remark|备注' => 'max:255'
  162. ]);
  163. Db::startTrans();
  164. try {
  165. $date = date('Y-m-d H:i:s');
  166. foreach ($param['list'] as $value) {
  167. if ($val_child->check($value) == false) throw new Exception($val_child->getError());
  168. if (!isset($info[$value['id']])) throw new Exception($value['id'] . '退货工单不存在');
  169. if ($info[$value['id']]['status'] != 1) throw new Exception($value['id'] . '退货工单状态有误');
  170. //退货工单
  171. Db::name('order_return_child')
  172. ->where(['is_del' => 0, 'id' => $value['id']])
  173. ->update([
  174. 'can_sell_num' => $value['can_sell_num'],
  175. 'defective_num' => $value['defective_num'],
  176. 'loss_num' => $value['loss_num'],
  177. 'remark' => $value['remark'] ?? '',
  178. 'updatetime' => $date,
  179. 'status' => 2
  180. ]);
  181. //发货工单数量减少
  182. Db::name('order_out_child')
  183. ->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
  184. ->dec('num', $info[$value['id']]['return_num'])
  185. ->update(['updatetime' => $date]);
  186. }
  187. $total = array_sum(array_column($param['list'], 'can_sell_num'));
  188. if ($total > 0) {
  189. if ($order_return['is_stock'] != 1) {
  190. //根据转化表判断该非库存品是否转化为库存品
  191. $spuCode = Db::name('good_change_stock')
  192. ->where(['old_spuCode' => $order_return['good_code'], 'old_order_type' => $order_return['order_type']])
  193. ->value('spuCode', '');
  194. if ($spuCode == '') {
  195. //将非库存品转化为库存品
  196. $spuCode = makeNo('SKU');
  197. if ($order_return['order_type'] == 2) {
  198. $good = Db::name('good_basic')
  199. ->where('spuCode', $order_return['good_code'])
  200. ->findOrEmpty();
  201. if (!empty($good)) {
  202. Db::name('good_basic')->insert(array_merge($good, [
  203. 'id' => null,
  204. 'spuCode' => $spuCode,
  205. 'addtime' => $date,
  206. 'updatetime' => $date,
  207. ]));
  208. }
  209. } else {
  210. $good = Db::name('good_zixun')
  211. ->where([])
  212. ->findOrEmpty();
  213. if (!empty($good)) {
  214. Db::name('good_basic')->insert([
  215. 'spuCode' => $spuCode,
  216. 'good_code' => $good['good_code'],
  217. 'good_name' => $good['good_name'],
  218. 'cat_id' => $good['cat_id'],
  219. 'brand_id' => $good['brand_id'],
  220. 'companyNo' => $good['companyNo'],
  221. 'companyName' => $good['companyName'],
  222. 'good_unit' => $good['good_unit'],
  223. 'good_type' => $good['good_type'],
  224. 'moq' => $good['moq'],
  225. 'is_exclusive' => 0,
  226. 'customized' => $good['customized'],
  227. 'tax' => $good['tax'],
  228. 'supplierNo' => $good['supplierNo'],
  229. 'supplierName' => $good['supplierName'],
  230. 'is_auth' => $good['is_auth'],
  231. 'auth_img' => $good['auth_img'],
  232. 'is_stock' => 1,
  233. 'after_sales' => '',
  234. 'craft_desc' => $good['craft_desc'],
  235. 'good_remark' => $good['good_remark'],
  236. 'good_size' => '',
  237. 'weight' => $good['weight'],
  238. 'packing_way' => '',
  239. 'packing_size' => '',
  240. 'packing_spec' => '',
  241. 'packing_list' => '',
  242. 'packing_weight' => 0,
  243. 'good_bar' => '',
  244. 'supply_area' => $good['supply_area'],
  245. 'delivery_place' => '',
  246. 'origin_place' => '',
  247. 'delivery_day' => '',
  248. 'lead_time' => '',
  249. 'sample_day' => '',
  250. 'sample_fee' => '',
  251. 'good_img' => $good['good_img'],
  252. 'good_thumb_img' => $good['good_thumb_img'],
  253. 'good_info_img' => $good['good_info_img'],
  254. 'cert_fee' => 0,
  255. 'packing_fee' => 0,
  256. 'cost_fee' => 0,
  257. 'mark_fee' => 0,
  258. 'demo_fee' => 0,
  259. 'open_fee' => 0,
  260. 'noble_metal' => $good['noble_metal'],
  261. 'noble_weight' => 0,
  262. 'is_gold_price' => $good['is_gold_price'],
  263. 'cgd_gold_price' => 0,
  264. 'market_price' => 0,
  265. 'nake_price' => 0,
  266. 'is_step' => 0,
  267. 'is_online' => 0,
  268. 'status' => 0,
  269. 'createrid' => $good['createrid'],
  270. 'creater' => $good['creater'],
  271. 'field_change' => '',
  272. 'is_del' => 0,
  273. 'addtime' => $date,
  274. 'updatetime' => $date,
  275. 'is_diff' => 0,
  276. 'config' => '',
  277. 'other_config' => '',
  278. 'stock_moq' => 0,
  279. 'is_support_barter' => 1,
  280. 'chargerid' => $good['createrid'],
  281. 'charger' => $good['creater'],
  282. 'is_support_stock' => 1
  283. ]);
  284. }
  285. }
  286. if (!empty($good)) {
  287. //关联表增数据
  288. Db::name('good_change_stock')
  289. ->insert([
  290. 'old_spuCode' => $order_return['good_code'],
  291. 'old_order_type' => $order_return['order_type'],
  292. 'spuCode' => $spuCode,
  293. 'addtime' => $date,
  294. 'updatetime' => $date,
  295. ]);
  296. } else throw new Exception('未找到对应的商品数据');
  297. }
  298. //新增bn记录,维护旧有bn记录
  299. $child_bns = Db::name('child_bn')
  300. ->field('id,num,origin_price')
  301. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode']])
  302. ->order(['num' => 'desc', 'id' => 'asc'])
  303. ->cursor();
  304. $origin_price = $j = 0;
  305. foreach ($child_bns as $child_bn) {
  306. if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
  307. Db::name('child_bn')
  308. ->where(['id' => $child_bn['id']])
  309. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  310. ->update(['updatetime' => $date]);
  311. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  312. if ($total == 0) break;
  313. }
  314. foreach ($param['list'] as $value) {
  315. if ($value['can_sell_num'] > 0) {
  316. $stockid = Db::name('good_stock')
  317. ->insertGetId([
  318. 'project_code' => '',
  319. 'spuCode' => $spuCode,
  320. 'wsm_code' => $info[$value['id']]['return_wsm_code'],
  321. 'wait_in_stock' => 0,
  322. 'wait_out_stock' => 0,
  323. 'usable_stock' => $value['can_sell_num'],
  324. 'intra_stock' => 0,
  325. 'total_stock' => $value['can_sell_num'],
  326. 'status' => 1,
  327. 'is_del' => 0,
  328. 'warn_stock' => 0,
  329. 'addtime' => $date,
  330. 'updatetime' => $date,
  331. ]);
  332. Db::name('good_stock_info')
  333. ->insert([
  334. 'stockid' => $stockid,
  335. 'bnCode' => substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
  336. 'total_num' => $value['can_sell_num'],
  337. 'used_num' => 0,
  338. 'balance_num' => $value['can_sell_num'],
  339. 'origin_price' => $origin_price,
  340. 'addtime' => $date,
  341. 'updatetime' => $date,
  342. ]);
  343. }
  344. }
  345. } else {
  346. //库存品,直接维护stock和info
  347. $stockids = Db::name('good_stock')
  348. ->where(['is_del' => 0, 'spuCode' => $order_return['good_code'], 'wsm_code' => array_column($info, 'return_wsm_code')])
  349. ->column('id', 'wsm_code');
  350. foreach ($param['list'] as $value) {
  351. //定义了stockid,维护bn
  352. if (isset($stockids[$info[$value['id']]['return_wsm_code']])) {
  353. $good_stock_info = Db::name('good_stock_info')
  354. ->where(['stockid' => $stockids[$info[$value['id']]['return_wsm_code']]])
  355. ->findOrEmpty();
  356. if (empty($good_stock_info)) {
  357. //从child_bn查询bn号并维护,新建到good_stock_info中
  358. $child_bns = Db::name('child_bn')
  359. ->field('id,num,bnCode,origin_price')
  360. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode'], 'childCode' => $info[$value['id']]['outChildCode']])
  361. ->order(['num' => 'desc', 'id' => 'asc'])
  362. ->cursor();
  363. $total = $value['can_sell_num'];
  364. foreach ($child_bns as $child_bn) {
  365. Db::name('child_bn')
  366. ->where(['id' => $child_bn['id']])
  367. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  368. ->update(['updatetime' => $date]);
  369. Db::name('good_stock_info')
  370. ->insert([
  371. 'stockid' => $stockids[$info[$value['id']]['return_wsm_code']],
  372. 'bnCode' => $child_bn['bnCode'],
  373. 'total_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  374. 'used_num' => 0,
  375. 'balance_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  376. 'origin_price' => $child_bn['origin_price'],
  377. 'addtime' => $date,
  378. 'updatetime' => $date,
  379. ]);
  380. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  381. if ($total == 0) break;
  382. }
  383. } else {
  384. //维护记录
  385. Db::name('good_stock_info')
  386. ->where(['id' => $good_stock_info['id']])
  387. ->inc('balance_num', $value['can_sell_num'])//可用数量增加
  388. ->dec('used_num', $value['can_sell_num'])//已用数量减少
  389. ->update(['updatetime' => $date]);
  390. }
  391. } else {
  392. //新建good_stock和good_stock_info
  393. $stockid = Db::name('good_stock')
  394. ->insertGetId([
  395. 'project_code' => '',
  396. 'spuCode' => $order_return['good_code'],
  397. 'wsm_code' => $value['return_wsm_code'],
  398. 'wait_in_stock' => 0,
  399. 'wait_out_stock' => 0,
  400. 'usable_stock' => $value['can_sell_num'],
  401. 'intra_stock' => 0,
  402. 'total_stock' => $value['can_sell_num'],
  403. 'status' => 1,
  404. 'is_del' => 0,
  405. 'warn_stock' => 0,
  406. 'addtime' => $date,
  407. 'updatetime' => $date,
  408. ]);
  409. //从child_bn查询bn号并维护,新建到good_stock_info中
  410. $child_bns = Db::name('child_bn')
  411. ->field('id,num,bnCode,origin_price')
  412. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode'], 'childCode' => $info[$value['id']]['outChildCode']])
  413. ->order(['num' => 'desc', 'id' => 'asc'])
  414. ->cursor();
  415. $total = $value['can_sell_num'];
  416. foreach ($child_bns as $child_bn) {
  417. Db::name('child_bn')
  418. ->where(['id' => $child_bn['id']])
  419. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  420. ->update(['updatetime' => $date]);
  421. Db::name('good_stock_info')
  422. ->insert([
  423. 'stockid' => $stockid,
  424. 'bnCode' => $child_bn['bnCode'],
  425. 'total_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  426. 'used_num' => 0,
  427. 'balance_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  428. 'origin_price' => $child_bn['origin_price'],
  429. 'addtime' => $date,
  430. 'updatetime' => $date,
  431. ]);
  432. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  433. if ($total == 0) break;
  434. }
  435. }
  436. }
  437. //维护商品层面的库存数
  438. Db::name('good')
  439. ->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
  440. ->inc('usable_stock', array_sum(array_column($info, 'return_num')) - array_sum(array_column($param['list'], 'loss_num')))
  441. ->update(['updatetime' => $date]);
  442. }
  443. }
  444. //售后申请单状态维护
  445. Db::name('order_return')
  446. ->where(['is_del' => 0, 'returnCode' => $param['returnCode'], 'status' => 12])
  447. ->update(['status' => 5, 'updatetime' => $date]);
  448. Db::commit();
  449. return json_show(0, '库管收货成功');
  450. } catch (Exception $exception) {
  451. Db::rollback();
  452. return json_show(1004, $exception->getMessage());
  453. }
  454. }
  455. //更新退货工单标记
  456. public function setRecord()
  457. {
  458. $param = $this->request->only(['id', 'record'], 'post', 'trim');
  459. $val = Validate::rule([
  460. 'id|退货工单id' => 'require|number|gt:0',
  461. 'record|标记内容' => 'require',
  462. ]);
  463. if ($val->check($param) == false) return json_show(1004, $val->getError());
  464. $temp = Db::name('order_return_child')
  465. ->field('id')
  466. ->where(['is_del' => 0, 'id' => $param['id']])
  467. ->findOrEmpty();
  468. if (empty($temp)) return json_show(1004, '该退货工单不存在');
  469. $rs = Db::name('order_return_child')
  470. ->where(['is_del' => 0, 'id' => $param['id']])
  471. ->update(['record' => $param['record'], 'updatetime' => date('Y-m-d H:i:s')]);
  472. return $rs ? json_show(0, '更新退货工单标记内容成功') : json_show(1004, '更新退货工单标记内容失败');
  473. }
  474. //详情
  475. public function info()
  476. {
  477. $param = $this->request->only(['id'], 'post', 'trim');
  478. $val = Validate::rule([
  479. 'id|退货工单id' => 'require|number|gt:0',
  480. ]);
  481. if ($val->check($param) == false) return json_show(1004, $val->getError());
  482. $info = Db::name('order_return_child')
  483. ->alias('a')
  484. ->field('a.*,b.supplierName send_supplierName,b.supplierNo send_supplierNo,b.name send_wsm_name,b.contactor_name send_contactor_name,c.supplierName return_supplierName,c.supplierNo return_supplierNo,c.name return_wsm_name,c.contactor_name return_contactor_name,d.companyNo,d.companyName,d.customer_code,d.customer_name,d.order_type,d.good_code spuCode')
  485. ->leftJoin('warehouse_info b', 'b.wsm_code=a.send_wsm_code')
  486. ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
  487. ->leftJoin('order_return d', 'd.returnCode=a.returnCode and d.is_del=0')
  488. ->where(['a.is_del' => 0, 'a.id' => $param['id']])
  489. ->findOrEmpty();
  490. if (empty($info)) return json_show(1004, '该退货工单不存在');
  491. return empty($info) ? json_show(1004, '该退货工单不存在') : json_show(0, '获取退货工单详情成功', $info);
  492. }
  493. }