|
@@ -132,75 +132,82 @@ class Reorder extends Base
|
|
|
Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . $date . "' WHERE `orderCode`='{$ordeCode}'");
|
|
|
|
|
|
//如果有退货地址,那么可能有发货单,可能有发货工单
|
|
|
- if ($returnadr != "") {
|
|
|
- $inf = [];
|
|
|
- foreach ($returnadr as $val) {
|
|
|
-
|
|
|
- if ($val['return_num'] == 0) continue;//当退货数量为0时,跳过
|
|
|
-
|
|
|
- $temp = [];
|
|
|
- $addrinfo = Db::name("order_addr")->where(['id' => $val['id'], "orderCode" => $ordeCode])->findOrEmpty();
|
|
|
- if ($addrinfo == false) throw new Exception("地址信息未找到");
|
|
|
-
|
|
|
- $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->findOrEmpty();
|
|
|
- if ($send['status'] >= 2) throw new Exception("地址已发货");
|
|
|
-
|
|
|
- if ($order['is_stock'] == 1) {
|
|
|
- if ($addrinfo['receipt_quantity'] < $val['return_num']) throw new Exception("地址发货数量不足");
|
|
|
-
|
|
|
- $addrinfo['receipt_quantity'] -= $val['return_num'];
|
|
|
- $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
|
|
|
- $addrinfo['updatetime'] = $date;
|
|
|
- $addrup = Db::name("order_addr")->save($addrinfo);
|
|
|
- if ($addrup == false) throw new Exception("地址发货数量更新失败");
|
|
|
-
|
|
|
- $out = Db::name("order_out")->where(["addrid" => $val['id']])->findOrEmpty();
|
|
|
- if ($out == false) throw new Exception("地址发货单数据未找到");
|
|
|
-
|
|
|
-// if ($send!=false) {
|
|
|
- if ($out['status'] >= 2) throw new Exception("地址发货单已发货");
|
|
|
+// if ($returnadr != "") {
|
|
|
+// $inf = [];
|
|
|
+// foreach ($returnadr as $val) {
|
|
|
+//
|
|
|
+// if ($val['return_num'] == 0) continue;//当退货数量为0时,跳过
|
|
|
+//
|
|
|
+// $temp = [];
|
|
|
+// $addrinfo = Db::name("order_addr")->where(['id' => $val['id'], "orderCode" => $ordeCode])->findOrEmpty();
|
|
|
+// if ($addrinfo == false) throw new Exception("地址信息未找到");
|
|
|
+//
|
|
|
+// $send = Db::name('order_out')->where([["addrid", "=", $val['id']]])->findOrEmpty();
|
|
|
+// if ($send['status'] >= 2) throw new Exception("地址已发货");
|
|
|
+//
|
|
|
+// if ($order['is_stock'] == 1) {
|
|
|
+// if ($addrinfo['receipt_quantity'] < $val['return_num']) throw new Exception("地址发货数量不足");
|
|
|
+//
|
|
|
+// $addrinfo['receipt_quantity'] -= $val['return_num'];
|
|
|
+// $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
|
|
|
+// $addrinfo['updatetime'] = $date;
|
|
|
+// $addrup = Db::name("order_addr")->save($addrinfo);
|
|
|
+// if ($addrup == false) throw new Exception("地址发货数量更新失败");
|
|
|
+//
|
|
|
+// $out = Db::name("order_out")->where(["addrid" => $val['id']])->findOrEmpty();
|
|
|
+// if ($out == false) throw new Exception("地址发货单数据未找到");
|
|
|
+//
|
|
|
+//// if ($send!=false) {
|
|
|
+// if ($out['status'] >= 2) throw new Exception("地址发货单已发货");
|
|
|
+//
|
|
|
+// if ($out['send_num'] < $val['return_num']) throw new Exception("地址发货单发货数量不足");
|
|
|
+//
|
|
|
+// $out['send_num'] -= $val['return_num'];
|
|
|
+// $out['is_del'] = $out['send_num'] == 0 ? 1 : 0;
|
|
|
+// $out['updatetime'] = $date;
|
|
|
+// $outup = Db::name("order_out")->save($out);
|
|
|
+// if ($outup == false) throw new Exception("地址发货单更新失败");
|
|
|
+//
|
|
|
+//
|
|
|
+//// $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
|
|
|
+//// if ($ordersend['send_num'] < $val['return_num']) {
|
|
|
+//// Db::rollback();
|
|
|
+//// return json_show(1004, "发货单发货数量不足");
|
|
|
+//// }
|
|
|
+//// $ordersend['send_num'] -= $val['return_num'];
|
|
|
+//// $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
|
|
|
+//// $ordersend['updatetime'] = $date;
|
|
|
+//// $sendip = Db::name("order_send")->save($ordersend);
|
|
|
+//// if ($sendip == false) {
|
|
|
+//// Db::rollback();
|
|
|
+//// return json_show(1004, "发货单更新失败");
|
|
|
+//// }
|
|
|
+//
|
|
|
+//// }
|
|
|
+// }
|
|
|
+// $temp['returnCode'] = $returnCode;
|
|
|
+// $temp['orderCode'] = $ordeCode;
|
|
|
+// $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
|
|
|
+// $temp['addrid'] = $val['id'];
|
|
|
+// $temp['send_num'] = $addrinfo['receipt_quantity'];
|
|
|
+// $temp['return_num'] = $val['return_num'];
|
|
|
+// $temp['is_del'] = 0;
|
|
|
+// $temp['addtime'] = $date;
|
|
|
+// $temp['updatetime'] = $date;
|
|
|
+// $inf[] = $temp;
|
|
|
+// }
|
|
|
+// $inadd = Db::name("sale_returnaddr")->insertAll($inf);
|
|
|
+// if ($inadd == 0) throw new Exception("退货单新建失败");
|
|
|
+// }
|
|
|
|
|
|
- if ($out['send_num'] < $val['return_num']) throw new Exception("地址发货单发货数量不足");
|
|
|
+ if ($in['status'] == 4 && $order['is_stock'] == 1) {
|
|
|
|
|
|
- $out['send_num'] -= $val['return_num'];
|
|
|
- $out['is_del'] = $out['send_num'] == 0 ? 1 : 0;
|
|
|
- $out['updatetime'] = $date;
|
|
|
- $outup = Db::name("order_out")->save($out);
|
|
|
- if ($outup == false) throw new Exception("地址发货单更新失败");
|
|
|
+ //未发货数量要减去发货单上的发货数量
|
|
|
+ $out_send_num = Db::name('order_out')
|
|
|
+ ->where(['is_del' => 0, 'orderCode' => $ordeCode, 'status' => [0, 1]])
|
|
|
+ ->sum('send_num');
|
|
|
|
|
|
-
|
|
|
-// $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
|
|
|
-// if ($ordersend['send_num'] < $val['return_num']) {
|
|
|
-// Db::rollback();
|
|
|
-// return json_show(1004, "发货单发货数量不足");
|
|
|
-// }
|
|
|
-// $ordersend['send_num'] -= $val['return_num'];
|
|
|
-// $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
|
|
|
-// $ordersend['updatetime'] = $date;
|
|
|
-// $sendip = Db::name("order_send")->save($ordersend);
|
|
|
-// if ($sendip == false) {
|
|
|
-// Db::rollback();
|
|
|
-// return json_show(1004, "发货单更新失败");
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
- }
|
|
|
- $temp['returnCode'] = $returnCode;
|
|
|
- $temp['orderCode'] = $ordeCode;
|
|
|
- $temp['outCode'] = isset($send['outCode']) ? $send['outCode'] : "";
|
|
|
- $temp['addrid'] = $val['id'];
|
|
|
- $temp['send_num'] = $addrinfo['receipt_quantity'];
|
|
|
- $temp['return_num'] = $val['return_num'];
|
|
|
- $temp['is_del'] = 0;
|
|
|
- $temp['addtime'] = $date;
|
|
|
- $temp['updatetime'] = $date;
|
|
|
- $inf[] = $temp;
|
|
|
- }
|
|
|
- $inadd = Db::name("sale_returnaddr")->insertAll($inf);
|
|
|
- if ($inadd == 0) throw new Exception("退货单新建失败");
|
|
|
- }
|
|
|
-
|
|
|
- if ($order['is_stock'] == 1) {
|
|
|
+ $order['wsend_num'] -= $out_send_num;
|
|
|
|
|
|
if ($order['wsend_num'] < $thnum) throw new Exception("销售单未发货数量不足退货");
|
|
|
|
|
@@ -282,72 +289,72 @@ class Reorder extends Base
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- $saleinfo = Db::name("sale_info")
|
|
|
- ->where([["orderCode", "=", $ordeCode], ["num", ">", 0]])
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
- if (empty($saleinfo)) {
|
|
|
- $ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->findOrEmpty();
|
|
|
- if (empty($ordernum)) throw new Exception('未找到关联采购单');
|
|
|
-
|
|
|
- $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->findOrEmpty();
|
|
|
- if (empty($cgd)) throw new Exception('未找到采购单数据');
|
|
|
-
|
|
|
- $bn = makeNo("BN");
|
|
|
- $stock = Db::name("good_stock")
|
|
|
- ->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code'], "is_del" => 0, "status" => 1])
|
|
|
- ->findOrEmpty();
|
|
|
- if ($stock == false) throw new Exception('商品库存数据未找到');
|
|
|
-
|
|
|
- $stock['usable_stock'] += $thnum;
|
|
|
- $stock['wait_out_stock'] -= $thnum;
|
|
|
- $stock['updatetime'] = $date;
|
|
|
- $st_up = Db::name("good_stock")->save($stock);
|
|
|
- if ($st_up == false) throw new Exception('可售商品入库失败');
|
|
|
-
|
|
|
- $yp = GoodStockInfo::AddBn($stock['id'], $bn, $thnum, $cgd['good_price']);
|
|
|
- if ($yp == false) throw new Exception('商品批次退货入库失败');
|
|
|
-
|
|
|
- } else {
|
|
|
- $tempnum = $thnum;
|
|
|
- foreach ($saleinfo as $va) {
|
|
|
- if ($tempnum == 0) break;
|
|
|
- $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])
|
|
|
- ->findOrEmpty();
|
|
|
- if ($stock == false) throw new Exception('商品库存数据未找到');
|
|
|
-
|
|
|
- if ($va['num'] >= $tempnum) {
|
|
|
- $tnm = $tempnum;
|
|
|
- $va['num'] -= $tempnum;
|
|
|
- $va['th_num'] += $tempnum;
|
|
|
- $tempnum = 0;
|
|
|
- } else {
|
|
|
- $tnm = $va['num'];
|
|
|
- $tempnum -= $va['num'];
|
|
|
- $va['th_num'] += $va['num'];
|
|
|
- $va['num'] = 0;
|
|
|
- }
|
|
|
- $stock['usable_stock'] += $tnm;
|
|
|
- $stock['wait_out_stock'] -= $tnm;
|
|
|
- $stock['updatetime'] = $date;
|
|
|
- $st_up = Db::name("good_stock")->save($stock);
|
|
|
- if ($st_up == false) throw new Exception('可售商品入库失败');
|
|
|
-
|
|
|
- $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
|
|
|
- if ($ps == false) throw new Exception('商品批次退货入库失败');
|
|
|
-
|
|
|
- $ret = GoodStockInfo::ReturnBn($returnCode, $va['id'], $tnm);
|
|
|
- if ($ret == false) throw new Exception('商品批次退货入库失败');
|
|
|
-
|
|
|
- $va['updatetime'] = $date;
|
|
|
- $sal = Db::name("sale_info")->save($va);
|
|
|
- if ($sal == false) throw new Exception('商品批次退货入库失败');
|
|
|
-
|
|
|
- $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
|
|
|
- $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
|
|
|
- GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'XSTHD');
|
|
|
- }
|
|
|
- }
|
|
|
+// $saleinfo = Db::name("sale_info")
|
|
|
+// ->where([["orderCode", "=", $ordeCode], ["num", ">", 0]])
|
|
|
+// ->select()
|
|
|
+// ->toArray();
|
|
|
+// if (empty($saleinfo)) {
|
|
|
+// $ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->findOrEmpty();
|
|
|
+// if (empty($ordernum)) throw new Exception('未找到关联采购单');
|
|
|
+//
|
|
|
+// $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->findOrEmpty();
|
|
|
+// if (empty($cgd)) throw new Exception('未找到采购单数据');
|
|
|
+//
|
|
|
+// $bn = makeNo("BN");
|
|
|
+// $stock = Db::name("good_stock")
|
|
|
+// ->where(["spuCode" => $order['good_code'], 'wsm_code' => $cgd['wsm_code'], "is_del" => 0, "status" => 1])
|
|
|
+// ->findOrEmpty();
|
|
|
+// if ($stock == false) throw new Exception('商品库存数据未找到');
|
|
|
+//
|
|
|
+// $stock['usable_stock'] += $thnum;
|
|
|
+// $stock['wait_out_stock'] -= $thnum;
|
|
|
+// $stock['updatetime'] = $date;
|
|
|
+// $st_up = Db::name("good_stock")->save($stock);
|
|
|
+// if ($st_up == false) throw new Exception('可售商品入库失败');
|
|
|
+//
|
|
|
+// $yp = GoodStockInfo::AddBn($stock['id'], $bn, $thnum, $cgd['good_price']);
|
|
|
+// if ($yp == false) throw new Exception('商品批次退货入库失败');
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// $tempnum = $thnum;
|
|
|
+// foreach ($saleinfo as $va) {
|
|
|
+// if ($tempnum == 0) break;
|
|
|
+// $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])
|
|
|
+// ->findOrEmpty();
|
|
|
+// if ($stock == false) throw new Exception('商品库存数据未找到');
|
|
|
+//
|
|
|
+// if ($va['num'] >= $tempnum) {
|
|
|
+// $tnm = $tempnum;
|
|
|
+// $va['num'] -= $tempnum;
|
|
|
+// $va['th_num'] += $tempnum;
|
|
|
+// $tempnum = 0;
|
|
|
+// } else {
|
|
|
+// $tnm = $va['num'];
|
|
|
+// $tempnum -= $va['num'];
|
|
|
+// $va['th_num'] += $va['num'];
|
|
|
+// $va['num'] = 0;
|
|
|
+// }
|
|
|
+// $stock['usable_stock'] += $tnm;
|
|
|
+// $stock['wait_out_stock'] -= $tnm;
|
|
|
+// $stock['updatetime'] = $date;
|
|
|
+// $st_up = Db::name("good_stock")->save($stock);
|
|
|
+// if ($st_up == false) throw new Exception('可售商品入库失败');
|
|
|
+//
|
|
|
+// $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
|
|
|
+// if ($ps == false) throw new Exception('商品批次退货入库失败');
|
|
|
+//
|
|
|
+// $ret = GoodStockInfo::ReturnBn($returnCode, $va['id'], $tnm);
|
|
|
+// if ($ret == false) throw new Exception('商品批次退货入库失败');
|
|
|
+//
|
|
|
+// $va['updatetime'] = $date;
|
|
|
+// $sal = Db::name("sale_info")->save($va);
|
|
|
+// if ($sal == false) throw new Exception('商品批次退货入库失败');
|
|
|
+//
|
|
|
+// $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
|
|
|
+// $good_data[] = ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
|
|
|
+// GoodLog::LogAdd(['id' => $this->uid, 'nickname' => $this->uname], $good_data, 'XSTHD');
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
// $data=[
|
|
@@ -874,7 +881,7 @@ class Reorder extends Base
|
|
|
->findOrEmpty();
|
|
|
if (empty($addrinfo)) throw new Exception("地址数据未找到");
|
|
|
|
|
|
- if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception( "地址发货数量不足");
|
|
|
+ if ($addrinfo['receipt_quantity'] < $value['return_num']) throw new Exception("地址发货数量不足");
|
|
|
|
|
|
$addrinfo['receipt_quantity'] -= $value['return_num'];
|
|
|
$addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
|