OrderOutChild.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <?php
  2. namespace app\admin\controller;
  3. //发货工单(从属于发货单)
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\GoodStockInfo;
  6. use think\Exception;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. class OrderOutChild extends Base
  10. {
  11. //分单时可用仓库列表
  12. public function getWsmList()
  13. {
  14. $outCode = $this->request->post('outCode', '', 'trim');
  15. if ($outCode == '') return json_show(1004, '发货单号不能为空');
  16. $out = Db::name('order_out')
  17. ->alias('a')
  18. ->field('a.id,a.outCode,a.send_status,b.good_code')
  19. ->leftJoin('sale b', 'b.orderCode=a.orderCode')
  20. ->where(['a.is_del' => 0, 'a.outCode' => $outCode])
  21. ->findOrEmpty();
  22. if (empty($out)) return json_show(1004, '该发货单不存在');
  23. if ($out['send_status'] != 0) return json_show(1004, '该发货单状态错误');
  24. $list = Db::name("good_stock")
  25. ->alias("a")
  26. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  27. ->field("a.id,a.wsm_code,b.name wsm_name,b.companyNo,b.companyName,b.supplierNo,b.supplierName,b.contactor_name,a.usable_stock")
  28. ->where(["spuCode" => $out['good_code'], "a.is_del" => 0])
  29. ->order(['id' => 'asc'])
  30. ->select()
  31. ->toArray();
  32. return json_show(0, '获取列表成功', $list);
  33. }
  34. //发货工单列表
  35. public function list()
  36. {
  37. $param = $this->request->only([
  38. 'page' => 1,
  39. 'size' => 10,
  40. 'start' => '',
  41. 'end' => '',
  42. 'orderCode' => '',
  43. 'customer_code' => '',
  44. 'status' => '',
  45. 'outChildCode' => '',
  46. 'companyNo' => '',
  47. 'spuCode' => '',
  48. 'outCode' => '',
  49. 'order_source' => '',
  50. 'wsm_code' => '',
  51. 'supplierNo' => '',
  52. 'skuCode' => '',
  53. 'apply_id' => '',
  54. 'apply_name' => '',
  55. 'order_type' => '',
  56. 'relaComNo' => '',
  57. ], 'post', 'trim');
  58. $where = [['a.is_del', '=', 0]];
  59. if ($param['start'] != '') $where[] = ['a.addtime', '>=', $param['start']];
  60. if ($param['end'] != '') $where[] = ['a.addtime', '<', $param['end'] . ' 23:59:59'];
  61. if ($param['orderCode'] != '') $where[] = ['a.orderCode', 'like', '%' . $param['orderCode'] . '%'];
  62. if ($param['customer_code'] != '') $where[] = ['a.customer_code', 'like', '%' . $param['customer_code'] . '%'];
  63. if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
  64. if ($param['outChildCode'] != '') $where[] = ['a.outChildCode', 'like', '%' . $param['outChildCode'] . '%'];
  65. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  66. if ($param['spuCode'] != '') $where[] = ['a.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  67. if ($param['outCode'] != '') $where[] = ['a.outCode', 'like', '%' . $param['outCode'] . '%'];
  68. if ($param['order_source'] != '') $where[] = ['a.order_source', '=', $param['order_source']];
  69. if ($param['wsm_code'] != '') $where[] = ['a.wsm_code', 'like', '%' . $param['wsm_code'] . '%'];
  70. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  71. if ($param['skuCode'] != '') $where[] = ['a.skuCode', 'like', '%' . $param['skuCode'] . '%'];
  72. if ($param['apply_id'] !== '') $where[] = ['a.apply_id', '=', $param['apply_id']];
  73. if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
  74. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  75. if ($param['relaComNo'] != '') $where[] = ['a.companyNo', '=', $param['relaComNo']];
  76. $condition = '';
  77. //只有level2的账号过滤数据权限
  78. if ($this->level == 2) {
  79. //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
  80. //是否是仓库管理员
  81. $tmp = Db::name('warehouse_info')->field('id')->where(['is_del' => 0, 'contactor' => $this->uid])->findOrEmpty();
  82. //库管看到所有的库存品发货申请单
  83. if (!empty($tmp)) $condition .= " a.order_type=1 AND c.contactor=" . $this->uid;
  84. else {
  85. $role = $this->checkDataShare();
  86. if (!empty($role[DataGroupModel::$type_全部])) {
  87. if ($condition != '') $condition .= " or ";
  88. $condition .= " a.apply_id in (" . implode(',', $role[DataGroupModel::$type_全部]) . ")";
  89. }
  90. }
  91. $person_supplier = Db::connect('mysql_sys')
  92. ->name('supplier')
  93. ->where(['is_del' => 0, 'personid' => $this->uid])
  94. ->column('code');
  95. if ($person_supplier) {
  96. if ($condition != '') $condition .= " or ";
  97. $condition .= "(a.order_type<>1 and a.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
  98. }
  99. }
  100. $count = Db::name('order_out_child')
  101. ->alias('a')
  102. ->leftJoin('warehouse_info c', 'c.wsm_code=a.wsm_code AND c.is_del=0')
  103. ->where($where)
  104. ->where($condition)
  105. ->count('a.id');
  106. $list = Db::name('order_out_child')
  107. ->alias('a')
  108. ->field('a.*,c.supplierNo wsm_supplierNo,c.supplierName wsm_supplierName,c.name wsm_name,c.contactor_name')
  109. ->leftJoin('warehouse_info c', 'c.wsm_code=a.wsm_code AND c.is_del=0')
  110. ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
  111. ->page($param['page'], $param['size'])
  112. ->where($where)
  113. ->where($condition)
  114. ->select()
  115. ->toArray();
  116. $all_apply_id = array_column($list, 'apply_id');
  117. $company_name = get_company_name_by_uid($all_apply_id);
  118. //校验是否开通了供应商账号
  119. $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list, 'supplierNo')));
  120. $data = [];
  121. foreach ($list as $value) {
  122. $value['company_name'] = $company_name[$value['apply_id']] ?? '';
  123. $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
  124. $data[] = $value;
  125. }
  126. return json_show(0, '获取成功', ['count' => $count, 'list' => $data]);
  127. }
  128. //导出
  129. public function export()
  130. {
  131. $param = $this->request->only([
  132. 'start' => '',
  133. 'end' => '',
  134. 'orderCode' => '',
  135. 'customer_code' => '',
  136. 'status' => '',
  137. 'outChildCode' => '',
  138. 'companyNo' => '',
  139. 'spuCode' => '',
  140. 'outCode' => '',
  141. 'order_source' => '',
  142. 'wsm_code' => '',
  143. 'supplierNo' => '',
  144. 'skuCode' => '',
  145. 'apply_id' => '',
  146. 'apply_name' => '',
  147. 'order_type' => '',
  148. ], 'post', 'trim');
  149. $where = [['a.is_del', '=', 0]];
  150. if ($param['start'] != '') $where[] = ['a.addtime', '>=', $param['start']];
  151. if ($param['end'] != '') $where[] = ['a.addtime', '<', $param['end'] . ' 23:59:59'];
  152. if ($param['orderCode'] != '') $where[] = ['a.orderCode', 'like', '%' . $param['orderCode'] . '%'];
  153. if ($param['customer_code'] != '') $where[] = ['a.customer_code', 'like', '%' . $param['customer_code'] . '%'];
  154. if ($param['status'] !== '') $where[] = ['a.status', '=', $param['status']];
  155. if ($param['outChildCode'] != '') $where[] = ['a.outChildCode', 'like', '%' . $param['outChildCode'] . '%'];
  156. if ($param['companyNo'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['companyNo'] . '%'];
  157. if ($param['spuCode'] != '') $where[] = ['a.spuCode', 'like', '%' . $param['spuCode'] . '%'];
  158. if ($param['outCode'] != '') $where[] = ['a.outCode', 'like', '%' . $param['outCode'] . '%'];
  159. if ($param['order_source'] != '') $where[] = ['a.order_source', '=', $param['order_source']];
  160. if ($param['wsm_code'] != '') $where[] = ['a.wsm_code', 'like', '%' . $param['wsm_code'] . '%'];
  161. if ($param['supplierNo'] != '') $where[] = ['a.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
  162. if ($param['skuCode'] != '') $where[] = ['a.skuCode', 'like', '%' . $param['skuCode'] . '%'];
  163. if ($param['apply_id'] !== '') $where[] = ['a.apply_id', '=', $param['apply_id']];
  164. if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
  165. if ($param['order_type'] != '') $where[] = ['a.order_type', '=', $param['order_type']];
  166. $list = Db::name('order_out_child')
  167. ->alias('a')
  168. ->field('a.outChildCode 发货工单号,a.orderCode 确认单编号,a.outCode 发货申请单号,a.companyNo 业务公司编号,a.companyName 业务公司名称,a.customer_code 客户编号,a.customer_name 客户名称,a.supplierNo 供应商编号,a.supplierName 供应商名称,a.spuCode 商品成本编号,a.skuCode 商品上线编号,a.good_name 商品名称,case a.order_source when 1 then "直接下单" when 2 then "咨询" when 3 then "项目" when 4 then "平台" when 5 then "有赞" when 6 then "售后补换货" when 7 then "报备转单" when 8 then "支付渠道" end "订单来源",case order_type when 1 then "备库" when 2 then "非库存" when 3 then "咨询商品" when 4 then "报备商品" end "商品类型",a.num 数量,case a.status when 1 then "待发货" when 2 then "发货完成" when 3 then "已收货" when 4 then "已全部退货" end "分单状态",a.addtime 下单时间,a.apply_name 申请人名称,a.post_name 物流公司,a.post_code 物流单号,a.post_fee 物流费用')
  169. ->order(['a.addtime' => 'desc', 'a.id' => 'desc'])
  170. ->where($where)
  171. ->select()
  172. ->toArray();
  173. // $all_apply_id = array_column($list, 'apply_id');
  174. // $company_name = get_company_name_by_uid($all_apply_id);
  175. // $data = [];
  176. // foreach ($list as &$value) {
  177. //
  178. // $value['company_name'] = $company_name[$value['apply_id']] ?? '';
  179. // unset($value['apply_id']);
  180. //
  181. // }
  182. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  183. excelSave('发货工单' . date('YmdHis'), array_keys($list[0]), $list);
  184. // return json_show(0, '获取成功', $data);
  185. }
  186. //拆单
  187. public function add()
  188. {
  189. $param = $this->request->only(['outCode', 'list'], 'post', 'trim');
  190. $val = Validate::rule([
  191. 'outCode|发货单号' => 'require',
  192. 'list' => 'require|array|max:100',
  193. ]);
  194. // $list=[
  195. // ['wsm_code'=>'','num'=>100],
  196. // ['wsm_code'=>'','num'=>100],
  197. // ];
  198. if ($val->check($param) == false) return json_show(1004, $val->getError());
  199. $val_child = Validate::rule([
  200. 'wsm_code|仓库编码' => 'require',
  201. 'num|发货数量' => 'require|number|gt:0|elt:999999999999',
  202. ]);
  203. $info = Db::name('order_out')
  204. ->alias('a')
  205. ->field('a.*,b.supplierNo companyNo,b.supplierName companyName,b.customer_code,b.customerName,b.supNo supplierNo,b.supName supplierName,b.good_code,b.skuCode,b.good_name,b.order_source,b.good_num,b.wsend_num')
  206. ->leftJoin('sale b', 'b.orderCode=a.orderCode AND b.is_del=0')
  207. ->where(['a.is_del' => 0, 'a.outCode' => $param['outCode'], 'a.send_status' => 1])
  208. ->findOrEmpty();
  209. if (empty($info)) return json_show(1004, '该发货单不存在或状态有误');
  210. if ($info['wsend_num'] < $info['send_num']) return json_show(1004, "订单待发货数量不足");
  211. if ($info['wsend_num'] < array_sum(array_column($param['list'], 'num'))) return json_show(1004, "仓库总发货数与发货单待发货数不同");
  212. //所有仓库信息
  213. $wsm = Db::name('good_stock')
  214. ->where(['is_del' => 0, 'spuCode' => $info['good_code'], 'wsm_code' => array_column($param['list'], 'wsm_code')])
  215. ->column('id', 'wsm_code');
  216. Db::startTrans();
  217. try {
  218. $date = date('Y-m-d H:i:s');
  219. $insert = [];
  220. $i = 0;
  221. foreach ($param['list'] as $value) {
  222. if ($val_child->check($value) == false) throw new Exception($val_child->getError());
  223. //改变编码规则,将原编码后两位换成序列号
  224. //str_pad字符串填充
  225. $outChildCode = substr(makeNo('TCD'), 0, -2) . str_pad($i++, 2, '0', STR_PAD_LEFT);
  226. $insert[] = [
  227. 'outChildCode' => $outChildCode,
  228. 'orderCode' => $info['orderCode'],
  229. 'outCode' => $param['outCode'],
  230. 'companyNo' => $info['companyNo'],
  231. 'companyName' => $info['companyName'],
  232. 'customer_code' => $info['customer_code'],
  233. 'customer_name' => $info['customerName'],
  234. 'supplierNo' => $info['supplierNo'],
  235. 'supplierName' => $info['supplierName'],
  236. 'spuCode' => $info['good_code'],
  237. 'skuCode' => $info['skuCode'],
  238. 'good_name' => $info['good_name'],
  239. 'order_type' => $info['order_type'],
  240. 'order_source' => $info['order_source'],
  241. 'num' => $value['num'],
  242. 'wsm_code' => $value['wsm_code'],
  243. 'apply_id' => $info['apply_id'],
  244. 'apply_name' => $info['apply_name'],
  245. 'addrid' => $info['addrid'],
  246. 'status' => 1,
  247. 'is_del' => 0,
  248. 'addtime' => $date,
  249. 'updatetime' => $date,
  250. ];
  251. if (!isset($wsm[$value['wsm_code']])) throw new Exception($value['wsm_code'] . '该仓库不存在');
  252. }
  253. Db::name('order_out_child')->insertAll($insert);
  254. foreach ($insert as $item) {
  255. GoodStockInfo::ChildAddBn($item['outChildCode'], $wsm[$value['wsm_code']]);//维护bn号
  256. }
  257. Db::name('order_out')
  258. ->where(['id' => $info['id'], 'is_del' => 0, 'outCode' => $param['outCode'], 'send_status' => 1])
  259. ->update(['send_status' => 2, 'status' => 1]);
  260. Db::commit();
  261. return json_show(0, '分单完成');
  262. } catch (Exception $exception) {
  263. Db::rollback();
  264. return json_show(1004, '分单失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  265. }
  266. }
  267. //详情
  268. public function info()
  269. {
  270. $outChildCode = $this->request->post('outChildCode', '', 'trim');
  271. if ($outChildCode == '') return json_show(1004, '发货工单号不能为空');
  272. $info = Db::name('order_out_child')
  273. ->alias('a')
  274. ->field('a.*,b.name wsm_name')
  275. ->leftJoin('warehouse_info b', 'b.wsm_code=a.wsm_code')
  276. ->where(['a.is_del' => 0, 'a.outChildCode' => $outChildCode])
  277. ->findOrEmpty();
  278. return json_show(0, '获取详情成功', $info);
  279. }
  280. //发货
  281. public function send()
  282. {
  283. if ($this->level == 1) return json_show(0, '管理员不能操作');
  284. $param = $this->request->post('list/a', '', 'trim');
  285. $temp = Db::name('order_out_child')
  286. ->field('id,outChildCode')
  287. ->where(['is_del' => 0, 'outChildCode' => array_column($param, 'outChildCode')])
  288. ->where('status', '<>', 1)
  289. ->findOrEmpty();
  290. if (!empty($temp)) return json_show(1004, $temp['outChildCode'] . '状态错误,不能发货');
  291. $child = Db::name('order_out_child')
  292. ->where(['is_del' => 0, 'status' => 1, 'outChildCode' => array_column($param, 'outChildCode')])
  293. ->column('id,orderCode,outCode,num,wsm_code,supplierNo', 'outChildCode');
  294. //检查所有的发货单是否有正在进行的售后单
  295. $temp = Db::name('order_return')
  296. ->where(['is_del' => 0, 'outCode' => array_unique(array_column($child, 'outCode'))])
  297. ->whereNotIn('status', [5, 6, 8])
  298. ->field('id,outCode')
  299. ->findOrEmpty();
  300. if (!empty($temp)) return json_show(1004, $temp['outCode'] . '有正在进行中的售后单,无法发货');
  301. $order_out = Db::name('order_out')
  302. ->where(['is_del' => 0, 'outCode' => array_unique(array_column($child, 'outCode'))])
  303. ->column('id,send_num,send_status,0 already_send_num', 'outCode');
  304. $sale = Db::name('sale')
  305. ->where(['is_del' => 0, 'orderCode' => array_unique(array_column($child, 'orderCode'))])
  306. ->column('id,good_num,send_num,wsend_num,good_code,supNo,is_stock,order_source', 'orderCode');
  307. $is_reurn = Db::name("sale_return")
  308. ->field('id,orderCode')
  309. ->where(['orderCode' => array_column($child, 'orderCode'), 'is_del' => 0])
  310. ->where("status", "in", [1, 2, 3, 7, 8, 9, 10, 11, 12])
  311. ->findOrEmpty();
  312. if (!empty($is_reurn)) return json_show(1004, $is_reurn['orderCode'] . "存在退货未处理完成");
  313. //判断供应商是否开通账号,若开通的话,则只能由供应商账号操作
  314. if ($this->level != 3) {
  315. $temp = checkHasAccountBySupplierNos(array_column($sale, 'supNo'));
  316. if (!empty($temp)) return json_show(1004, implode(',', array_keys($temp)) . '这些供应商已经开通账号,请使用供应商账号操作');
  317. }
  318. $val = Validate::rule([
  319. 'outChildCode|发货工单号' => 'require|max:255',
  320. 'post_name|物流公司' => 'require|max:255',
  321. 'post_code|物流单号' => 'require|alphaDash|max:255',
  322. 'post_fee|物流费用' => 'require|egt:0|max:99999999.99'
  323. ]);
  324. Db::startTrans();
  325. try {
  326. $date = date('Y-m-d H:i:s');
  327. //所有供应商负责人
  328. $userCommon = \app\admin\common\User::getIns();
  329. $person_temp = $userCommon->handle('sGetList', ['more_code' => array_unique(array_column($child, 'supplierNo'))]);
  330. $person = array_column($person_temp['data']['list'], 'personid', 'code');
  331. unset($userCommon);
  332. unset($person_temp);
  333. //所有仓库管理员
  334. $wsm_contactor = Db::name('warehouse_info')
  335. ->where(['is_del' => 0, 'wsm_code' => array_unique(array_column($child, 'wsm_code'))])
  336. ->column('contactor', 'wsm_code');
  337. $yz_tmp = [];
  338. foreach ($param as $value) {
  339. if ($val->check($value) == false) throw new Exception($val->getError());
  340. //如果是库存品,只能由库管操作
  341. //非库存品和采返商品只能由供应商负责人操作
  342. if ($this->level == 2) {
  343. if ($sale[$child[$value['outChildCode']]['orderCode']]['is_stock'] == 1) {
  344. if ($this->uid != $wsm_contactor[$child[$value['outChildCode']]['wsm_code']]) throw new Exception('库存品只能由仓库管理员操作');
  345. } else {
  346. if ($this->uid != $person[$child[$value['outChildCode']]['supplierNo']]) throw new Exception('非库存品和采返商品只能由供应商负责人操作');
  347. }
  348. }
  349. //工单
  350. if (!isset($child[$value['outChildCode']])) throw new Exception($value['outChildCode'] . '工单不存在或状态不允许发货');
  351. Db::name('order_out_child')
  352. ->where(['id' => $child[$value['outChildCode']]['id'], 'is_del' => 0, 'status' => 1])
  353. ->update([
  354. 'post_name' => $value['post_name'],
  355. 'post_code' => $value['post_code'],
  356. 'post_fee' => $value['post_fee'],
  357. 'status' => 2,
  358. 'sendtime' => $date,
  359. 'updatetime' => $date,
  360. ]);
  361. $order_out[$child[$value['outChildCode']]['outCode']]['already_send_num'] += $child[$value['outChildCode']]['num'];
  362. //发货单
  363. //send_status 3部分发货,4全部发货
  364. Db::name('order_out')
  365. ->where(['id' => $order_out[$child[$value['outChildCode']]['outCode']]['id']])
  366. ->update(['send_status' => $order_out[$child[$value['outChildCode']]['outCode']]['already_send_num'] >= $order_out[$child[$value['outChildCode']]['outCode']]['send_num'] ? 4 : 3, 'status' => 2, 'updatetime' => $date]);
  367. $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] += $child[$value['outChildCode']]['num'];
  368. $sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'] -= $child[$value['outChildCode']]['num'];
  369. //销售单
  370. $send_status = $sale[$child[$value['outChildCode']]['orderCode']]['send_num'] >= $sale[$child[$value['outChildCode']]['orderCode']]['good_num'] ? 4 : 3;
  371. Db::name('sale')
  372. ->where(['is_del' => 0, 'id' => $sale[$child[$value['outChildCode']]['orderCode']]['id']])
  373. ->update([
  374. 'send_num' => $sale[$child[$value['outChildCode']]['orderCode']]['send_num'],
  375. 'wsend_num' => $sale[$child[$value['outChildCode']]['orderCode']]['wsend_num'],
  376. 'send_status' => $send_status,
  377. ]);
  378. if ($sale[$child[$value['outChildCode']]['orderCode']]['order_source'] == 5 && $send_status == 4) {
  379. $yz_tmp[] = [
  380. 'post_name' => $value['post_name'],
  381. 'post_code' => $value['post_code'],
  382. 'outCode' => $child[$value['outChildCode']]['outCode'],
  383. 'orderCode' => $child[$value['outChildCode']]['orderCode'],
  384. ];
  385. }
  386. //库存
  387. Db::name('good_stock')
  388. ->where(['is_del' => 0, 'spuCode' => $sale[$child[$value['outChildCode']]['orderCode']]['good_code'], 'wsm_code' => $child[$value['outChildCode']]['wsm_code']])
  389. ->dec('wait_out_stock', $child[$value['outChildCode']]['num'])
  390. ->update(['updatetime' => $date]);
  391. }
  392. //日志、待办已办……
  393. Db::commit();
  394. //如果是有赞订单 且 所属发货单全部发货了,将发货信息推到有赞
  395. //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
  396. foreach ($yz_tmp as $temp) {
  397. curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $temp['orderCode'], 'out_stype' => $temp['post_name'], 'post_code' => $temp['post_code'], 'uid' => $this->uid, 'uname' => $this->uname, 'order_out' => $temp['outCode']]);
  398. }
  399. // if ($einfo['order_source'] == 5) {
  400. // $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $einfo['orderCode'], 'out_stype' => $post_name, 'post_code' => $post_code, 'uid' => $uid, 'uname' => $uname, 'order_out' => $outCode]);
  401. // $res = json_decode($res, true);
  402. // if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
  403. // }
  404. return json_show(0, '操作完成');
  405. } catch (Exception $exception) {
  406. Db::rollback();
  407. return json_show(1004, $exception->getMessage());
  408. }
  409. }
  410. }