|
@@ -7,7 +7,7 @@ use app\abutment\model\SupplierUser;
|
|
|
use app\admin\model\DataGroup as DataGroupModel;
|
|
|
use app\admin\model\GoodLog;
|
|
|
use app\admin\model\GoodStockInfo;
|
|
|
-use app\admin\model\ProcessOrder;
|
|
|
+use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
|
|
|
use app\admin\model\SaleInfo;
|
|
|
use Exception;
|
|
|
use think\App;
|
|
@@ -336,12 +336,6 @@ class Sale extends Base
|
|
|
if ($order == false) {
|
|
|
throw new Exception("未找到可以发货得采购单数据");
|
|
|
}
|
|
|
- $order['wsend_num'] -= $num;
|
|
|
- $order['send_num'] += $num;
|
|
|
- $or = Db::name("order_num")->save($order);
|
|
|
- if ($or == false) {
|
|
|
- throw new Exception("发货地址添加创建失败");
|
|
|
- }
|
|
|
$tep = [
|
|
|
"cgdNo" => $order['cgdNo'],
|
|
|
"outCode" => $outCode,
|
|
@@ -384,6 +378,7 @@ class Sale extends Base
|
|
|
throw new Exception("发货地址添加创建失败");
|
|
|
// return error_show(1002, "发货地址添加创建失败");
|
|
|
} else {
|
|
|
+ OrderOutChild::makeChild($outCode);
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
|
|
|
"order_code" => $outCode,//出库单号
|
|
@@ -744,6 +739,8 @@ class Sale extends Base
|
|
|
throw new Exception("发货单创建失败");
|
|
|
// return error_show(1002, "发货地址添加创建失败");
|
|
|
} else {
|
|
|
+ OrderOutChild::makeChild($outCode);
|
|
|
+
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
|
|
|
"order_code" => $outCode,//出库单号
|
|
@@ -1162,6 +1159,7 @@ class Sale extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "发货地址添加创建失败");
|
|
|
} else {
|
|
|
+ OrderOutChild::makeChild($outCode);
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
|
|
|
"order_code" => $outCode,//出库单号
|
|
@@ -1184,14 +1182,7 @@ class Sale extends Base
|
|
|
//将发货编号添加到台账中
|
|
|
$standing_book_data['outCode'][] = $outCode;
|
|
|
}
|
|
|
- $order['send_num'] += $value['receipt_quantity'];
|
|
|
- $order['wsend_num'] -= $value['receipt_quantity'];
|
|
|
- if ($order['wsend_num'] < 0) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "发货数量已超出总数");
|
|
|
- }
|
|
|
- $ups = Db::name("order_num")->save($order);
|
|
|
- if ($ups) {
|
|
|
+
|
|
|
$tep = [
|
|
|
"cgdNo" => $order['cgdNo'],
|
|
|
"outCode" => $outCode,
|
|
@@ -1205,8 +1196,6 @@ class Sale extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "发货地址添加创建失败");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
return error_show(1002, "发货地址添加创建失败");
|
|
@@ -1275,8 +1264,8 @@ class Sale extends Base
|
|
|
try {
|
|
|
$plan = Db::name("project_plan")->where(["planNo" => $planNo, "is_del" => 0])->lock(true)->find();
|
|
|
if ($plan == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1004, "未找到方案信息");
|
|
|
+ throw new Exception("未找到方案信息");
|
|
|
+// return error_show(1004, "未找到方案信息");
|
|
|
}
|
|
|
$feedid = array_column($feedbackid, "feedback_id");
|
|
|
$feedbacks = Db::name("project_feedback")
|
|
@@ -1287,8 +1276,8 @@ class Sale extends Base
|
|
|
$good = [];
|
|
|
$feedback = $feedbacks[$value['feedback_id']]??[];
|
|
|
if (empty($feedback)) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "反馈数据未找到");
|
|
|
+ throw new Exception("反馈数据未找到");
|
|
|
+// return error_show(1002, "反馈数据未找到");
|
|
|
}
|
|
|
$key = array_search($feedback['id'], $feedid);
|
|
|
$price = $feedbackid[$key];
|
|
@@ -1312,8 +1301,8 @@ class Sale extends Base
|
|
|
$standing_book_data = ['projectNo' => $plan['projectNo'], 'updatetime' => date('Y-m-d H:i:s')];
|
|
|
if ($value['sendtype'] == 1) {
|
|
|
if (!isset($value['addrlist']) || empty($value['addrlist'])) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "订单地址不能为空");
|
|
|
+ throw new Exception("订单地址不能为空");
|
|
|
+// return error_show(1002, "订单地址不能为空");
|
|
|
}
|
|
|
$good['addrlist'] = $value['addrlist'];
|
|
|
$good['send_num'] = array_sum(array_column($value['addrlist'], "receipt_quantity"));
|
|
@@ -1322,38 +1311,21 @@ class Sale extends Base
|
|
|
|
|
|
$feed = $this->project_good($good, $standing_book_data);
|
|
|
if ($feed !== true) {
|
|
|
- Db::rollback();
|
|
|
- switch ($feed) {
|
|
|
- case 1:
|
|
|
- $msg = '库存不足';
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- $msg = '库存更新失败';
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- $msg = '关联采购失败';
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- $msg = '商品信息未找到';
|
|
|
- break;
|
|
|
- default:
|
|
|
- $msg = '咨询订单生成失败';
|
|
|
-
|
|
|
- }
|
|
|
- return error_show(1002, $msg);
|
|
|
+ throw new Exception("订单生成失败");
|
|
|
+// return error_show(1002, $msg);
|
|
|
}
|
|
|
} else {
|
|
|
$feed = $this->project_zx($good, $standing_book_data);
|
|
|
if ($feed == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "咨询订单生成失败");
|
|
|
+ throw new Exception("咨询订单生成失败");
|
|
|
+// return error_show(1002, "咨询订单生成失败");
|
|
|
}
|
|
|
}
|
|
|
$old_fk_status = $feedback['status'];
|
|
|
$fed = Db::name("project_feedback")->where($feedback)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
|
|
|
if ($fed == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "项目订单生成失败");
|
|
|
+ throw new Exception("项目反馈更新失败");
|
|
|
+// return error_show(1002, "项目订单生成失败");
|
|
|
}
|
|
|
|
|
|
//处理台账(一个项目会生成多个销售订单,第一个更新,其余的新增)
|
|
@@ -1386,8 +1358,8 @@ class Sale extends Base
|
|
|
// $plan['updatetime']=date("Y-m-d H:i:s");
|
|
|
$in = Db::name("project_plan")->where($plan)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
|
|
|
if ($in == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "项目订单生成失败");
|
|
|
+ throw new Exception("项目方案状态更新失败");
|
|
|
+// return error_show(1002, "项目订单生成失败");
|
|
|
} else {
|
|
|
//修改状态,添加待办,只记录动作
|
|
|
ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
|
|
@@ -1402,8 +1374,8 @@ class Sale extends Base
|
|
|
// $project['updatetime']=date("Y-m-d H:i:s");
|
|
|
$pr = Db::name("project")->where($project)->save(["updatetime" => date("Y-m-d H:i:s"), "status" => 6]);
|
|
|
if ($pr == false) {
|
|
|
- Db::rollback();
|
|
|
- return error_show(1002, "项目订单生成失败");
|
|
|
+ throw new Exception("项目状态更新失败");
|
|
|
+// return error_show(1002, "项目订单生成失败");
|
|
|
} else {
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
|
|
@@ -1638,13 +1610,13 @@ class Sale extends Base
|
|
|
];
|
|
|
$good = Db::name("good_zixun")->insert($limt);
|
|
|
if (!$good) {
|
|
|
- return false;
|
|
|
+ throw new Exception("咨询商品录入失败");
|
|
|
}
|
|
|
if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
|
|
|
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
|
|
|
+ $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
|
|
|
->find();
|
|
|
if ($order == false) {
|
|
|
- return false;
|
|
|
+ throw new Exception("关联采购单信息未找到");
|
|
|
}
|
|
|
$i = 1;
|
|
|
foreach ($data['addrlist'] as $value) {
|
|
@@ -1698,8 +1670,9 @@ class Sale extends Base
|
|
|
];
|
|
|
$ou = Db::name("order_out")->insertGetId($out);
|
|
|
if ($ou == false) {
|
|
|
- return false;
|
|
|
+ throw new Exception("发货单生成失败");
|
|
|
}
|
|
|
+ OrderOutChild::makeChild($outCode);
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
|
|
|
"order_code" => $outCode,//项目编码
|
|
@@ -1718,13 +1691,6 @@ class Sale extends Base
|
|
|
'wait_id'=>$holder_id,
|
|
|
'wait_name'=>$holder_name,
|
|
|
]);
|
|
|
- $order['send_num'] += $value['receipt_quantity'];
|
|
|
- $order['wsend_num'] -= $value['receipt_quantity'];
|
|
|
- if ($order['wsend_num'] < 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $ups = Db::name("order_num")->save($order);
|
|
|
- if ($ups) {
|
|
|
$tep = [
|
|
|
"cgdNo" => $order['cgdNo'],
|
|
|
"outCode" => $outCode,
|
|
@@ -1735,14 +1701,14 @@ class Sale extends Base
|
|
|
];
|
|
|
$sen = Db::name("order_send")->save($tep);
|
|
|
if ($sen == false) {
|
|
|
- return false;
|
|
|
+ throw new Exception("发货单关联采购单生成失败");
|
|
|
}
|
|
|
|
|
|
$standing_book_data['outCode'][] = $outCode;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
- return false;
|
|
|
+ throw new Exception("地址录入失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1766,11 +1732,13 @@ class Sale extends Base
|
|
|
->field("a.*,b.skuCode,b.platform_code")->find();
|
|
|
|
|
|
if ($good == false) {
|
|
|
- return 4; //商品信息未找到
|
|
|
+// return 4; //商品信息未找到
|
|
|
+ throw new Exception("商品信息未找到");
|
|
|
}
|
|
|
$goodlass = Db::name("good_ladder")->where(["skuCode" => $data['skuCode'], "is_del" => 0, "status" => 1])->where([["min_num", "<=", $data['good_num']]])->order("min_num desc")->find();
|
|
|
if ($goodlass == false) {
|
|
|
- return 4;//商品信息未找到
|
|
|
+// /return 4;//商品信息未找到
|
|
|
+ throw new Exception("商品售价信息未找到");
|
|
|
}
|
|
|
$sale_price = $goodlass['sale_price'];
|
|
|
$origin_price = 0;
|
|
@@ -1778,7 +1746,8 @@ class Sale extends Base
|
|
|
$origin = Db::name("good_nake")->where([["spuCode", "=", $data['spuCode']], ["min_num", "<=", $data['good_num']],
|
|
|
["is_del", "=", 0]])->order("min_num desc")->find();
|
|
|
if ($origin == false) {
|
|
|
- return 4;//商品信息未找到
|
|
|
+// return 4;//商品信息未找到
|
|
|
+ throw new Exception("商品成本售价信息未找到");
|
|
|
}
|
|
|
$origin_price = $origin['nake_total'];
|
|
|
}
|
|
@@ -1901,28 +1870,21 @@ class Sale extends Base
|
|
|
if ($good['is_stock'] == 0) {
|
|
|
$bol = $this->createCgd($cgd, $standing_book_data);
|
|
|
if ($bol == false) {
|
|
|
- return 3;//关联采购失败
|
|
|
+// return 3;//关联采购失败
|
|
|
+ throw new Exception("采购单生成失败");
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
- $stock_arr = Db::name("good_stock")->alias("a")
|
|
|
- ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
|
|
|
- ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
|
|
|
- ->where(["spuCode" => $good['spuCode'], "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$data['companyNo']])
|
|
|
- ->column('stockid,balance_num');
|
|
|
- $stock_num = array_sum(array_column($stock_arr,"balance_num"));
|
|
|
- $stockid = array_unique(array_column($stock_arr,"stockid"));
|
|
|
- if($stock_num < $data['good_num']){
|
|
|
- return 1;
|
|
|
+ if($good['usable_stock'] < $data['good_num']){
|
|
|
+ throw new Exception("可用库存数不足");
|
|
|
}
|
|
|
- if (!empty($stockid)) {
|
|
|
-
|
|
|
- $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,$data['good_num']);
|
|
|
- if($stockinfo==false){
|
|
|
- return 2; //库存不足
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ $stockUp =[
|
|
|
+ "usable_stock"=>$good['usable_stock']-$data['good_num'],
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $goodStockUp = Db::name("good")->where(['spuCode'=>$good['spuCode'],"usable_stock"=>$good['usable_stock']])->update
|
|
|
+ ($stockUp);
|
|
|
+ if($goodStockUp==false) throw new Exception("商品可用库存更新失败");
|
|
|
}
|
|
|
if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
|
|
|
$i = 1;
|
|
@@ -1957,22 +1919,12 @@ class Sale extends Base
|
|
|
$outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
|
|
|
$i++;
|
|
|
if ($good['is_stock'] != 1) {
|
|
|
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
|
|
|
- ->lock(true)->find();
|
|
|
+ $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
|
|
|
+ ->find();
|
|
|
if ($order == false) {
|
|
|
- return 3;
|
|
|
+ throw new Exception("关联采购单信息未找到");
|
|
|
}
|
|
|
|
|
|
- //改变编码规则,将原来的outCode后两位换成序列号
|
|
|
- //str_pad字符串填充
|
|
|
-
|
|
|
- $order['wsend_num'] -= $num;
|
|
|
- $order['send_num'] += $num;
|
|
|
- $or = Db::name("order_num")->save($order);
|
|
|
- if ($or == false) {
|
|
|
-
|
|
|
- return 3;
|
|
|
- }
|
|
|
$tep = [
|
|
|
"cgdNo" => $order['cgdNo'],
|
|
|
"outCode" => $outCode,
|
|
@@ -1983,13 +1935,11 @@ class Sale extends Base
|
|
|
];
|
|
|
$sen = Db::name("order_send")->save($tep);
|
|
|
if ($sen == false) {
|
|
|
-
|
|
|
- return 3;
|
|
|
+ throw new Exception("发货单关联采购单信息失败");
|
|
|
}
|
|
|
$cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
|
|
|
if ($cgdinfo == false) {
|
|
|
-
|
|
|
- return 4;
|
|
|
+ throw new Exception("采购单信息未找到");
|
|
|
}
|
|
|
}
|
|
|
$out = [
|
|
@@ -2013,8 +1963,9 @@ class Sale extends Base
|
|
|
];
|
|
|
$ou = Db::name("order_out")->insertGetId($out);
|
|
|
if ($ou == false) {
|
|
|
- return 0;
|
|
|
+ throw new Exception("发货单生成失败");
|
|
|
} else {
|
|
|
+ OrderOutChild::makeChild($outCode);
|
|
|
$standing_book_data['outCode'][] = $outCode;
|
|
|
//修改状态,添加待办
|
|
|
if($good['is_stock'] == 1){
|
|
@@ -2044,7 +1995,7 @@ class Sale extends Base
|
|
|
]);
|
|
|
}
|
|
|
} else {
|
|
|
- return false;
|
|
|
+ throw new Exception("地址录入失败");
|
|
|
}
|
|
|
}
|
|
|
}
|