post['tradNo'])&&$this->post['tradNo']!=""?trim($this->post['tradNo']):""; if($tradNo==""){ return error_show(1004,"参数 tradNo 不能为空"); } $orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr'])?$this->post['orderArr']:[]; if(empty($orderArr)){ return error_show(1004,"参数 orderArr 不能为空"); } Db::startTrans(); try{ $logNo=makeNo("TRC"); $trade =Db::name("trade")->where(["tradNo"=>$tradNo,"is_del"=>0])->lock(true)->findOrEmpty(); if(empty($trade)){ Db::rollback(); return error_show(1004,"未找到资金信息"); } $total_fee =array_sum(array_column($orderArr,"trad_fee")); if ($trade['balance']<$total_fee){ Db::rollback(); return error_show(1004,"资金余额不足核销"); } $assoc=[]; foreach ($orderArr as $value){ if(!isset($value['sequenceNo'])||$value['sequenceNo']==""){ Db::rollback(); return error_show(1004,"销售单编号不能为空"); } if(!isset($value['trad_fee'])||$value['trad_fee']==""){ Db::rollback(); return error_show(1004,"销售单核销金额不能为空"); } $qrd =Db::name("qrd_info")->where("sequenceNo","=",$value['sequenceNo'])->field("id,customerNo,status,pay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty(); if(empty($qrd)){ Db::rollback(); return error_show(1004,"销售单信息未找到"); } if($qrd['wpay_fee']<$value['trad_fee']){ Db::rollback(); return error_show(1004,"销售单未付款金额不足核销金额"); } $updt=[ "pay_fee"=>$qrd['pay_fee']+$value['trad_fee'], "wpay_fee"=>$qrd['wpay_fee']-$value['trad_fee'], "pay_status"=>2, "status"=>1, "updatetime"=>date("Y-m-d H:i:s") ]; $qrdup = Db::name("qrd_info")->where($qrd)->update($updt); if($qrdup==false){ Db::rollback(); return error_show(1004,"销售单核销金额失败"); } $temp=[ "assocNo"=>makeNo("AS"), "apply_id"=>$this->uid, "apply_name"=>$this->uname, "type"=>2, "orderCode"=>$value['sequenceNo'], "customerNo"=>$qrd['customerNo'], "viceCode"=>$logNo, "order_total"=>$qrd['totalPrice'], "vice_total"=>$total_fee, "cancel_fee"=>$value['trad_fee'], "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $assoc[]=$temp; $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find(); if($report)$report->setField("logNo",$logNo); if($report)$report->setField("tradNo",$tradNo); } $asscin= Db::name("assoc")->insertAll($assoc); if($asscin!=count($assoc)){ Db::rollback(); return error_show(1004,"销售单核销金额关联失败"); } $update=[ "balance"=>$trade['balance']-$total_fee, "used_fee"=>$trade['used_fee']+$total_fee, "status"=>($trade['balance']-$total_fee)==0 ? 2:1, "updatetime"=>date("Y-m-d H:i:s"), ]; $tradup=Db::name("trade")->where($trade)->update($update); if($tradup){ $create = [ "logNo"=>$logNo, "tradNo"=>$tradNo, "companyNo"=>$trade['companyNo'], "apply_id"=>$this->uid, "apply_name"=>$this->uname, "trade_time"=>$trade['trade_time'], "total_fee"=>$total_fee, "status"=>1, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $tradchild =Db::name("trade_pool")->insert($create); if($tradchild){ Db::commit(); return app_show(0,"资金认领成功",["logNo"=>$logNo]); } } Db::rollback(); return error_show(1004,"资金认领失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } // 1待审批2审批通过3审批驳回4退款5解除认领 public function status(){ $logNo = isset($this->post['logNo'])&&$this->post['logNo']!=""?trim($this->post['logNo']):""; if($logNo==""){ return error_show(1004,"参数logNo不能为空"); } $status=isset($this->post['status'])&&$this->post['status']!=""?intval($this->post['status']):""; if($status==""){ return error_show(1004,"参数 status 不能为空"); } $remark=isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):""; // if($remark==""){ // return error_show(1004,"参数 remark 不能为空"); // } Db::startTrans(); try { $logingo= Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find(); if($logingo==false){ Db::rollback(); return error_show(1004,"资金认领信息未找到"); } $up=["status"=>$status,"updatetime"=>date("Y-m-d H:i:s"),"remark"=>$remark]; $logup = Db::name("trade_pool")->where($logingo)->update($up); if($logup){ if($status==2){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray(); if(!empty($qrdArr)){ foreach ($qrdArr as $value){ $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty(); if(empty($qrd)){ Db::rollback(); return error_show(1005,"未找到销售单数据"); } if($qrd['pay_fee']<$value['cancel_fee']){ Db::rollback(); return error_show(1005,"销售单待付金额不足"); } $update =[ "apay_fee"=>$qrd['apay_fee']+$value['cancel_fee'], "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'], "paytime"=>date("Y-m-d H:i:s"), "pay_status"=>$qrd['wpay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 3:2, "updatetime"=>date("Y-m-d H:i:s") ]; $qrdup =Db::name("qrd_info")->where($qrd)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } $asscup =[ "status"=>2, "assoc_time"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $assc=Db::name("assoc")->where($value)->update($asscup); if($assc==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } } } } if($status==3){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray(); if(!empty($qrdArr)){ foreach ($qrdArr as $value){ $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty(); if(empty($qrd)){ Db::rollback(); return error_show(1005,"未找到销售单数据"); } if($qrd['pay_fee']<$value['cancel_fee']){ Db::rollback(); return error_show(1005,"销售单待付金额不足"); } $update =[ "wpay_fee"=>$qrd['wpay_fee']+$value['cancel_fee'], "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'], "pay_status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 1:2, "status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ?0:1, "updatetime"=>date("Y-m-d H:i:s") ]; $qrdup =Db::name("qrd_info")->where($qrd)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } $asscup =[ "status"=>3, "updatetime"=>date("Y-m-d H:i:s") ]; $assc=Db::name("assoc")->where($value)->update($asscup); if($assc==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } $report=ReportCode::where(["qrdNo"=>$value['orderCode']])->find(); if($report)$report->rmField("logNo",$logNo); } } $trade =Db::name("trade")->where(["tradNo"=>$logingo['tradNo'],"is_del"=>0])->findOrEmpty(); if($trade==false){ Db::rollback(); return error_show(1005,"资金信息未找到"); } if($trade['used_fee']<$logingo['total_fee']){ Db::rollback(); return error_show(1005,"资金信息已认领金额不足"); } $tradup =[ "used_fee"=>$trade['used_fee']-$logingo['total_fee'], "balance"=>$trade['balance']+$logingo['total_fee'], "status"=>($trade['used_fee']-$logingo['total_fee'])==0 ? 0 :1, "updatetime"=>date("Y-m-d H:i:s") ]; $updaT=Db::name("trade")->where($trade)->update($tradup); if($updaT==false){ Db::rollback(); return error_show(1005,"资金信息更新失败"); } } Db::commit(); return app_show(0,"审核成功"); } Db::rollback(); return error_show(1004,"审核失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //资金信息列表 public function list(){ $condition=[]; $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1; $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15; $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):""; $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):""; $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):""; $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):""; $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):""; $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):""; $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):""; $used_lower =isset($this->post['userd_lower'])&&$this->post['userd_lower']!==""? floor($this->post['userd_lower']) :"0"; $used_upper =isset($this->post['used_upper'])&&$this->post['used_upper']!==""? floor($this->post['used_upper']):""; if($used_lower!=="")$condition[]=["used_fee",">=",$used_lower]; if($used_upper!=="")$condition[]=["used_fee","<=",$used_upper]; if($companyNo!==""){ $condition[]=["companyNo","=",$companyNo]; } $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :""; if($relaComNo!=""){ $condition[]=["companyNo","=",$relaComNo]; } if($tradNo!==""){ $condition[]=["tradNo","like","%$tradNo%"]; } if($bank!=""){ $condition[]=["trade_bank","like","%$bank%"]; } if($name!=""){ $condition[]=["trade_out","like","%$name%"]; } if($start!=""){ $condition[]=["trade_time",">=",$start." 00:00:00"]; } if($end!=""){ $condition[]=["trade_time","<=",$end." 23:59:59"]; } if($status!==""){ $condition[]=["status","=",$status]; } $count=Db::name("trade")->where($condition)->count(); $total=ceil($count/$size); $page=$page>$total? intval($total):$page; $list =Db::name("trade")->where($condition)->page($page,$size)->order("addtime desc")->select()->toArray(); foreach ($list as &$value){ $data = Db::name("trade_pool")->alias("a") ->leftJoin("assoc b","a.logNo=b.viceCode") ->leftJoin("qrd_info c","b.orderCode=c.sequenceNo") ->where(["a.tradNo"=>$value['tradNo'],"a.is_del"=>0]) ->order("a.addtime desc") ->field("a.*,b.orderCode,c.qrdSource,goodNo,goodName,qrdType,c.ownerName,c.ownerid,c.department,c.poCode") ->select()->toArray(); $value['child']=$data; } return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } // 认领资金列表明细 public function tradeList(){ $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1; $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15; $condition =[["a.is_del","=",0],["b.is_del","=",0]]; $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):""; $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):""; $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):""; $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):""; $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):""; $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):""; $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):""; $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):""; $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):""; $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):""; if($companyNo!==""){ $condition[]=["a.companyNo","=",$companyNo]; } $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :""; if($relaComNo!=""){ $condition[]=["companyNo","=",$relaComNo]; } if($tradNo!==""){ $condition[]=["a.tradNo","like","%$tradNo%"]; } if($orderCode!==""){ $condition[]=["d.orderCode","like","%$orderCode%"]; } $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=""? trim($this->post['logNo']):""; if($logNo!==""){ $condition[]=["a.logNo","like","%$logNo%"]; } if($bank!=""){ $condition[]=["b.trade_bank","like","%$bank%"]; } if($name!=""){ $condition[]=["b.trade_out","like","%$name%"]; } if($start!=""){ $condition[]=["a.add_time",">=",$start." 00:00:00"]; } if($end!=""){ $condition[]=["a.add_time","<=",$end." 23:59:59"]; } if($status!==""){ $condition[]=["a.status","=",$status]; } if($apply_id!==""){ $condition[]=["a.apply_id","=",$apply_id]; } if($apply_name!==""){ $condition[]=["a.apply_name","like","%$apply_name%"]; } $count=Db::name("trade_pool")->alias("a") ->leftJoin("trade b","a.tradNo=b.tradNo") ->leftJoin("assoc d","a.logNo=d.viceCode") ->leftJoin("qrd_info c","d.orderCode=c.sequenceNo") ->where($condition)->count(); $total=ceil($count/$size); $page=$page>$total? intval($total):$page; $list =Db::name("trade_pool")->alias("a") ->leftJoin("trade b","a.tradNo=b.tradNo") ->leftJoin("assoc d","a.logNo=d.viceCode") ->leftJoin("qrd_info c","d.orderCode=c.sequenceNo") ->where($condition) ->page($page,$size) ->field("a.*,b.trade_bank,b.trade_account,b.trade_out,b.total_fee as btotal_fee,b.used_fee,b.balance, d.orderCode,c.qrdSource,c.goodNo,c.goodName,c.qrdType,c.ownerName,c.ownerid,c.department,c.poCode,c.platName,c.totalPrice,d.cancel_fee") ->order("a.addtime desc")->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } // 获取资金下面的认领信息 public function tradeQuery(){ $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):""; $status =isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):""; $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):""; $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):""; $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):""; if($companyNo!==""){ $condition[]=["companyNo","=",$companyNo]; } $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :""; if($relaComNo!=""){ $condition[]=["companyNo","=",$relaComNo]; } $condition=[["is_del","=",0]]; if($apply_id!==""){ $condition[]=["apply_id","=",$apply_id]; } if($apply_name!==""){ $condition[]=["apply_name","like","%$apply_name%"]; } if($status!==""){ $condition[]=["status","=",$status]; } if($tradNo!==""){ $condition[]=["tradNo","like","%$tradNo%"]; } $list =Db::name("trade_pool")->where($condition)->order("addtime desc")->select(); return app_show(0,"获取成功",$list); } //资金详情 public function tradeInfo(){ $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):""; if($tradNo==""){ return error_show(1004,"参数 tradNo 不能为空"); } $tradinfo = Db::name("trade")->where(["tradNo"=>$tradNo,"is_del"=>0])->find(); if($tradinfo==false){ return error_show(1004,"资金信息未找到"); } return app_show(0,"获取成功",$tradinfo); } //资金认领详情 public function logInfo(){ $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=""? trim($this->post['logNo']):""; if($logNo==""){ return error_show(1004,"参数 logNo 不能为空"); } $tradinfo = Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find(); if($tradinfo==false){ return error_show(1004,"资金信息未找到"); } $trade = Db::name("trade")->where(["tradNo"=>$tradinfo['tradNo'],"is_del"=>0])->find(); $tradinfo['trade_out']= $trade['trade_out']??""; $tradinfo['trade_in']= $trade['trade_in']??""; $tradinfo['trade_bank']= $trade['trade_bank']??""; $tradinfo['customerNo']= $trade['customerNo']??""; $tradinfo['companyNo']= $trade['companyNo']??""; $tradinfo['total_fee']= $trade['total_fee']??""; $tradinfo['balance']= $trade['balance']??""; $tradinfo['used_fee']= $trade['used_fee']??""; $orderinfo = Db::name("assoc")->alias("a")->leftJoin("qrd_info c","a.orderCode=c.sequenceNo") ->where(["a.viceCode"=>$logNo,"a.is_del"=>0,"a.status"=>[1,2,3]]) ->order("a.addtime desc") ->field("c.*,a.cancel_fee") ->findOrEmpty(); $tradinfo['orderinfo']=$orderinfo; return app_show(0,"获取成功",$tradinfo); } //认领资金退回或退款 type 1 退款 2 解除资金认领 public function ReturnPay(){ $logNo = isset($this->post['logNo'])&&$this->post['logNo']!="" ? trim($this->post['logNo']):""; if($logNo==''){ return error_show(1004,"参数 logNo 不能为空"); } $type = isset($this->post['type'])&&$this->post['type']!="" ? intval($this->post['type']):""; if($type==""){ return error_show(1004,"参数 type 不能为空"); } $loginfo = Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find(); if($loginfo==false){ return error_show(1004,"认领资金信息未找到"); } if($loginfo['status']!=2)return error_show(1004,"认领资金信息审核未通过"); $tradinfo = Db::name("trade")->where(["tradNo"=>$loginfo['tradNo'],"is_del"=>0])->find(); if($tradinfo==false){ return error_show(1004,"资金信息未找到"); } $reason = isset($this->post['return_reason'])&&$this->post['return_reason']!="" ? trim($this->post['return_reason']):""; $remark = isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):""; $returnCode =makeNo("RTA"); $data=[ "returnCode"=>$returnCode, "logNo"=>$logNo, "companyNo"=>$tradinfo['companyNo'], "tradNo"=>$loginfo['tradNo'], "type"=>$type, "apply_id"=>$this->uid, "apply_name"=>$this->uname, "return_reason"=>$reason, "remark"=>$remark, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $in = Db::name("trade_return")->insert($data); if($in){ return app_show(0,"申请新建成功"); }else{ return error_show(1004,"申请新建失败"); } } /**退款列表 * //page size tradNo logNo apply_id apply_name type status returnCode * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function returnList(){ $page=isset($this->post['page'])&&$this->post['page']!='' ? intval($this->post['page']):1; $size=isset($this->post['size'])&&$this->post['size']!='' ? intval($this->post['size']):15; $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=''?trim($this->post['tradNo']):""; $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=''?trim($this->post['logNo']):""; $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=''?intval($this->post['apply_id']):""; $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=''?trim($this->post['apply_name']):""; $type =isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):""; $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):""; $returnCode =isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):""; $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):""; $companyNo =isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']):""; if($companyNo!==""){ $condition[]=["a.companyNo","=",$companyNo]; } $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :""; if($relaComNo!=""){ $condition[]=["a.companyNo","=",$relaComNo]; } $condition=[["a.is_del","=",0]]; if($tradNo!=''){ $condition[]=["a.tradNo","like","%$tradNo%"]; } if($orderCode!=''){ $condition[]=["b.orderCode","like","%$orderCode%"]; } if($logNo!=''){ $condition[]=["a.logNo","like","%$logNo%"]; } if($apply_id!=''){ $condition[]=["a.apply_id","=",$apply_id]; } if($apply_name!=''){ $condition[]=["a.apply_name","like","%$apply_name%"]; } if($returnCode!=''){ $condition[]=["a.returnCode","like","%$returnCode%"]; } if($type!=''){ $condition[]=["a.type","=",$type]; } if($status!=''){ $condition[]=["a.status","=",$status]; } $count =Db::name("trade_return")->alias("a") ->leftJoin("assoc b","a.logNo=b.viceCode") ->leftJoin("qrd_info c","c.sequenceNo=b.orderCode") ->where($condition)->count(); $total=ceil($count/$size); $page = $page>$total ? intval($total):$page; $list=Db::name("trade_return")->alias("a")->leftJoin("assoc b","a.logNo=b.viceCode") ->leftJoin("qrd_info c","c.sequenceNo=b.orderCode") ->field("a.*,b.orderCode,c.qrdSource,goodNo,goodName,qrdType,c.ownerName,c.ownerid,c.department,c.poCode,c.platName,b.cancel_fee,c.customerName") ->where($condition)->page($page,$size)->order("a.addtime desc")->select(); return app_show(0,"获取成功",["list"=>$list,"count"=>$count]); } //退款状态审核 0 待审核 1 财务审核 2 财务驳回 public function returnStatus(){ $returnCode=isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):""; if($returnCode==''){ return error_show(1004,"参数 returnCode 不能为空"); } $returninfo =Db::name("trade_return")->where(["returnCode"=>$returnCode,"is_del"=>0])->find(); if($returninfo==false){ return error_show(1004,"退款申请数据未找到"); } $status=isset($this->post['status']) &&$this->post['status']!=''?intval($this->post['status']) : ''; if($status==''){ return error_show(1004,"参数 status 不能为空"); } $return_img = isset($this->post['return_img'])&&$this->post['return_img']!=''?trim($this->post['return_img']):""; $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):""; $loginfo = Db::name("trade_pool")->where(["logNo"=>$returninfo['logNo'],"is_del"=>0])->find(); if($loginfo==false){ return error_show(1004,"认领资金信息未找到"); } if($loginfo['status']!=2)return error_show(1004,"认领资金信息审核未通过"); Db::startTrans(); try{ $update=["status"=>$status,"return_img"=>$return_img,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")]; $up =Db::name("trade_return")->where($returninfo)->update($update); if($up){ if($status==1){ $qrdArr=Db::name("assoc")->where(["viceCode"=>$returninfo['logNo'],"status"=>2,"is_del"=>0])->select() ->toArray(); if(!empty($qrdArr)){ foreach ($qrdArr as $value){ $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty(); if(empty($qrd)){ Db::rollback(); return error_show(1005,"未找到销售单数据"); } if($qrd['apay_fee']<$value['cancel_fee']){ Db::rollback(); return error_show(1005,"销售单待付金额不足"); } $update =[ "wpay_fee"=>$qrd['wpay_fee']+$value['cancel_fee'], "apay_fee"=>$qrd['apay_fee']-$value['cancel_fee'], "pay_status"=>($qrd['apay_fee']-$value['cancel_fee'])==0 && $qrd['pay_fee']==0 ? 1:2, "status"=>$qrd['pay_fee']==0 && ($qrd['apay_fee']-$value['cancel_fee'])==0 ?0:1, "updatetime"=>date("Y-m-d H:i:s") ]; $qrdup =Db::name("qrd_info")->where($qrd)->update($update); if($qrdup==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } $asscup =[ "status"=>3, "updatetime"=>date("Y-m-d H:i:s") ]; $assc=Db::name("assoc")->where($value)->update($asscup); if($assc==false){ Db::rollback(); return error_show(1005,"销售单更新失败"); } $report=ReportCode::where(["qrdNo"=>$value['orderCode']])->find(); if($report)$report->setField("returnTrad",$returnCode); } } $logup =["status"=>$returninfo['type']==1?5:4,"updatetime"=>date("Y-m-d H:i:s")]; $upde =Db::name("trade_pool")->where($loginfo)->update($logup); if($upde==false){ Db::rollback(); return error_show(1005,"资金认领信息更新失败"); } // if($returninfo['type']==1){ $trade =Db::name("trade")->where(["tradNo"=>$returninfo['tradNo'],"is_del"=>0])->find(); if($trade==false){ Db::rollback(); return error_show(1005,"资金信息未找到"); } if($trade['used_fee']<$loginfo['total_fee']){ Db::rollback(); return error_show(1005,"资金信息已认领金额不足"); } $tradup =[ "used_fee"=>$trade['used_fee']-$loginfo['total_fee'], "balance"=>$trade['balance']+$loginfo['total_fee'], "status"=>($trade['used_fee']-$loginfo['total_fee'])==0 ? 0 :1, "updatetime"=>date("Y-m-d H:i:s") ]; $updaT=Db::name("trade")->where($trade)->update($tradup); if($updaT==false){ Db::rollback(); return error_show(1005,"资金信息更新失败"); } // } } Db::commit(); return app_show(0,"退款申请审核成功"); } Db::rollback(); return error_show(1004,'审核状态失败'); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } //退款申请详情 public function returnInfo(){ $returnCode=isset($this->post['returnCode'])&&$this->post['returnCode']!=''?trim($this->post['returnCode']):""; if($returnCode==''){ return error_show(1004,"参数 returnCode 不能为空"); } $returninfo =Db::name("trade_return")->where(["returnCode"=>$returnCode,"is_del"=>0])->find(); if($returninfo==false){ return error_show(1004,"退款申请数据未找到"); } $trade = Db::name("trade")->where(["tradNo"=>$returninfo['tradNo'],"is_del"=>0])->find(); $returninfo['trade_out']= $trade['trade_out']??""; $returninfo['trade_in']= $trade['trade_in']??""; $returninfo['trade_bank']= $trade['trade_bank']??""; $returninfo['trade_time']= $trade['trade_time']??""; $returninfo['customerNo']= $trade['customerNo']??""; $returninfo['companyNo']= $trade['companyNo']??""; $returninfo['total_fee']= $trade['total_fee']??""; $returninfo['balance']= $trade['balance']??""; $returninfo['used_fee']= $trade['used_fee']??""; $pool =Db::name("trade_pool")->where(["logNo"=>$returninfo['logNo'],"is_del"=>0])->find(); $returninfo['log_total_fee']= $pool['total_fee']??""; $returninfo['log_apply_id']= $pool['apply_id']??""; $returninfo['log_apply_name']= $pool['apply_name']??""; $orderinfo = Db::name("assoc")->alias("a")->leftJoin("qrd_info c","a.orderCode=c.sequenceNo") ->where(["a.viceCode"=>$returninfo['logNo'],"a.is_del"=>0,"a.status"=>[1,2]]) ->order("a.addtime desc") ->field("c.*") ->findOrEmpty(); $returninfo['orderinfo'] = $orderinfo; return app_show(0,"获取成功",$returninfo); } /** * 显示创建资源表单页. * * @return \think\Response */ public function importTrade() { $files = $this->request->file("excel"); $data = upload($files,$files->getOriginalExtension()); if($data['code']!=0){ return error_show(1004,$data['msg']); } $trade = $data['data']; $list = []; foreach ( $trade as $key => $value) { if (!isset($value[0]) || $value[0] == '') { //return ['code' => 1003, "msg" => '交易时间不能为空']; return error_show( 1003, '第'.($key+1).'行收款方公司编号不能为空!'); } if (!isset($value[4]) || $value[4] == '') { // return ['code' => 1003, "msg" => '交易行名不能为空']; return error_show( 1003, '第'.($key+1).'行收入金额不能为空!'); } if (!isset($value[8]) || $value[8] == '') { // return ['code' => 1003, "msg" => '对方账户不能为空']; return error_show( 1003, '第'.($key+1).'行对方账户不能为空!'); } if (!isset($value[9]) || $value[9] == '') { // return ['code' => 1003, "msg" => '对方户名不能为空']; return error_show( 1003, '第'.($key+1).'行对方户名不能为空!'); } if ($key == 0) { if ($value[0] != '收款方公司编号') { // return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!']; return error_show( 1003, '模板第一列为必须为收款方公司编号!'); } if ($value[4] != '收入金额') { // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!']; return error_show( 1003, '模板第五列为必须为收入金额!'); } if ($value[6] != '交易行名') { //return ['code' => 1003, "msg" => '模板第五列为必须为交易行名!']; return error_show( 1003, '模板第七列为必须为交易行名!'); } if ($value[8] != '对方账号') { // return ['code' => 1003, "msg" => '模板第七列为必须为对方账号!']; return error_show( 1003, '模板第九列为必须为对方账号!'); } if ($value[9] != '对方户名') { // return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!']; return error_show( 1003, '模板第十列为必须为对方户名!'); } continue; } $company =Db::name("company_info")->where(["companyNo"=>$value[0]])->findOrEmpty(); if(empty($company)){ return error_show( 1003, "业务公司编号不存在{$value[0]}"); } $total_fee = $value[4]; $type = 0; $time = explode(" ", $value[3]); $list[$key]["tradeTime"] = date("Y-m-d", strtotime($time[0])) . " " . (isset($time[1]) ? $time[1] : "00:00:00"); $list[$key]["trade_fee"] = str_replace(",","",$total_fee); $list[$key]["trade_bank"] = $value[6]; $list[$key]["trade_account"] = $value[8]; $list[$key]["trade_out"] = $value[9]; $list[$key]["trade_in"] = $value[1]??$company['company_name']; $list[$key]["trade_type"] = $type; $list[$key]["trade_used"] = isset($value[10]) ? $value[10] : ""; $list[$key]["trade_remark"] = ''; $list[$key]["companyNo"] = $value[0]; $list[$key]["trade_in_account"] = $value[2]??""; } if(empty($list)){ return error_show( 1003, '导入数据不能为空!'); } Db::startTrans(); try{ $tra=[]; foreach ($list as $value) { $temp = []; $temp["tradNo"] = makeStr('S'); $temp['trade_time'] = $value['tradeTime']; $temp['total_fee'] = $value['trade_fee']; $temp['trade_bank'] = $value['trade_bank']; $temp['trade_account'] = $value['trade_account']; $temp['trade_type'] =$value['trade_type']; $temp['trade_out'] = $value['trade_out']; $temp['trade_in'] = $value['trade_in']; $temp['trade_in_account'] = $value['trade_in_account']; $temp['companyNo'] = $value['companyNo']; $temp['trade_used'] = $value['trade_used']; $temp['trade_remark'] = $value['trade_remark']; $temp['balance'] =$value['trade_fee']; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $tra[]=$temp; } $list = Db::name('trade')->insertAll($tra); if($list==count($tra)){ Db::commit(); return app_show(0, "资金导入成功"); }else{ Db::rollback(); return app_show(1004, "资金导入失败"); } }catch (\Exception $e){ Db::rollback(); return app_show(1004, $e->getMessage()); } } /** * @return \think\response\Json|void */ public function importTradeByArr() { $trade =isset($this->post['data']) &&!empty($this->post['data'])? $this->post['data']:[]; if(!is_array($trade) || empty($trade) ) return error_show( 1003,"参数 data 不能为空"); $list = []; foreach ( $trade as $key => $value) { if (!isset($value[0]) || $value[0] == '') { //return ['code' => 1003, "msg" => '交易时间不能为空']; return error_show( 1003, '第'.($key+1).'行收款方公司编号不能为空!'); } if (!isset($value[4]) || $value[4] == '') { // return ['code' => 1003, "msg" => '交易行名不能为空']; return error_show( 1003, '第'.($key+1).'行收入金额不能为空!'); } if (!isset($value[8]) || $value[8] == '') { // return ['code' => 1003, "msg" => '对方账户不能为空']; return error_show( 1003, '第'.($key+1).'行对方账户不能为空!'); } if (!isset($value[9]) || $value[9] == '') { // return ['code' => 1003, "msg" => '对方户名不能为空']; return error_show( 1003, '第'.($key+1).'行对方户名不能为空!'); } // if ($key == 0) { // if ($value[0] != '收款方公司编号') { // // return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!']; // return error_show( 1003, '模板第一列为必须为收款方公司编号!'); // } // if ($value[4] != '收入金额') { // // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!']; // return error_show( 1003, '模板第五列为必须为收入金额!'); // } // // if ($value[6] != '交易行名') { // //return ['code' => 1003, "msg" => '模板第五列为必须为交易行名!']; // return error_show( 1003, '模板第七列为必须为交易行名!'); // } // if ($value[8] != '对方账号') { // // return ['code' => 1003, "msg" => '模板第七列为必须为对方账号!']; // return error_show( 1003, '模板第九列为必须为对方账号!'); // } // if ($value[9] != '对方户名') { // // return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!']; // return error_show( 1003, '模板第十列为必须为对方户名!'); // } // continue; // } $company =Db::name("company_info")->where(["companyNo"=>$value[0]])->findOrEmpty(); if(empty($company)){ return error_show( 1003, "业务公司编号不存在{$value[0]}"); } $total_fee = $value[4]; $type = 0; $time = explode(" ", $value[3]); $list[$key]["tradeTime"] = date("Y-m-d", strtotime($time[0])) . " " . (isset($time[1]) ? $time[1] : "00:00:00"); $list[$key]["trade_fee"] = str_replace(",","",$total_fee); $list[$key]["trade_bank"] = $value[6]; $list[$key]["trade_account"] = $value[8]; $list[$key]["trade_out"] = $value[9]; $list[$key]["trade_in"] = $value[1]??$company['company_name']; $list[$key]["trade_type"] = $type; $list[$key]["trade_used"] = isset($value[10]) ? $value[10] : ""; $list[$key]["trade_remark"] = ''; $list[$key]["companyNo"] = $value[0]; $list[$key]["trade_in_account"] = $value[2]??""; } if(empty($list)){ return error_show( 1003, '导入数据不能为空!'); } Db::startTrans(); try{ $tra=[]; foreach ($list as $value) { $temp = []; $temp["tradNo"] = makeStr('S'); $temp['trade_time'] = $value['tradeTime']; $temp['total_fee'] = $value['trade_fee']; $temp['trade_bank'] = $value['trade_bank']; $temp['trade_account'] = $value['trade_account']; $temp['trade_type'] =$value['trade_type']; $temp['trade_out'] = $value['trade_out']; $temp['trade_in'] = $value['trade_in']; $temp['trade_in_account'] = $value['trade_in_account']; $temp['companyNo'] = $value['companyNo']; $temp['trade_used'] = $value['trade_used']; $temp['trade_remark'] = $value['trade_remark']; $temp['balance'] =$value['trade_fee']; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $tra[]=$temp; } $list = Db::name('trade')->insertAll($tra); if($list==count($tra)){ Db::commit(); return app_show(0, "资金导入成功"); }else{ Db::rollback(); return app_show(1004, "资金导入失败"); } }catch (\Exception $e){ Db::rollback(); return app_show(1004, $e->getMessage()); } } }