|
@@ -195,7 +195,7 @@ class TagGood extends Base{
|
|
|
if($code==''){
|
|
|
return error_show(1004,"参数 code 不能为空");
|
|
|
}
|
|
|
- $taglog =Db::name("tag_log")->where(["tag_id"=>$tagid,"code"=>$code,"status"=>1])->findOrEmpty();
|
|
|
+// $taglog =Db::name("tag_log")->where(["tag_id"=>$tagid,"code"=>$code,"status"=>1])->findOrEmpty();
|
|
|
$total_fee =isset($this->post['total_fee']) &&$this->post["total_fee"]!=="" ? floatval($this->post["total_fee"]):"";
|
|
|
if($total_fee==''){
|
|
|
return error_show(1004,"参数 total_fee 不能为空");
|
|
@@ -204,18 +204,11 @@ class TagGood extends Base{
|
|
|
$tag_remark=isset($this->post["tag_remark"]) && $this->post["tag_remark"]!=""?$this->post["tag_remark"]:"";
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
- if(!empty($taglog)){
|
|
|
- $up = Db::name("tag_log")->where($taglog)->update(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
- if($up==false){
|
|
|
- Db::rollback();
|
|
|
- return error_show(1004,"标签日志新建失败");
|
|
|
- }
|
|
|
- }
|
|
|
if($taginfo['type']==1 || $taginfo['type']==2){
|
|
|
- $result= $this->payTag($taginfo['type'],$code,$total_fee);
|
|
|
+ $this->payTag($taginfo['type'],$code,$total_fee);
|
|
|
}
|
|
|
if($taginfo['type']==3|| $taginfo['type']==4){
|
|
|
- $result= $this->qrdTag($taginfo['type'],$code,$total_fee);
|
|
|
+ $this->qrdTag($taginfo['type'],$code,$total_fee);
|
|
|
}
|
|
|
$tagdata=[
|
|
|
"code"=>$code,
|
|
@@ -230,17 +223,10 @@ class TagGood extends Base{
|
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
|
];
|
|
|
$in =Db::name("tag_log")->insert($tagdata);
|
|
|
- if($in==false){
|
|
|
- Db::rollback();
|
|
|
- return error_show(1004,"标签日志新建失败");
|
|
|
- }
|
|
|
- $data =$result->getData();
|
|
|
- if($data['code']==0){
|
|
|
+ if($in==false) throw new \Exception("标签日志新建失败");
|
|
|
+
|
|
|
Db::commit();
|
|
|
return app_show(0,"标签添加成功");
|
|
|
- }
|
|
|
- Db::rollback();
|
|
|
- return error_show($data['code'],$data['message']);
|
|
|
}catch (\Exception $e){
|
|
|
Db::rollback();
|
|
|
return error_show(1004,$e->getMessage());
|
|
@@ -296,7 +282,8 @@ class TagGood extends Base{
|
|
|
$message="销售单{$loginfo->code}{$loginfo->tag_name}";
|
|
|
$this->qrdReTag($loginfo['type'],$loginfo->code,$pay_fee);
|
|
|
}
|
|
|
- $loginfo->status=0;
|
|
|
+ $loginfo['status']=0;
|
|
|
+ unset($loginfo['addtime'],$loginfo['updatetime']);
|
|
|
$loginfo->id=null;
|
|
|
TagLog::create($loginfo->toArray());
|
|
|
}catch (\Exception $exception){
|
|
@@ -316,31 +303,31 @@ class TagGood extends Base{
|
|
|
private function payTag($tagId,$code,$total_fee){
|
|
|
$pay=Db::name("pay")->where(["payNo"=>$code,"is_del"=>0])->findOrEmpty();
|
|
|
if(empty($pay)){
|
|
|
- return error_show(1004,"未找到对账单数据");
|
|
|
+ throw new \Exception('未找到对账单数据');
|
|
|
}
|
|
|
$update=["updatetime"=>date("Y-m-d H:i:s")];
|
|
|
if($tagId==1){
|
|
|
if($pay['wpay_fee']+$pay['pay_tag_fee']<$total_fee){
|
|
|
- return error_show(1004,"对账单未付金额不足");
|
|
|
+ throw new \Exception('对账单未付金额不足');
|
|
|
}
|
|
|
$update['wpay_fee']=$pay['wpay_fee']+$pay['pay_tag_fee']-$total_fee;
|
|
|
$status = $update['wpay_fee']==0 &&$pay['pay_fee']==0 ? 3:($pay['apay_fee']==0?1:2);
|
|
|
- $update['pay_tag_fee'] = $total_fee;
|
|
|
+ $update['pay_tag_fee'] += $total_fee;
|
|
|
$update['pay_status'] = $status;
|
|
|
$update['pay_tag'] = 1;
|
|
|
}
|
|
|
if($tagId==2){
|
|
|
if($pay['winv_fee']+$pay['inv_tag_fee']<$total_fee){
|
|
|
- return error_show(1004,"对账单未付金额不足");
|
|
|
+ throw new \Exception('对账单未开票金额不足');
|
|
|
}
|
|
|
$update['winv_fee']=$pay['winv_fee']+$pay['inv_tag_fee']-$total_fee;
|
|
|
$status = $update['winv_fee']==0 &&$pay['inv_fee']==0 ? 3:($pay['ainv_fee']==0?1:2);
|
|
|
- $update['inv_tag_fee'] = $total_fee;
|
|
|
+ $update['inv_tag_fee'] += $total_fee;
|
|
|
$update['inv_status'] = $status;
|
|
|
$update['inv_tag'] = 1;
|
|
|
}
|
|
|
$resulr= Db::name("pay")->where($pay)->update($update);
|
|
|
- return $resulr? app_show(0,"标签添加成功"):error_show(1004,"标签添加失败");
|
|
|
+ if($resulr==false) throw new \Exception('对账单更新失败');
|
|
|
}
|
|
|
|
|
|
/**解除标签
|
|
@@ -380,31 +367,31 @@ class TagGood extends Base{
|
|
|
private function qrdTag($tagId,$code,$total_fee){
|
|
|
$qrd=Db::name("qrd_info")->where(["sequenceNo"=>$code,"is_del"=>0])->findOrEmpty();
|
|
|
if(empty($qrd)){
|
|
|
- return error_show(1004,"未找到销售单数据");
|
|
|
+ throw new \Exception('未找到销售单数据');
|
|
|
}
|
|
|
$update=["updatetime"=>date("Y-m-d H:i:s")];
|
|
|
if($tagId==3){
|
|
|
if($qrd['wpay_fee']+$qrd['pay_tag_fee']<$total_fee){
|
|
|
- return error_show(1004,"对账单未付金额不足");
|
|
|
+ throw new \Exception('销售单未付金额不足');
|
|
|
}
|
|
|
$update['wpay_fee']=$qrd['wpay_fee']+$qrd['pay_tag_fee']-$total_fee;
|
|
|
$status = $update['wpay_fee']==0 &&$qrd['pay_fee']==0 ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
- $update['pay_tag_fee'] = $total_fee;
|
|
|
+ $update['pay_tag_fee'] += $total_fee;
|
|
|
$update['pay_status'] = $status;
|
|
|
$update['pay_tag'] = 1;
|
|
|
}
|
|
|
if($tagId==4){
|
|
|
if($qrd['winv_fee']+$qrd['inv_tag_fee']<$total_fee){
|
|
|
- return error_show(1004,"对账单未开票金额不足");
|
|
|
+ throw new \Exception('销售单未开票金额不足');
|
|
|
}
|
|
|
$update['winv_fee']=$qrd['winv_fee']+$qrd['inv_tag_fee']-$total_fee;
|
|
|
$status = $update['winv_fee']==0 &&$qrd['inv_fee']==0 ? 3:($qrd['ainv_fee']==0?1:2);
|
|
|
- $update['inv_tag_fee'] = $total_fee;
|
|
|
+ $update['inv_tag_fee'] += $total_fee;
|
|
|
$update['inv_status'] = $status;
|
|
|
$update['inv_tag'] = 1;
|
|
|
}
|
|
|
$resulr= Db::name("qrd_info")->where($qrd)->update($update);
|
|
|
- return $resulr? app_show(0,"标签添加成功"):error_show(1004,"标签添加失败");
|
|
|
+ if($resulr==false) throw new \Exception('标签添加失败');
|
|
|
}
|
|
|
|
|
|
/** 解除标签销售单
|