|
@@ -5193,7 +5193,7 @@ class Sale extends Base
|
|
|
|
|
|
$list = Db::name('sale')
|
|
|
->alias('a')
|
|
|
- ->field('a.id sale_id,a.good_code,a.platform_order,a.good_name,a.wsend_num,a.total_price,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.platform_order,a.good_name,a.wsend_num,a.total_price,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,a.addtime')
|
|
|
->leftJoin('order_num b', 'b.orderCode=a.orderCode')
|
|
|
->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
|
|
|
->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
|
|
@@ -5216,6 +5216,71 @@ class Sale extends Base
|
|
|
->inc("usable_stock",$sale['wsend_num'])
|
|
|
->update();
|
|
|
if ($stock == false) throw new Exception('商品库存更新失败');
|
|
|
+ if(strtotime($sale['addtime'])< strtotime('2023-04-17 00:00:00')){
|
|
|
+ $saleinfo = Db::name('sale_info')
|
|
|
+ ->where([['orderCode', '=',$sale['orderCode']], ['num', '>', 0]])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if (empty($saleinfo)) {
|
|
|
+ $ordernum = Db::name('order_num')->where(['orderCode' =>$sale['orderCode']])->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' => $sale['good_code'], 'wsm_code' => $cgd['wsm_code'], 'is_del' => 0, 'status' => 1])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if ($stock == false) throw new Exception('商品库存数据未找到');
|
|
|
+
|
|
|
+ $stock['usable_stock'] += $sale['wsend_num'];
|
|
|
+ $stock['wait_out_stock'] -= $sale['wsend_num'];
|
|
|
+ $stock['updatetime'] = $date;
|
|
|
+ $st_up = Db::name('good_stock')->save($stock);
|
|
|
+ if ($st_up == false) throw new Exception('可售商品入库失败');
|
|
|
+
|
|
|
+ $yp = GoodStockInfo::AddBn($stock['id'], $bn, $sale['wsend_num'], $cgd['good_price']);
|
|
|
+ if ($yp == false) throw new Exception('商品批次退货入库失败');
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $tempnum = $sale['wsend_num'];
|
|
|
+ foreach ($saleinfo as $va) {
|
|
|
+ if ($tempnum == 0) break;
|
|
|
+ $stock = Db::name('good_stock')->where(['spuCode' => $sale['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($sale['orderCode'], $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('商品批次退货入库失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
if($sale['order_type'] == 4){
|
|
|
$fill =Db::name("filing")->where(["filingCode"=>$sale["platform_order"]])->findOrEmpty();
|
|
@@ -5395,7 +5460,7 @@ class Sale extends Base
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
Db::commit();
|
|
|
return json_show(0, '操作成功');
|