|
@@ -233,9 +233,9 @@ class Reorder extends Base
|
|
|
$uap = Db::name("sale")->save($order);
|
|
|
if ($uap == false) throw new Exception('销售单订单更新失败');
|
|
|
$good =Db::name("good")->where(["spuCode"=>$order['good_code']])->findOrEmpty();
|
|
|
- if(empty($good))throw new Exception('未找到商品信息');
|
|
|
- $stock=Db::name("good")->where($good)->update(["usable_stock"=>$good['usable_stock']+$thnum,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
- if ($stock == false) throw new Exception('商品库存更新失败');
|
|
|
+ if(empty($good))throw new Exception('未找到商品信息');
|
|
|
+ $stock=Db::name("good")->where($good)->update(["usable_stock"=>$good['usable_stock']+$thnum,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
+ if ($stock == false) throw new Exception('商品库存更新失败');
|
|
|
ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
"order_code" => $order["orderCode"],//出库单号
|
|
|
"status" => $lor,//这里的status是之前的值
|
|
@@ -299,74 +299,76 @@ class Reorder extends Base
|
|
|
// return json_show(1005, '备库单库存数据释放失败');
|
|
|
// }
|
|
|
// }
|
|
|
+ if(strtotime($order['addtime'])< strtotime("2023-04-17 00:00:00")){
|
|
|
+ $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('商品库存数据未找到');
|
|
|
|
|
|
-// $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"];
|
|
|
+ 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=[
|
|
|
"orderCode"=>$ordeCode,
|