|
@@ -3,7 +3,7 @@
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
use app\admin\BaseController;
|
|
|
-use think\App;
|
|
|
+use Exception;use think\App;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class OrderInv extends BaseController{
|
|
@@ -50,37 +50,60 @@ class OrderInv extends BaseController{
|
|
|
$temp =[];
|
|
|
$invNo=makeNo("INV");
|
|
|
$invfee=array_sum(array_column($orderArr,'inv_fee'));
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ foreach ($orderArr as $value){
|
|
|
+ if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"参数 sequenceNo 不能为空");
|
|
|
+ }
|
|
|
+ $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find();
|
|
|
+ if($qrd['status']==2){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"确认单{$value['sequenceNo']}不参与对账");
|
|
|
+ }
|
|
|
+ if(!isset($value['inv_fee']) || $value['inv_fee']===''){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"参数 inv_fee 不能为空");
|
|
|
+ }
|
|
|
+ if($qrd['winv_fee']<$value['inv_fee']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
|
|
|
+ }
|
|
|
+ $ascc=[
|
|
|
+ "assocNo"=>makeNo("AS"),
|
|
|
+ "apply_id"=>$this->uid,
|
|
|
+ "apply_name"=>$this->uname,
|
|
|
+ "type"=>1,
|
|
|
+ "orderCode"=>$value['sequenceNo'],
|
|
|
+ "viceCode"=>$invNo,
|
|
|
+ "order_total"=>$qrd['totalPrice'],
|
|
|
+ "vice_total"=>$invfee,
|
|
|
+ "cancel_fee"=>$value['inv_fee'],
|
|
|
+ "status"=>1,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $update = [
|
|
|
+ "inv_fee"=>$qrd['inv_fee']+$value['inv_fee'],
|
|
|
+ "winv_fee"=>$qrd['winv_fee']-$value['inv_fee'],
|
|
|
+ "inv_status"=>2,
|
|
|
+ "status"=>1,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $up = Db::name("qrd_info")->where($qrd)->update($update);
|
|
|
+ if($up==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"确认单{$value['sequenceNo']} 更新失败");
|
|
|
+ }
|
|
|
+ $temp[]=$ascc;
|
|
|
+ }
|
|
|
+ $associn = Db::name("assoc")->insertAll($temp);
|
|
|
+ if($associn==0){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"确认单申请开票失败");
|
|
|
+ }
|
|
|
|
|
|
- foreach ($orderArr as $value){
|
|
|
- if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){
|
|
|
- return error_show(1004,"参数 sequenceNo 不能为空");
|
|
|
- }
|
|
|
- $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find();
|
|
|
- if($qrd['status']==2){
|
|
|
- return error_show(1004,"确认单{$value['sequenceNo']}不参与对账");
|
|
|
- }
|
|
|
- if(!isset($value['inv_fee']) || $value['inv_fee']===''){
|
|
|
- return error_show(1004,"参数 inv_fee 不能为空");
|
|
|
- }
|
|
|
- if($qrd['winv_fee']<$value['inv_fee']){
|
|
|
- return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
|
|
|
- }
|
|
|
- $ascc=[
|
|
|
- "assocNo"=>makeNo("AS"),
|
|
|
- "apply_id"=>$this->uid,
|
|
|
- "apply_name"=>$this->uname,
|
|
|
- "type"=>1,
|
|
|
- "orderCode"=>$value['sequenceNo'],
|
|
|
- "viceCode"=>$invNo,
|
|
|
- "order_total"=>$qrd['totalPrice'],
|
|
|
- "vice_total"=>$invfee,
|
|
|
- "cancel_fee"=>$value['inv_fee'],
|
|
|
- "status"=>1,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $temp[]=$ascc;
|
|
|
- }
|
|
|
$inv=[
|
|
|
"invNo"=>$invNo,
|
|
|
"inv_value"=>$invfee,
|
|
@@ -101,6 +124,491 @@ class OrderInv extends BaseController{
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
|
];
|
|
|
+ $invin = Db::name("invoice_pool")->insert($inv);
|
|
|
+ if($invin){
|
|
|
+ $invinfo=[
|
|
|
+ "buyer_title"=>$buyinfo['invoice_title'],
|
|
|
+ "buyer_code"=>$buyinfo['invoice_code'],
|
|
|
+ "buyer_addr"=>$buyinfo['invoice_addr'],
|
|
|
+ "buyer_mobile"=>$buyinfo['invoice_mobile'],
|
|
|
+ "buyer_bank"=>$buyinfo['invoice_bank'],
|
|
|
+ "buyer_bankNo"=>$buyinfo['invoice_bankNo'],
|
|
|
+ "seller_title"=>$company['company_name'],
|
|
|
+ "seller_code"=>$company['company_license'],
|
|
|
+ "seller_addr"=>$company['company_address'],
|
|
|
+ "seller_mobile"=>$company['mobile'],
|
|
|
+ "seller_bank"=>$company['bank_name'],
|
|
|
+ "seller_bankNo"=>$company['bankNo'],
|
|
|
+ "invNo"=>$invNo,
|
|
|
+ "voider"=>$company['voider'],
|
|
|
+ "payee"=>$company['payee'],
|
|
|
+ "drawer"=>$company['drawer'],
|
|
|
+ "reviewer"=>$company['reviewer'],
|
|
|
+ "ownerPlace"=>$company['ownerPlace'],
|
|
|
+ "addtime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $poolinfo =Db::name("invoice_pool_info")->insert($invinfo);
|
|
|
+ if($poolinfo){
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"确认单发票申请成功",["invNo"=>$invNo]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"确认单发票申请失败");
|
|
|
+ }catch (Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 0 待财务开票/待金税开票 1待财务审核 2待填写物流 3开票完成 4开票失败/开票驳回 5财务驳回 6退票
|
|
|
+ public function status(){
|
|
|
+ $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
|
|
|
+ if($invNo==""){
|
|
|
+ return error_show(1004,"参数 invNo 不能为空");
|
|
|
+ }
|
|
|
+ $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
|
|
|
+ if($invinfo==false){
|
|
|
+ return error_show(1004,"发票申请数据未找到");
|
|
|
+ }
|
|
|
+ $status= isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
|
|
|
+ if($status===''){
|
|
|
+ return error_show(1004,"参数 status 不能为空");
|
|
|
+ }
|
|
|
+ //open_type 1 金税开票 2 金税线下开票 3 线下开票
|
|
|
+ $open_type = isset($this->post['open_type'])&&$this->post['open_type']!==''?intval($this->post['open_type']):"";
|
|
|
+
|
|
|
+ $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
|
|
|
+
|
|
|
+// $invArr=isset($this->post['invArr'])&&!empty($this->post['invArr'])?$this->post['invArr']:[];
|
|
|
+ $invCode =isset($this->post['invCode'])&&$this->post['invCode']!=''?trim($this->post['invCode']):"";
|
|
|
+ $invNum =isset($this->post['invNum'])&&$this->post['invNum']!=''?trim($this->post['invNum']):"";
|
|
|
+ $open_date =isset($this->post['open_date'])&&$this->post['open_date']!=''?trim($this->post['open_date']):"";
|
|
|
+ $total_fee =isset($this->post['total_fee'])&&$this->post['total_fee']!=''?floor($this->post['total_fee']):"";
|
|
|
+ $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floor($this->post['subtotal_fee']):"";
|
|
|
+
|
|
|
+ if($status==1){
|
|
|
+ if($open_type==='')return error_show(1004,"参数 open_type 不能为空");
|
|
|
+ if($open_type!=1){
|
|
|
+ if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
|
|
|
+ if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
|
|
|
+ if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
|
|
|
+ if($total_fee==='') return error_show(1004,"参数 tatal_fee 不能为空");
|
|
|
+ if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
|
|
|
+ if($total_fee!=$invinfo['inv_value'])return error_show(1004,"发票金额不足");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $update=[
|
|
|
+ "status"=>$status,
|
|
|
+ "exam_remark"=>$remark,
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $status==1 ? $update['open_type']=$open_type :"";
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+
|
|
|
+ $invup =Db::name("invoice_pool")->where($invinfo)->update($update);
|
|
|
+ if($invup){
|
|
|
+ if($status==1 && $open_type!=1){
|
|
|
+ $temp=[];
|
|
|
+ $invpool=[
|
|
|
+ "invNo"=>$invinfo['invNo'],
|
|
|
+ "inv_type"=>$open_type,
|
|
|
+ "inv_code"=>$invCode,
|
|
|
+ "inv_number"=>$invNum,
|
|
|
+ "inv_total"=>$total_fee,
|
|
|
+ "inv_subtotal"=>$subtotal_fee,
|
|
|
+ "open_date"=>$open_date,
|
|
|
+ "status"=>1,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+// foreach ($invArr as $value){
|
|
|
+// $invpool=[
|
|
|
+// "invNo"=>$invinfo['invNo'],
|
|
|
+// "in_type"=>$open_type,
|
|
|
+// "inv_code"=>$value['inv_code'],
|
|
|
+// "inv_number"=>$value['inv_number'],
|
|
|
+// "inv_total"=>$value['inv_total'],
|
|
|
+// "inv_subtotal"=>$value['inv_subtotal'],
|
|
|
+// "open_date"=>$value['open_date'],
|
|
|
+// "status"=>1,
|
|
|
+// "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+// "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+// ];
|
|
|
+// $temp[]=$invpool;
|
|
|
+// }
|
|
|
+
|
|
|
+ // $in = Db::name("invoice_ticket")->insertAll($temp);
|
|
|
+ $in = Db::name("invoice_ticket")->insert($invpool);
|
|
|
+ if($in==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"发票信息添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($status==4 ||$status==5 ){
|
|
|
+ $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->column("id,orderCode,cancel_fee");
|
|
|
+ if(!empty($qrdArr)){
|
|
|
+ foreach ($qrdArr as $value){
|
|
|
+ $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
|
|
|
+ if($qrdinfo==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息未找到");
|
|
|
+ }
|
|
|
+ if($qrdinfo['inv_fee']<$value['cancel_fee']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息开票金额不足");
|
|
|
+ }
|
|
|
+ $update =[
|
|
|
+ "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
|
|
|
+ "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
|
|
|
+ "inv_status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 1 : 2,
|
|
|
+ "status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ?0 : 1,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
|
|
|
+ if($qrdup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息更新失败");
|
|
|
+ }
|
|
|
+ $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $assocup =Db::name("assoc")->where($value)->update($assoc);
|
|
|
+ if($assocup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单关联信息更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 SetPost(){
|
|
|
+ // @param invNo postCompany postCode postFee;
|
|
|
+ $invNo =isset($this->post['invNo'])&&$this->post['invNo']!="" ? trim($this->post['invNo']):"";
|
|
|
+ if($invNo==''){
|
|
|
+ return error_show(1004,"参数invNo不能为空");
|
|
|
+ }
|
|
|
+ $invinfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
|
|
|
+ if($invinfo==false){
|
|
|
+ return error_show(1004,"发票申请信息未找到");
|
|
|
+ }
|
|
|
+ $post_company =isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
|
|
|
+ if($post_company==''){
|
|
|
+ return error_show(1004,"参数 post_company 不能为空");
|
|
|
+ }
|
|
|
+ $post_code =isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
|
|
|
+ if($post_code==''){
|
|
|
+ return error_show(1004,"参数 post_code 不能为空");
|
|
|
+ }
|
|
|
+ $post_fee =isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? floor($this->post['post_fee']):"0";
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $data=[
|
|
|
+ "post_company"=>$post_company,
|
|
|
+ "post_code"=>$post_code,
|
|
|
+ "post_fee"=>$post_fee,
|
|
|
+ "status"=>3,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $up =Db::name("invoice_pool")->where($invinfo)->update($data);
|
|
|
+ if($up){
|
|
|
+ $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->column("id,orderCode,cancel_fee");
|
|
|
+ if(!empty($qrdArr)){
|
|
|
+ foreach ($qrdArr as $value){
|
|
|
+ $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
|
|
|
+ if($qrdinfo==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息未找到");
|
|
|
+ }
|
|
|
+ if($qrdinfo['inv_fee']<$value['cancel_fee']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息开票金额不足");
|
|
|
+ }
|
|
|
+ $update =[
|
|
|
+ "ainv_fee"=>$qrdinfo['ainv_fee']+$value['cancel_fee'],
|
|
|
+ "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
|
|
|
+ "inv_tme"=>date("Y-m-d H:i:s"),
|
|
|
+ "inv_status"=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
|
|
|
+ if($qrdup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息更新失败");
|
|
|
+ }
|
|
|
+ $assoc=["status"=>2,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $assocup =Db::name("assoc")->where($value)->update($assoc);
|
|
|
+ if($assocup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单关联信息更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"更新成功");
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"发票申请信息更新失败");
|
|
|
+ }catch (Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 发票废弃使用
|
|
|
+ */
|
|
|
+ public function Discard(){
|
|
|
+
|
|
|
+ }
|
|
|
+ /**@param invNo return_reason remark 退票申请
|
|
|
+ * @return \think\response\Json|void
|
|
|
+ */
|
|
|
+ public function ReturnAdd(){
|
|
|
+ $invNo = isset($this->post['invNo']) && $this->post['invNo']!=''? trim($this->post['invNo']) :'';
|
|
|
+ if($invNo==""){
|
|
|
+ return error_show(1004,"参数 invNo 不能为空");
|
|
|
+ }
|
|
|
+ $return_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']) :'';
|
|
|
+ if($return_reason==""){
|
|
|
+ return error_show(1004,"参数 return_reason 不能为空");
|
|
|
+ }
|
|
|
+ if($remark==""){
|
|
|
+ return error_show(1004,"参数 remark 不能为空");
|
|
|
+ }
|
|
|
+ $returnCode = makeNo("RIN");
|
|
|
+ $data=[
|
|
|
+ "returnCode"=>$returnCode,
|
|
|
+ "invNo"=>$invNo,
|
|
|
+ "return_reason"=>$return_reason,
|
|
|
+ "remark"=>$remark,
|
|
|
+ "status"=>0,
|
|
|
+ "apply_id"=>$this->uid,
|
|
|
+ "apply_name"=>$this->uname,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $inter = Db::name("invoice_return")->insert($data);
|
|
|
+ if($inter){
|
|
|
+ return app_show(0,"退票申请新建成功",["returnCode"=>$returnCode]);
|
|
|
+ }else{
|
|
|
+ return error_show(1005,"退票申请新建失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 0 待审核 1 待退票 2 退票成功 3 驳回4 退票失败
|
|
|
+ public function ReturnStatus(){
|
|
|
+ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
|
|
|
+ if($returnCode==""){
|
|
|
+ return error_show(1005,"参数 returnCode 不能为空");
|
|
|
+ }
|
|
|
+ $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):"";
|
|
|
+ if ($status==""){
|
|
|
+ return error_show(1005,"参数 status 不能为空");
|
|
|
+ }
|
|
|
+ $return_type = isset($this->post['return_type'])&&$this->post['return_type']!="" ? intval($this->post['return_type']):"";
|
|
|
+ if ($return_type==""){
|
|
|
+ return error_show(1005,"参数 return_type 不能为空");
|
|
|
+ }
|
|
|
+ $remark =isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
|
|
|
+ if($remark==""){
|
|
|
+ return error_show(1005,"参数 remark 不能为空");
|
|
|
+ }
|
|
|
+ $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
|
|
|
+ if($return==false){
|
|
|
+ return error_show(1005,"退票申请信息未找到");
|
|
|
+ }
|
|
|
+ $update=["status"=>$status,"return_type"=>$return_type,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $up =Db::name("invoice_return")->where($return)->update($update);
|
|
|
+ if($up){
|
|
|
+ return app_show(0,"退票申请信息更新成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1005,"退票申请信息更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function returnRed(){
|
|
|
+ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
|
|
|
+ if($returnCode==""){
|
|
|
+ return error_show(1005,"参数 returnCode 不能为空");
|
|
|
+ }
|
|
|
+ $redinv =isset($this->post['redinv'])&&$this->post['redinv']!="" ? trim($this->post['redinv']):"";
|
|
|
+ if($redinv==""){
|
|
|
+ return error_show(1005,"参数 redinv 不能为空");
|
|
|
+ }
|
|
|
+ $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
|
|
|
+ if($return==false){
|
|
|
+ return error_show(1005,"退票申请信息未找到");
|
|
|
+ }
|
|
|
+ $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find();
|
|
|
+ if($invinfo==false){
|
|
|
+ return error_show(1005,"发票申请信息未找到");
|
|
|
+ }
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+
|
|
|
+ $update=["status"=>2,"red_inv"=>$redinv,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $up =Db::name("invoice_return")->where($return)->update($update);
|
|
|
+ if($up){
|
|
|
+ $invup = ["status"=>6,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $inv=Db::name("invoice_pool")->where($invinfo)->update($invup);
|
|
|
+ if($inv){
|
|
|
+ $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0])->column("id,orderCode,cancel_fee");
|
|
|
+ if(!empty($qrdArr)){
|
|
|
+ foreach ($qrdArr as $value){
|
|
|
+ $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
|
|
|
+ if($qrdinfo==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息未找到");
|
|
|
+ }
|
|
|
+ if($qrdinfo['inv_fee']<$value['cancel_fee']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息开票金额不足");
|
|
|
+ }
|
|
|
+ $update =[
|
|
|
+ "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
|
|
|
+ "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
|
|
|
+ "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 ? 1 : 2,
|
|
|
+ "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1,
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
+ ];
|
|
|
+ $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
|
|
|
+ if($qrdup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单信息更新失败");
|
|
|
+ }
|
|
|
+ $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ $assocup =Db::name("assoc")->where($value)->update($assoc);
|
|
|
+ if($assocup==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1003,"确认单关联信息更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"退票申请信息更新成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,"退票申请信息更新失败");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1005,$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function list(){
|
|
|
+ $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]];
|
|
|
+ $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
|
|
|
+ $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
|
|
|
+ if($start!=""){
|
|
|
+ $condition[]=["a.addtime",">=",$start." 00:00:00"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if($end!=""){
|
|
|
+ $condition[]=["a.addtime","<=",$end." 23:59:59"];
|
|
|
+ }
|
|
|
+ $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
|
|
|
+ if($status!==""){
|
|
|
+ $condition[]=["a.status","=",$status];
|
|
|
+ }
|
|
|
+ $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
|
|
|
+ if($inv_type!==""){
|
|
|
+ $condition[]=["a.inv_type","=",$inv_type];
|
|
|
+ }
|
|
|
+ $inv_out= isset($this->post['inv_out'])&&$this->post['inv_out']!=="" ? trim($this->post['inv_out']):"";
|
|
|
+ if($inv_out!==""){
|
|
|
+ $condition[]=["a.inv_out","=",$inv_out];
|
|
|
+ }
|
|
|
+ $inv_in = isset($this->post['inv_in'])&&$this->post['inv_in']!=="" ? trim($this->post['inv_in']):"";
|
|
|
+ if($inv_in!==""){
|
|
|
+ $condition[]=["a.inv_in","=",$inv_in];
|
|
|
+ }
|
|
|
+ $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
|
|
|
+ if($invNo!==""){
|
|
|
+ $condition[]=["a.invNo","like","%$invNo%"];
|
|
|
+ }
|
|
|
+
|
|
|
+ $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
|
|
|
+ if($apply_id!==""){
|
|
|
+ $condition[]=["a.apply_id","=",$apply_id];
|
|
|
+ }
|
|
|
+ $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
|
|
|
+ if($apply_name!==""){
|
|
|
+ $condition[]=["a.apply_name","like","%$apply_name%"];
|
|
|
+ }
|
|
|
+ $count=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where
|
|
|
+ ($condition)->count();
|
|
|
+ $total =ceil($count/$size);
|
|
|
+ $page= $page>$total ? intval($total):$page;
|
|
|
+ $list=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where($condition)
|
|
|
+ ->page($page,$size)->select();
|
|
|
+ return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ $condition=[["b.is_del","=",0]];
|
|
|
+ $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
|
|
|
+ $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
|
|
|
+ if($start!=""){
|
|
|
+ $condition[]=["a.addtime",">=",$start." 00:00:00"];
|
|
|
+ }
|
|
|
+ if($end!=""){
|
|
|
+ $condition[]=["a.addtime","<=",$end." 23:59:59"];
|
|
|
+ }
|
|
|
+ $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
|
|
|
+ if($inv_type!==""){
|
|
|
+ $condition[]=["b.inv_type","=",$inv_type];
|
|
|
+ }
|
|
|
+ $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
|
|
|
+ if($apply_id!==""){
|
|
|
+ $condition[]=["a.apply_id","=",$apply_id];
|
|
|
+ }
|
|
|
+ $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
|
|
|
+ if($apply_name!==""){
|
|
|
+ $condition[]=["a.apply_name","like","%$apply_name%"];
|
|
|
+ }
|
|
|
+ $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
|
|
|
+ if($status!==""){
|
|
|
+ $condition[]=["a.status","=",$status];
|
|
|
+ }
|
|
|
+ $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
|
|
|
+ if($invNo!==""){
|
|
|
+ $condition[]=["a.invNo","like","%$invNo%"];
|
|
|
+ }
|
|
|
+ $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!=="" ? trim($this->post['returnCode']):"";
|
|
|
+ if($returnCode!==""){
|
|
|
+ $condition[]=["a.returnCode","like","%$returnCode%"];
|
|
|
+ }
|
|
|
+ $count=Db::name("invoice_return")->alias("a")
|
|
|
+ ->leftJoin("invoice_pool b","a.invNo=b.invNo")
|
|
|
+ ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
|
|
|
+ ->where($condition)->count();
|
|
|
+ $total =ceil($count/$size);
|
|
|
+ $page= $page>$total ? intval($total):$page;
|
|
|
+ $list=Db::name("invoice_return")->alias("a")
|
|
|
+ ->leftJoin("invoice_pool b","a.invNo=b.invNo")
|
|
|
+ ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
|
|
|
+ ->where($condition)->page($page,$size)->field("c.buyer_title,c.buyer_code,c.buyer_addr,c.buyer_mobile,c.buyer_bank,
|
|
|
+ c.buyer_bankNo,c.seller_title,c.seller_code,c.seller_addr,c.seller_mobile,c.seller_bank,c.seller_bankNo,c.voider,c.payee,
|
|
|
+ c.drawer,c.reviewer,c.ownerPlace,b.inv_value,b.inv_out,b.inv_in,b.inv_type,b.open_type,is_ticket,b.email,
|
|
|
+ b.winv_fee,b.ainv_fee,b.post_fee,b.post_company,b.post_code,a.*")->select();
|
|
|
+ return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
+ }
|
|
|
}
|