|
@@ -5129,7 +5129,7 @@ class Sale extends Base
|
|
|
|
|
|
$list = Db::name('sale')
|
|
|
->alias('a')
|
|
|
- ->field('a.id sale_id,a.order_type,a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status,c.cgdNo,c.cgder_id')
|
|
|
+ ->field('a.id sale_id,a.good_code,a.wsend_num,a.order_type,a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status,c.cgdNo,c.cgder_id')
|
|
|
->leftJoin('order_num b', 'b.orderCode=a.orderCode')
|
|
|
->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
|
|
|
->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
|
|
@@ -5155,14 +5155,16 @@ class Sale extends Base
|
|
|
if ($sale['sale_status'] == 3) throw new \think\Exception($sale['orderCode'] . '已取消,无法重复操作');
|
|
|
if (in_array($sale['cat_id'], $cat_id)) throw new \think\Exception($sale['orderCode'] . '为贵金属,无法取消');
|
|
|
|
|
|
- if (in_array($sale['sale_status'], [0, 1]) == false) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
|
|
|
-
|
|
|
-// if ($sale['order_type'] == 1) {
|
|
|
-// if (in_array($sale['sale_status'], [0, 1]) == false) throw new \think\Exception($sale['orderCode'] . '未处于待发货状态,无法取消');
|
|
|
-// } else {
|
|
|
-// if (in_array($sale['cgd_status'], [0, 1]) == false) throw new \think\Exception($sale['orderCode'] . '采购单已入库,无法取消');
|
|
|
-// }
|
|
|
-
|
|
|
+// if ($sale['sale_status']!=0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
|
|
|
+ if ($sale['order_type'] == 1) {
|
|
|
+ if ($sale['sale_status']!=0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
|
|
|
+ $good =Db::name("good")->where(["spuCode"=>$sale['good_code']])->findOrEmpty();
|
|
|
+ if(empty($good))throw new Exception('未找到商品信息');
|
|
|
+ $stock=Db::name("good")->where($good)->update(["usable_stock"=>$good['usable_stock']+$sale['wsend_num'],"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
+ if ($stock == false) throw new Exception('商品库存更新失败');
|
|
|
+ } else {
|
|
|
+ if (in_array($sale['cgd_status'], [0, 1]) == false) throw new \think\Exception($sale['orderCode'] . '采购单已入库,无法取消');
|
|
|
+ }
|
|
|
//修改状态,添加待办
|
|
|
ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
"order_code" => $sale['orderCode'],//销售单号
|
|
@@ -5242,6 +5244,16 @@ class Sale extends Base
|
|
|
->where(['is_del' => 0, 'orderCode' => $orderCode])
|
|
|
->update(['status' => 5, 'updatetime' => $date]);
|
|
|
foreach ($ooc_list as $ooc) {
|
|
|
+ $stockinfo =Db::name("good_stock")->where(["spuCode"=>$ooc['spuCode'],"wsm_code"=>$ooc['wsm_code']])->findOrEmpty();
|
|
|
+ if(empty($stockinfo))throw new Exception('未找到库存信息');
|
|
|
+ $stockup =[
|
|
|
+ "usable_stock"=>$stockinfo['usable_stock']+$ooc['num'],
|
|
|
+ "wait_out_stock"=>$stockinfo['"wait_out_stock']- $ooc['num'],
|
|
|
+ "updatetime" => $date
|
|
|
+ ] ;
|
|
|
+ $ysup =Db::name("good_stock")->where($stockinfo)->update($stockup);
|
|
|
+ if($ysup==false)throw new Exception('库存信息更新失败');
|
|
|
+ GoodStockInfo::ChildReturnBn($ooc['outChildCode'],$stockinfo['id'],$ooc['num']);//处理bn数据
|
|
|
ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
|
|
|
"order_code" => $ooc['outChildCode'],//销售单号
|
|
|
"status" => $ooc['status'],//这里的status是之前的值
|