|
@@ -174,37 +174,35 @@ class MateCheck extends Auth
|
|
|
if($ginfo){
|
|
|
$this->error('还有物品未盘库');
|
|
|
}
|
|
|
- $ret = Db::name('mate_check')->where('id',$id)->update(['status'=>1,'finish_time'=>date('Y-m-d H:i:s')]);
|
|
|
-
|
|
|
- $goodsList = Db::name('mate_check_goods')
|
|
|
- ->where('check_id',$id)
|
|
|
- ->where('del',0)
|
|
|
- ->where('status','>',0)
|
|
|
- ->select();
|
|
|
-
|
|
|
- foreach ($goodsList as $k=>$v){
|
|
|
-// $num = $v['nums'] - $v['check_nums'];
|
|
|
-// if($num > 0){
|
|
|
-// $save = Db::name('mate_goods')
|
|
|
-// ->where('id',$v['goods_id'])
|
|
|
-// ->setDec('nums',$num);
|
|
|
-// }else{
|
|
|
-// $num = abs($num);
|
|
|
-// $save = Db::name('mate_goods')
|
|
|
-// ->where('id',$v['goods_id'])
|
|
|
-// ->setInc('nums',$num);
|
|
|
-// }
|
|
|
- $save = Db::name('mate_goods')
|
|
|
- ->where('id',$v['goods_id'])
|
|
|
- ->update(['nums'=>$v['check_nums']]);
|
|
|
- if(!$save){
|
|
|
- $this->error('数量修改失败');
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $ret = Db::name('mate_check')->where('id',$id)->update(['status'=>1,'finish_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ if(!$ret){
|
|
|
+ \exception("操作失败");
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if(!$ret){
|
|
|
+ $goodsList = Db::name('mate_check_goods')
|
|
|
+ ->where('check_id',$id)
|
|
|
+ ->where('del',0)
|
|
|
+ ->where('status','>',0)
|
|
|
+ ->select();
|
|
|
+ $goodsList = $goodsList?$goodsList:[];
|
|
|
+ foreach ($goodsList as $k=>$v){
|
|
|
+ $save = Db::name('mate_goods')
|
|
|
+ ->where('id',$v['goods_id'])
|
|
|
+ ->update(['nums'=>$v['check_nums'],'update_time'=>date("Y-m-d H:i:s")]);
|
|
|
+ if(!$save){
|
|
|
+ \exception("操作失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
$this->error('操作失败');
|
|
|
}
|
|
|
+
|
|
|
$this->success('操作成功');
|
|
|
}
|
|
|
|