|
@@ -20,7 +20,17 @@ class CombindStock extends Base
|
|
|
}
|
|
|
|
|
|
public function list(){
|
|
|
-
|
|
|
+ $param=$this->request->only(['spuCode'=>'','wsm_code'=>'','good_name'=>'','cat_id'=>'','status'=>'','flag'=>'',
|
|
|
+ "create_start"=>"2023-01-01 00:00:00","create_end"=>date("Y-m-d H:i:s")],'post','trim');
|
|
|
+ $where=[["createtime","between",[$param['create_start'],$param['create_end']]]];
|
|
|
+ $param['spuCode']?? $where[]=["spuCode","like","%{$param['spuCode']}%"];
|
|
|
+ $param['wsm_code']?? $where[]=["wsm_code","like","%{$param['wsm_code']}%"];
|
|
|
+ $param['good_name']?? $where[]=["good_name","like","%{$param['good_name']}%"];
|
|
|
+ $param['cat_id']?? $where[]=["good_basic.cat_id","=",$param['cat_id']];
|
|
|
+ $list = $this->combindStock->withJoin(["wsminfo","good"],"left")->order("id desc")->paginate
|
|
|
+ (["page"=>$param['page'],"list_rows"=>$param['size']]);
|
|
|
+ return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
|
|
|
+
|
|
|
}
|
|
|
/**@param spuCode 商品编号
|
|
|
**@param wsm_code 仓库编号
|
|
@@ -121,10 +131,9 @@ class CombindStock extends Base
|
|
|
$up =$row->save();
|
|
|
if($up==false) throw new \Exception("数据状态更新失败");
|
|
|
if($param['status']==2){
|
|
|
-
|
|
|
$GoodStock =new GoodStock();
|
|
|
$stock =$GoodStock->where(["spuCode"=>$row->spuCode,"wsm_code"=>$row->wsm_code])->findOrEmpty();
|
|
|
- if($param['flag']==1){
|
|
|
+ if($row->flag==1){
|
|
|
$bn = makeNo('BN');
|
|
|
if($stock->isEmpty()){
|
|
|
$wsm_stock = [
|
|
@@ -162,17 +171,34 @@ class CombindStock extends Base
|
|
|
$stockCodeLog= (new CombindStockInfo())->save(["stockCode"=>$row->stockCode,"flag"=>1,
|
|
|
"stock_num"=>$row->stock_num,"bnCode"=>$bn,"origin_price"=>$origin_price]);
|
|
|
if($stockCodeLog==false)throw new \Exception( '组合商品bn库存生成失败');
|
|
|
- (new CombindBninfo())->AaddBNLog($row->spuCode,$bn,$stockCodeLog);
|
|
|
+ $bnlist =$this->combind->AddStock($row->spuCode,$row->stock_num);
|
|
|
+ (new CombindBninfo())->AaddBNLog($row->spuCode,$bn,$bnlist);
|
|
|
}else{
|
|
|
-
|
|
|
+ if($stock->usable_stock < $row->stock_num) throw new \Exception('仓库可用库数不足');
|
|
|
+ $up =GoodStockInfo::SaleBn($stock->id,intval($row->stock_num));
|
|
|
+ if(empty($up)) throw new \Exception('未找到对应子商品BN库存信息');
|
|
|
+ foreach ($up as $item){
|
|
|
+ $bnlist =$this->combind->subStock($row->spuCode,$item['bnCode'],$item['num']);
|
|
|
+ if($bnlist==false)throw new \Exception('子商品BN库存信息更新失败');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if($param['status']==3){
|
|
|
- if($param['flag']==1){
|
|
|
-
|
|
|
- }else{
|
|
|
-
|
|
|
- }
|
|
|
+ $good= (new \app\admin\model\Good())->where(['spuCode'=>$row->spuCode])->findOrEmpty();
|
|
|
+ if($good->isEmpty()==false){
|
|
|
+ if($row->flag==0){
|
|
|
+ $good->usable_stock = bcadd($good->usable_stock ,$row->stock_num);
|
|
|
+ $stockup = $good->save();
|
|
|
+ if($stockup==false) throw new \Exception('组合商品库存解除驳回失败');
|
|
|
+ }else{
|
|
|
+ foreach ($comblist as $item){
|
|
|
+ $num = bcmul($item['child_num'],$row->stock_num);
|
|
|
+ $stockup = Db::name('good')->where('spuCode',$item['childCode'])->inc('usable_stock',intval
|
|
|
+ ($num))->update();
|
|
|
+ if($stockup==false) throw new \Exception('组合商品的子商品信息库存占用驳回失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
$row->commit();
|
|
|
}catch (\Exception $exception){
|