AfterChild.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. ->where(['a.is_del' => 0, 'a.returnCode' => $param['returnCode'], 'a.id' => array_column($param['list'], 'id')])
  157. ->column('a.id,a.return_wsm_code,a.outChildCode,b.wsm_code,a.status,a.return_num', 'a.id');
  158. if (empty($info)) return json_show(1004, '退货工单不存在');
  159. $val_child = Validate::rule([
  160. 'id|退货工单id' => 'require|gt:0|max:999999999',
  161. 'can_sell_num|销售仓入库数量' => 'require|number|egt:0|max:999999999999',
  162. 'defective_num|次品仓入库数量' => 'require|number|egt:0|max:999999999999',
  163. 'loss_num|丢失数量' => 'require|number|egt:0|max:999999999999',
  164. 'remark|备注' => 'max:255'
  165. ]);
  166. Db::startTrans();
  167. try {
  168. $date = date('Y-m-d H:i:s');
  169. foreach ($param['list'] as $value) {
  170. if ($val_child->check($value) == false) throw new Exception($val_child->getError());
  171. if (!isset($info[$value['id']])) throw new Exception($value['id'] . '退货工单不存在');
  172. if ($info[$value['id']]['status'] != 1) throw new Exception($value['id'] . '退货工单状态有误');
  173. //退货工单
  174. Db::name('order_return_child')
  175. ->where(['is_del' => 0, 'id' => $value['id']])
  176. ->update([
  177. 'can_sell_num' => $value['can_sell_num'],
  178. 'defective_num' => $value['defective_num'],
  179. 'loss_num' => $value['loss_num'],
  180. 'remark' => $value['remark'] ?? '',
  181. 'updatetime' => $date,
  182. 'status' => 2
  183. ]);
  184. //发货工单数量减少
  185. Db::name('order_out_child')
  186. ->where(['is_del' => 0, 'outChildCode' => $info[$value['id']]['outChildCode']])
  187. ->dec('num', $info[$value['id']]['return_num'])
  188. ->update(['updatetime' => $date]);
  189. }
  190. $total = array_sum(array_column($param['list'], 'can_sell_num'));
  191. if ($total > 0) {
  192. if ($order_return['is_stock'] != 1) {
  193. //根据转化表判断该非库存品是否转化为库存品
  194. $spuCode = Db::name('good_change_stock')
  195. ->where(['old_spuCode' => $order_return['good_code'], 'old_order_type' => $order_return['order_type']])
  196. ->value('spuCode', '');
  197. if ($spuCode == '') {
  198. //将非库存品转化为库存品
  199. $spuCode = makeNo('SKU');
  200. if ($order_return['order_type'] == 2) {
  201. $good = Db::name('good_basic')
  202. ->where('spuCode', $order_return['good_code'])
  203. ->findOrEmpty();
  204. if (!empty($good)) {
  205. Db::name('good_basic')->insert(array_merge($good, [
  206. 'id' => null,
  207. 'spuCode' => $spuCode,
  208. 'addtime' => $date,
  209. 'updatetime' => $date,
  210. ]));
  211. }
  212. } else {
  213. $good = Db::name('good_zixun')
  214. ->where(['spuCode'=>$order_return['good_code']])
  215. ->findOrEmpty();
  216. if (!empty($good)) {
  217. Db::name('good_basic')->insert([
  218. 'spuCode' => $spuCode,
  219. 'good_code' => $good['good_code'],
  220. 'good_name' => $good['good_name'],
  221. 'cat_id' => $good['cat_id'],
  222. 'brand_id' => $good['brand_id'],
  223. 'companyNo' => $good['companyNo'],
  224. 'companyName' => $good['companyName'],
  225. 'good_unit' => $good['good_unit'],
  226. 'good_type' => $good['good_type'],
  227. 'moq' => $good['moq'],
  228. 'is_exclusive' => 0,
  229. 'customized' => $good['customized'],
  230. 'tax' => $good['tax'],
  231. 'supplierNo' => $good['supplierNo'],
  232. 'supplierName' => $good['supplierName'],
  233. 'is_auth' => $good['is_auth'],
  234. 'auth_img' => $good['auth_img'],
  235. 'is_stock' => 1,
  236. 'after_sales' => '',
  237. 'craft_desc' => $good['craft_desc'],
  238. 'good_remark' => $good['good_remark'],
  239. 'good_size' => '',
  240. 'weight' => $good['weight'],
  241. 'packing_way' => '',
  242. 'packing_size' => '',
  243. 'packing_spec' => '',
  244. 'packing_list' => '',
  245. 'packing_weight' => 0,
  246. 'good_bar' => '',
  247. 'supply_area' => $good['supply_area'],
  248. 'delivery_place' => '',
  249. 'origin_place' => '',
  250. 'delivery_day' => '',
  251. 'lead_time' => '',
  252. 'sample_day' => '',
  253. 'sample_fee' => '',
  254. 'good_img' => $good['good_img'],
  255. 'good_thumb_img' => $good['good_thumb_img'],
  256. 'good_info_img' => $good['good_info_img'],
  257. 'cert_fee' => 0,
  258. 'packing_fee' => 0,
  259. 'cost_fee' => 0,
  260. 'mark_fee' => 0,
  261. 'demo_fee' => 0,
  262. 'open_fee' => 0,
  263. 'noble_metal' => $good['noble_metal'],
  264. 'noble_weight' => 0,
  265. 'is_gold_price' => $good['is_gold_price'],
  266. 'cgd_gold_price' => 0,
  267. 'market_price' => 0,
  268. 'nake_price' => 0,
  269. 'is_step' => 0,
  270. 'is_online' => 0,
  271. 'status' => 0,
  272. 'createrid' => $good['createrid'],
  273. 'creater' => $good['creater'],
  274. 'field_change' => '',
  275. 'is_del' => 0,
  276. 'addtime' => $date,
  277. 'updatetime' => $date,
  278. 'is_diff' => 0,
  279. 'config' => '',
  280. 'other_config' => '',
  281. 'stock_moq' => 0,
  282. 'is_support_barter' => 1,
  283. 'chargerid' => $good['createrid'],
  284. 'charger' => $good['creater'],
  285. 'is_support_stock' => 1
  286. ]);
  287. }
  288. }
  289. if (!empty($good)) {
  290. //关联表增数据
  291. Db::name('good_change_stock')
  292. ->insert([
  293. 'old_spuCode' => $order_return['good_code'],
  294. 'old_order_type' => $order_return['order_type'],
  295. 'spuCode' => $spuCode,
  296. 'addtime' => $date,
  297. 'updatetime' => $date,
  298. ]);
  299. } else throw new Exception('未找到对应的商品数据');
  300. }
  301. //新增bn记录,维护旧有bn记录
  302. $child_bns = Db::name('child_bn')
  303. ->field('id,num,origin_price')
  304. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode']])
  305. ->order(['num' => 'desc', 'id' => 'asc'])
  306. ->cursor();
  307. $origin_price = $j = 0;
  308. foreach ($child_bns as $child_bn) {
  309. if ($origin_price === 0) $origin_price = $child_bn['origin_price'];
  310. Db::name('child_bn')
  311. ->where(['id' => $child_bn['id']])
  312. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  313. ->update(['updatetime' => $date]);
  314. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  315. if ($total == 0) break;
  316. }
  317. foreach ($param['list'] as $value) {
  318. if ($value['can_sell_num'] > 0) {
  319. $stockid = Db::name('good_stock')
  320. ->insertGetId([
  321. 'project_code' => '',
  322. 'spuCode' => $spuCode,
  323. 'wsm_code' => $info[$value['id']]['return_wsm_code'],
  324. 'wait_in_stock' => 0,
  325. 'wait_out_stock' => 0,
  326. 'usable_stock' => $value['can_sell_num'],
  327. 'intra_stock' => 0,
  328. 'total_stock' => $value['can_sell_num'],
  329. 'status' => 1,
  330. 'is_del' => 0,
  331. 'warn_stock' => 0,
  332. 'addtime' => $date,
  333. 'updatetime' => $date,
  334. ]);
  335. Db::name('good_stock_info')
  336. ->insert([
  337. 'stockid' => $stockid,
  338. 'bnCode' => substr(makeNo("BN"), 0, -2) . str_pad($j++, 2, '0', STR_PAD_LEFT),
  339. 'total_num' => $value['can_sell_num'],
  340. 'used_num' => 0,
  341. 'balance_num' => $value['can_sell_num'],
  342. 'origin_price' => $origin_price,
  343. 'addtime' => $date,
  344. 'updatetime' => $date,
  345. ]);
  346. }
  347. }
  348. } else {
  349. //库存品,直接维护stock和info
  350. $stockids = Db::name('good_stock')
  351. ->where(['is_del' => 0, 'spuCode' => $order_return['good_code'], 'wsm_code' => array_column($info, 'return_wsm_code')])
  352. ->column('id', 'wsm_code');
  353. foreach ($param['list'] as $value) {
  354. //定义了stockid,维护bn
  355. if (isset($stockids[$info[$value['id']]['return_wsm_code']])) {
  356. $good_stock_info = Db::name('good_stock_info')
  357. ->where(['stockid' => $stockids[$info[$value['id']]['return_wsm_code']]])
  358. ->findOrEmpty();
  359. if (empty($good_stock_info)) {
  360. //从child_bn查询bn号并维护,新建到good_stock_info中
  361. $child_bns = Db::name('child_bn')
  362. ->field('id,num,bnCode,origin_price')
  363. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode'], 'childCode' => $info[$value['id']]['outChildCode']])
  364. ->order(['num' => 'desc', 'id' => 'asc'])
  365. ->cursor();
  366. $total = $value['can_sell_num'];
  367. foreach ($child_bns as $child_bn) {
  368. Db::name('child_bn')
  369. ->where(['id' => $child_bn['id']])
  370. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  371. ->update(['updatetime' => $date]);
  372. Db::name('good_stock_info')
  373. ->insert([
  374. 'stockid' => $stockids[$info[$value['id']]['return_wsm_code']],
  375. 'bnCode' => $child_bn['bnCode'],
  376. 'total_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  377. 'used_num' => 0,
  378. 'balance_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  379. 'origin_price' => $child_bn['origin_price'],
  380. 'addtime' => $date,
  381. 'updatetime' => $date,
  382. ]);
  383. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  384. if ($total == 0) break;
  385. }
  386. } else {
  387. //维护记录
  388. Db::name('good_stock_info')
  389. ->where(['id' => $good_stock_info['id']])
  390. ->inc('balance_num', $value['can_sell_num'])//可用数量增加
  391. ->dec('used_num', $value['can_sell_num'])//已用数量减少
  392. ->update(['updatetime' => $date]);
  393. }
  394. } else {
  395. //新建good_stock和good_stock_info
  396. $stockid = Db::name('good_stock')
  397. ->insertGetId([
  398. 'project_code' => '',
  399. 'spuCode' => $order_return['good_code'],
  400. 'wsm_code' => $value['return_wsm_code'],
  401. 'wait_in_stock' => 0,
  402. 'wait_out_stock' => 0,
  403. 'usable_stock' => $value['can_sell_num'],
  404. 'intra_stock' => 0,
  405. 'total_stock' => $value['can_sell_num'],
  406. 'status' => 1,
  407. 'is_del' => 0,
  408. 'warn_stock' => 0,
  409. 'addtime' => $date,
  410. 'updatetime' => $date,
  411. ]);
  412. //从child_bn查询bn号并维护,新建到good_stock_info中
  413. $child_bns = Db::name('child_bn')
  414. ->field('id,num,bnCode,origin_price')
  415. ->where(['orderCode' => $order_return['orderCode'], 'outCode' => $order_return['outCode'], 'childCode' => $info[$value['id']]['outChildCode']])
  416. ->order(['num' => 'desc', 'id' => 'asc'])
  417. ->cursor();
  418. $total = $value['can_sell_num'];
  419. foreach ($child_bns as $child_bn) {
  420. Db::name('child_bn')
  421. ->where(['id' => $child_bn['id']])
  422. ->dec('num', ($child_bn['num'] >= $total) ? $total : $child_bn['num'])
  423. ->update(['updatetime' => $date]);
  424. Db::name('good_stock_info')
  425. ->insert([
  426. 'stockid' => $stockid,
  427. 'bnCode' => $child_bn['bnCode'],
  428. 'total_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  429. 'used_num' => 0,
  430. 'balance_num' => ($child_bn['num'] >= $total) ? $total : $child_bn['num'],
  431. 'origin_price' => $child_bn['origin_price'],
  432. 'addtime' => $date,
  433. 'updatetime' => $date,
  434. ]);
  435. $total = ($child_bn['num'] >= $total) ? 0 : ($total - $child_bn['num']);
  436. if ($total == 0) break;
  437. }
  438. }
  439. }
  440. //维护商品层面的库存数
  441. Db::name('good')
  442. ->where(['is_del' => 0, 'spuCode' => $order_return['good_code']])
  443. ->inc('usable_stock', array_sum(array_column($info, 'return_num')) - array_sum(array_column($param['list'], 'loss_num')))
  444. ->update(['updatetime' => $date]);
  445. }
  446. }
  447. //售后申请单状态维护
  448. Db::name('order_return')
  449. ->where(['is_del' => 0, 'returnCode' => $param['returnCode'], 'status' => 12])
  450. ->update(['status' => 5, 'updatetime' => $date]);
  451. Db::commit();
  452. return json_show(0, '库管收货成功');
  453. } catch (Exception $exception) {
  454. Db::rollback();
  455. return json_show(1004, $exception->getMessage());
  456. }
  457. }
  458. //更新退货工单标记
  459. public function setRecord()
  460. {
  461. $param = $this->request->only(['id', 'record'], 'post', 'trim');
  462. $val = Validate::rule([
  463. 'id|退货工单id' => 'require|number|gt:0',
  464. 'record|标记内容' => 'require',
  465. ]);
  466. if ($val->check($param) == false) return json_show(1004, $val->getError());
  467. $temp = Db::name('order_return_child')
  468. ->field('id')
  469. ->where(['is_del' => 0, 'id' => $param['id']])
  470. ->findOrEmpty();
  471. if (empty($temp)) return json_show(1004, '该退货工单不存在');
  472. $rs = Db::name('order_return_child')
  473. ->where(['is_del' => 0, 'id' => $param['id']])
  474. ->update(['record' => $param['record'], 'updatetime' => date('Y-m-d H:i:s')]);
  475. return $rs ? json_show(0, '更新退货工单标记内容成功') : json_show(1004, '更新退货工单标记内容失败');
  476. }
  477. //详情
  478. public function info()
  479. {
  480. $param = $this->request->only(['id'], 'post', 'trim');
  481. $val = Validate::rule([
  482. 'id|退货工单id' => 'require|number|gt:0',
  483. ]);
  484. if ($val->check($param) == false) return json_show(1004, $val->getError());
  485. $info = Db::name('order_return_child')
  486. ->alias('a')
  487. ->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')
  488. ->leftJoin('warehouse_info b', 'b.wsm_code=a.send_wsm_code')
  489. ->leftJoin('warehouse_info c', 'c.wsm_code=a.return_wsm_code')
  490. ->leftJoin('order_return d', 'd.returnCode=a.returnCode and d.is_del=0')
  491. ->where(['a.is_del' => 0, 'a.id' => $param['id']])
  492. ->findOrEmpty();
  493. if (empty($info)) return json_show(1004, '该退货工单不存在');
  494. return empty($info) ? json_show(1004, '该退货工单不存在') : json_show(0, '获取退货工单详情成功', $info);
  495. }
  496. }