AfterChild.php 30 KB

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