request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $condition = [['is_del',"=",0],['refund_status',"=",0]]; $guserinfo =GetUserInfo($token); if(isset($guserinfo['code']) && $guserinfo['code']!=0){ return error_show($guserinfo['code'],$guserinfo['message']); } $check = checkRole($guserinfo['data']['roleid'],52); if($check){ $condition[]=["apply_id","=", $guserinfo['data']['id']]; } $no = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : ""; if ($no != "") { $condition[] = ["inv_in", "=", "{$no}"]; } $status = isset($post['status']) && $post['status'] !== "" ? intval($post['status']) : ""; if ($status !== "") { $condition[] = ["status", "=", "{$status}"]; } $type_check = isset($post['type_check']) && $post['type_check'] != "" ? $post['type_check'] : ""; if ($type_check != "") { $condition[] = ["type_check", "=", "{$type_check}"]; } $starttime = isset($post['starttime']) && $post['starttime'] != "" ? $post['starttime'] : ""; if ($starttime != "") { $starttime = $starttime." 00:00:00"; $condition[] = ["addtime", ">=", "{$starttime}"]; } $endtime = isset($post['endtime']) && $post['endtime'] != "" ? $post['endtime'] : ""; if ($endtime != "") { $endtime = $endtime." 23:59:59"; $condition[] = ["addtime", "<=", "{$endtime}"]; } $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1; $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10; $count = Db::name("invoice_pool")->where($condition)->count(); $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1; $page = $page >= $total ? intval($total) : $page; $list = Db::name("invoice_pool")->where($condition)->order("addtime desc")->page(intval($page), $size)->select(); $data=[]; foreach ($list as $value){ $customer= Db::name("customer_info")->where("companyNo","=",$value['inv_in'])->field("companyName,contactor") ->find(); $value['company'] = isset($customer['companyName']) ? $customer['companyName']:""; $value['contactor'] = isset($customer['contactor']) ? $customer['contactor']:""; $out = Db::name('company_info')->where('companyNo',"=",$value['inv_out'])->find(); $value['kp_company'] =isset($out['company_name']) ? $out['company_name']:""; $post = Db::name("inv_post")->where("invNo","=",$value['invNo'])->find(); $value['post_company']=isset($post['post_company'])&&$post['post_company']!="" ? $post['post_company']:""; $value['post_code']=isset($post['postNo'])&&$post['postNo']!="" ? $post['postNo']:""; $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,"count"=>$count]); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):""; $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $type = isset($post['type'])&&$post['type']!=""?intval($post['type']):1; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1"; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $good = isset($post['good'])&&is_array($post['good'])?$post['good']:""; if($good==""&& empty($good)){ return error_show(1004,"商品信息不能为空"); } $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; $orderinfo=[]; $orderNo=makeNo('ORD'); $total=0; $fund_fee=0; $wfund_fee=0; $inv_fee=0; $winv_fee=0; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } Db::startTrans(); try{ foreach ($good as $value){ $temp=[]; if(!isset($value['num'])||$value['num']==0){ return error_show(1004,"商品数量不能为空"); } if(!isset($value['total_fee'])||$value['total_fee']==0){ return error_show(1004,"商品总金额不能为空"); } $temp['orderNo'] = $orderNo; $temp['goodNo']= $value['sequenceNo']; $goocp = Db::name("qrd_list")->where("sequenceNo","=",$value['sequenceNo'])->find(); $temp['good_name']= $goocp['goodname']; $temp['qrdNo'] = $goocp['qrdNo']; $temp['brand']= $goocp['brand']; $temp['unit']= $value['unit']; $temp['good_num']= $value['num']; $temp['price']= $goocp['price']; $temp['total_fee']= $value['total_fee']; $temp['wfund_fee'] =$value['total_fee']; $temp['winv_fee'] = $value['total_fee']; $temp['other_fee']= 0; $temp['status']= 1; $temp['remark']= isset($value['remark']) ? $value['remark'] : ""; $temp['addtime']= date("Y-m-d H:i:s"); $temp['updatetime']= date("Y-m-d H:i:s"); $total+= $value['total_fee']; $fund_fee+= $goocp['apay_fee']; $winv_fee+= $goocp['winv_fee']; $inv_fee+= $goocp['ainv_fee']; $wfund_fee+= $goocp['wpay_fee']; $orderinfo[]=$temp; } if(!empty($invoice) && $invoice!=''){ $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if($inv_add==1){ $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); }else{ Db::name('customer_invoice')->where('invoice_code',"=",$invoice['invoice_code'])->save($invoice); } } $orderins = Db::name("order_info")->insertAll($orderinfo); //if($total<0){ // Db::rollback(); // return error_show(1005,"发票核销数据为不能为负值"); // } if($orderins) { $order = [ "orderNo" => $orderNo, "companyNo" => $companyNo, "sales_id" => $effetc['data']['user']['id'], "sales_name" => $username, "total_amount" => $total, "inv_status" => 1, "fund_status" => 1, "fund_fee"=>0, "wfund_fee"=>$total, "inv_fee"=>0, "inv_used"=>$total, "winv_fee"=>0, "status" => 0, "type" => $type, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $orderpool = Db::name("order_pool")->insert($order, true); if ($orderpool > 0) { $invNo = makeNo("INV"); $inv = [ "invNo" => $invNo, "inv_value" => $total, "inv_out" => $inv_out, "inv_in" => $companyNo, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "status" => 0, "worder_fee"=>0, "order_used"=>$total, "wtrade_fee"=>$total, "remark" => $remark, "invoice_title" => $invoice['invoice_title'], "invoice_addr" => $invoice['invoice_addr'], "invoice_mobile" => $invoice['invoice_mobile'], "invoice_code" => $invoice['invoice_code'], "invoice_bank" => $invoice['invoice_bank'], "invoice_bankNo" => $invoice['invoice_bankNo'], "inv_add" => $inv_add, "is_order" =>1, "inv_type"=>$inv_type, "type_check"=>$type, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $invinsert = Db::name("invoice_pool")->insert($inv); if ($invinsert) { if($type==2){ Db::commit(); return app_show(0,"发票新建成功"); } $assocNo = makeNo("ASC"); $asslog = [ "assocNo"=>$assocNo, "type"=>1, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "companyNo"=>$companyNo, "codeNo"=>$orderNo, "rela_form"=>1, "total_fee"=>$total, "balance"=>0, "cancel_total"=>$total, "status"=>1, "source"=>2, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $logassc = Db::name("assoc_key")->insert($asslog); if($logassc){ $assrela =[ "assocNo"=>$assocNo, "viceNo"=>$invNo, "vice_total"=>$total, "vice_fee"=>0, "cancel_fee"=>$total, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $relas = Db::name("assoc_rela")->insert($assrela); if($relas){ $resula= $this->updateQrd($orderNo,$total); if($resula){ Db::commit(); return app_show(0,"发票新建申请成功"); } } } } } } Db::rollback(); return error_show(1004,"发票新建申请失败"); }catch (\Exception $e) { Db::rollback(); return error_show(1004, $e->getMessage()); } } /** * 保存新建的资源 * @param \think\Request $request * @return \think\Response */ public function save() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : ""; $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):""; $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $type = isset($post['type'])&&$post['type']!=""?intval($post['type']):1; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if($invNo==""){ return error_show(1004,"参数invNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $invinfo =Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->find(); if(empty($invinfo)){ return error_show(1004,"发票信息未找到"); } if($invinfo['status']>=3){ return error_show(1004,"发票信息已通过财务审核,无法修改!"); } $good = isset($post['good'])&&is_array($post['good'])?$post['good']:""; if($good==""&& empty($good)){ return error_show(1004,"商品信息不能为空"); } $assc = Db::name("assoc_list")->where([["viceNo","=",$invNo],["is_del","=",0],["type","=",1]])->find(); if(empty($assc)){ return error_show(1005,"未找到对应的关联数据"); } $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } $total=0; $fund_fee=0; $wfund_fee=0; $inv_fee=0; $winv_fee=0; Db::startTrans(); try{ if(!empty($invoice) && $invoice!='') { $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if ($inv_add == 1) { $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); } else { Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); } } // $reset = $this->qrd_delet($assc['codeNo'],$assc['cancel_total']); // if($reset){ // Db::name("order_info")->where("orderNo","=",$assc['codeNo'])->save(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]); // }else{ // Db::rollback(); // return error_show(1004,"确认单数据编辑失败"); // } foreach ($good as $value){ // $temp['goodNo']= $value['sequenceNo']; // $temp['orderNo']= $assc['codeNo']; //$goocp = Db::name("qrd_list")->where("sequenceNo","=",$value['sequenceNo'])->find(); $goocp = Db::name("order_info")->where([["orderNo","=",$assc['codeNo']],["goodNo","=",$value['sequenceNo']]]) ->find(); // $goocp['good_name']= $value['remark']; // $temp['qrdNo'] = $goocp['qrdNo']; // $temp['brand']= $goocp['brand']; // $temp['unit']= $goocp['unit']; // $temp['good_num']= $value['num']; // $temp['price']= $goocp['price']; // $temp['total_fee']= $value['total_fee']; // $temp['wfund_fee'] = $value['total_fee']; // $temp['winv_fee'] = $value['total_fee']; // $temp['other_fee']= 0; // $temp['status']=1; $goocp['remark']= isset($value['remark']) ? $value['remark'] : ""; $goocp['updatetime']= date("Y-m-d H:i:s"); // $temp['addtime']= date("Y-m-d H:i:s"); // $fund_fee+= $goocp['apay_fee']; // $winv_fee+= $goocp['winv_fee']; // $inv_fee+= $goocp['ainv_fee']; // $wfund_fee+= $goocp['wpay_fee']; Db::name("order_info")->save($goocp); $total+= $value['total_fee']; } $order = [ "companyNo" => $companyNo, "total_amount" => $total, "fund_fee"=>0, "wfund_fee"=>$total, "inv_fee"=>0, "inv_used"=>$total, "winv_fee"=>0, "updatetime" => date("Y-m-d H:i:s") ]; // if($total<0){ // Db::rollback(); // return error_show(1005,"发票核销数据为不能为负值"); // } $orderpool = Db::name("order_pool")->where("orderNo","=",$assc['codeNo'])->save($order); if ($orderpool) { $invinfo['inv_value'] = $total; $invinfo['inv_in'] = $companyNo; $invinfo['inv_out'] = $inv_out; $invinfo['worder_fee'] = 0; $invinfo['inv_type'] = $inv_type; $invinfo['type_check'] = $type; $invinfo['wtrade_fee'] = $total; $invinfo['order_used'] = $total; $invinfo['invoice_title'] = $invoice['invoice_title']; $invinfo['invoice_addr'] = $invoice['invoice_addr']; $invinfo['invoice_mobile'] = $invoice['invoice_mobile']; $invinfo['invoice_code'] = $invoice['invoice_code']; $invinfo['invoice_bank'] = $invoice['invoice_bank']; $invinfo['invoice_bankNo'] = $invoice['invoice_bankNo']; $invinfo['inv_add'] = $inv_add; $invinfo['remark']=$remark; $invinfo['updatetime'] =date("Y-m-d H:i:s"); $invinsert = Db::name("invoice_pool")->save($invinfo); if($invinsert){ $asslog = [ "cancel_fee" => $total, "vice_fee" => 0, "vice_total" => 0, "updatetime" => date("Y-m-d H:i:s") ]; $logassc = Db::name("assoc_rela")->where("id","=", $assc['id'])->save($asslog); if ($logassc) { $keyas=[ "total_fee"=>$total, "balance"=>0, "cancel_total"=>$total, "updatetime"=>date("Y-m-d H:i:s") ]; $relas = Db::name("assoc_key")->where("id","=",$assc['aid'])->save($keyas); if($relas){ // $resula= $this->updateQrd($assc['codeNo'],$total); // if($resula){ Db::commit(); return app_show(0,"发票编辑成功"); // } } } } } Db::rollback(); return error_show(1004,"发票编辑失败"); }catch (\Exception $e) { Db::rollback(); return error_show(1004, $e->getMessage()); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function CreateByTrade(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1"; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } $traNo = isset($post['traNo'])&&$post['traNo']!=""?$post['traNo']:""; if($traNo==""){ return error_show(1004,"参数traNo 不能为空"); } $trade = Db::name("trade_pool")->where([["traNo","in",$traNo],["is_del","=",0],['status',"=",3]])->select() ->toArray(); if(empty($trade)){ return error_show(1004,"未找到资金信息"); } $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } Db::startTrans(); try{ if(!empty($invoice) && $invoice!='') { $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if ($inv_add == 1) { $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); } else { Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); } } $total=0; $relas=[]; $assocNo = makeNo("ASC"); $invNo = makeNo("INV"); foreach ($trade as $value){ if($value['winv_fee']<=0){ continue; } $relas[] =[ "assocNo"=>$assocNo, "viceNo"=>$value['traNo'], "vice_total"=>$value['total_fee'], "vice_fee"=>0, "cancel_fee"=>$value['winv_fee'], "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $total+=$value['winv_fee']; $value['inv_used']+=$value['winv_fee']; $value['winv_fee']=0; $value['updatetime']=date("Y-m-d H:i:s"); Db::name("trade_pool")->save($value); } $inv = [ "invNo" => $invNo, "inv_value" => $total, "inv_out" => $inv_out, "inv_in" => $companyNo, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "status" => 0, "worder_fee"=>$total, "order_used"=>0, "fund_used"=>$total, "wtrade_fee"=>0, "remark" => $remark, "invoice_title" => $invoice['invoice_title'], "invoice_addr" => $invoice['invoice_addr'], "invoice_mobile" => $invoice['invoice_mobile'], "invoice_code" => $invoice['invoice_code'], "invoice_bank" => $invoice['invoice_bank'], "invoice_bankNo" => $invoice['invoice_bankNo'], "inv_add" => $inv_add, "is_order" =>0, "inv_type"=>$inv_type, "type_check"=>3, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $invinsert = Db::name("invoice_pool")->insert($inv); if ($invinsert) { $asslog = [ "assocNo"=>$assocNo, "type"=>2, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "companyNo"=>$companyNo, "codeNo"=>$invNo, "rela_form"=>4, "total_fee"=>$total, "balance"=>0, "cancel_total"=>$total, "status"=>1, "source"=>2, "addtime"=>date("Y-m-d H:i:s"), "updatetime"=>date("Y-m-d H:i:s") ]; $logassc = Db::name("assoc_key")->insert($asslog); if($logassc){ $relas = Db::name("assoc_rela")->insertAll($relas); if($relas){ Db::commit(); return app_show(0,"发票新建申请成功"); } } } Db::rollback(); return error_show(1005,"发票新建申请失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function EditByTrain(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1"; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):""; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if($invNo==""){ return error_show(1004,"参数invNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } $invinfo =Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->find(); if(empty($invinfo)){ return error_show(1004,"发票信息未找到"); } if($invinfo['status']>=3){ return error_show(1004,"发票信息已通过财务审核,无法修改!"); } $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } Db::startTrans(); try{ if(!empty($invoice) && $invoice!='') { $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if ($inv_add == 1) { $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); } else { Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); } } $invpool=[ "invoice_title" => $invoice['invoice_title'], "invoice_addr" => $invoice['invoice_addr'], "invoice_mobile" => $invoice['invoice_mobile'], "invoice_code" => $invoice['invoice_code'], "invoice_bank" => $invoice['invoice_bank'], "invoice_bankNo" => $invoice['invoice_bankNo'], "inv_add" => $inv_add, "inv_out" => $inv_out, "remark"=>$remark, "updatetime"=>date("Y-m-d H:i:s") ]; $up= Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->save($invpool); if($up){ Db::commit(); return app_show(0,"更新成功"); }else{ Db::rollback(); return error_show(1005,"更新失败"); } }catch(\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } /** * 显示指定的资源 * * @param int $id * @return \think\Response */ public function read() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invid = isset($post['id'])&&$post['id']!=""?intval($post['id']):""; if($invid==""){ return error_show(1004,"参数id 不能为空"); } $inv = Db::name("invoice_pool")->where("id","=",$invid)->find(); if(empty($inv)){ return error_show(1005,"未找到发票信息"); } $customer = Db::name("customer_info")->where("companyNo","=",$inv['inv_in'])->find(); $inv['customer']=empty($customer)? []:$customer; $kp_company = Db::name("company_info")->where("companyNo","=",$inv['inv_out'])->find(); $inv['kp_company']=empty($kp_company)? []:$kp_company; $inv['order']=[]; $assoc = Db::name("assoc_list")->where([["type","=",1],['viceNo',"=",$inv["invNo"]],["is_del","=",0]]) ->find(); if(!empty($assoc)){ $order= Db::name("order_pool")->where([['orderNo',"=",$assoc['codeNo']]])->find(); $list=[]; if($order['type']==1){ $good = Db::name('order_info')->where([['orderNo',"=",$assoc['codeNo']],["status","=",1]])->select(); foreach ($good as $key=>$value){ $info = Db::name("qrd_list")->where("sequenceNo","=",$value['goodNo'])->find(); $value['num'] = intval($info['num']); $value['ainv_fee'] =sprintf("%.2f", $info['ainv_fee']); $value['winv_fee'] = sprintf("%.2f",$info['winv_fee']); $value['total'] = sprintf("%.2f",$info['total_fee']); $value['inv_num'] = intval($info['inv_num']); $list[]=$value; } } $order['good'] = $list; $inv['order']=$order; } $inv['trade']=[]; $assoc= Db::name("assoc_list")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$inv["invNo"]]])->select()->toArray(); if(!empty($assoc)) { foreach ($assoc as $value) { $temp = Db::name("trade_list")->alias("a")->leftJoin("cfp_customer_info b","a.companyNo=b.companyNo") ->where([["a.is_del", "=", 0], ["a.traNo", "=", $value["viceNo"]]])->field("a.*,b.companyName") ->find(); $inv['trade'][]=$temp; } } return app_show(0,"获取成功",$inv); } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function add() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : ""; $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } $total = isset($post['total'])&&$post['total']!=""?$post['total']:""; if($total==""){ return error_show(1004,"参数total 不能为空"); } //if($total<0){ // Db::rollback(); // return error_show(1005,"发票核销数据为不能为负值"); // } Db::startTrans(); try{ if(!empty($invoice) && $invoice!='') { $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if ($inv_add == 1) { $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); } else { Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); } } $invNo = makeNo("INV"); $inv = [ "invNo" => $invNo, "inv_value" => $total, "inv_out" => $inv_out, "inv_in" => $companyNo, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "status" => 0, "trade_status" => 1, "order_status" => 1, "worder_fee"=>$total, "wtrade_fee"=>$total, "invoice_title" => $invoice['invoice_title'], "invoice_addr" => $invoice['invoice_addr'], "invoice_mobile" => $invoice['invoice_mobile'], "invoice_code" => $invoice['invoice_code'], "invoice_bank" => $invoice['invoice_bank'], "invoice_bankNo" => $invoice['invoice_bankNo'], "inv_add" => $inv_add, "inv_type"=>$inv_type, "type_check"=>2, "is_order"=>0, "remark"=>$remark, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $invinsert = Db::name("invoice_pool")->insert($inv); if($invinsert){ Db::commit(); return app_show(0,"发票创建成功"); } Db::rollback(); return error_show(1004,"发票新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):""; $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):""; $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1; $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : ""; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if($invNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):""; if($inv_out==""){ return error_show(1004,"参数inv_out 不能为空"); } $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find(); if(empty($out)){ return error_show(1004,"未找到开票企业信息"); } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $invinfo =Db::name("invoice_pool")->where("invNo","=",$invNo)->find(); if(empty($invinfo)){ return error_show(1004,"发票信息未找到"); } if($invinfo['status']>=3){ return error_show(1004,"发票信息已通过财务审核,无法修改!"); } $total = isset($post['total'])&&$post['total']!=""?$post['total']:""; if($total==""){ return error_show(1004,"参数total 不能为空"); } //if($total<0){ // Db::rollback(); // return error_show(1005,"发票核销数据为不能为负值"); // } isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $customer['invoice_addr'] = $post['invoice_addr']:""; $invoice=[]; isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = $post['invoice_bankNo']:""; isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = $post['invoice_mobile']:""; isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } $invinfo['inv_value']=$total; $invinfo['worder_fee']=$total; $invinfo['wtrade_fee']=$total; $invinfo['inv_in']=$companyNo; $invinfo['inv_out']=$inv_out; $invinfo['invoice_title'] = $invoice['invoice_title']; $invinfo['invoice_addr'] = $invoice['invoice_addr']; $invinfo['invoice_mobile'] = $invoice['invoice_mobile']; $invinfo['invoice_code'] = $invoice['invoice_code']; $invinfo['invoice_bank'] = $invoice['invoice_bank']; $invinfo['invoice_bankNo'] = $invoice['invoice_bankNo']; $invinfo['inv_type']=$inv_type; $invinfo['inv_add']=$inv_add; $invinfo['remark']=$remark; $invinfo['updatetime']= date("Y-m-d H:i:s"); Db::startTrans(); try{ if(!empty($invoice) && $invoice!='') { $invoice['updatetime'] = date("Y-m-d H:i:s"); $invoice['checkNo'] = $companyNo; if ($inv_add == 1) { $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); if($cust){ Db::rollback(); return error_show(1005,"企业财务信息已存在"); } $invoice['addtime'] = date("Y-m-d H:i:s"); Db::name('customer_invoice')->insert($invoice); } else { Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); } } $invinsert = Db::name("invoice_pool")->save($invinfo); if($invinsert){ Db::commit(); return app_show(0,"发票编辑成功"); } Db::rollback(); return error_show(1004,"发票编辑失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function status( ) { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invNo=isset($post['invNo'])&& $post['invNo']!=""? trim($post['invNo']):""; if($invNo==""){ return error_show(1004,"参数invNo 不能为空"); } $invinfo = Db::name("invoice_pool")->where("invNo","=",$invNo)->find(); if(empty($invinfo)){ return error_show(1003,"未找到发票数据"); } $status = isset($post['status'])&&$post['status']!==""? intval($post['status']):""; $remark = isset($post['remark'])&&$post['remark']!==""? trim($post['remark']):""; if($status===""){ return error_show(1005,"参数status 不能为空"); } if($status==$invinfo['status']){ return error_show(1005,"状态已修改"); } if(!in_array($status,[0,1,2,3,4,5])){ return error_show(1005,"参数status 无效"); } if($status===0&&$invinfo['status']>=3){ return error_show(1005,"发票已通过审核无法取消申请!"); } // if($status===1&&$invinfo['status']>=3){ // return error_show(1005,"发票已通过审核无法取消申请!"); // } Db::startTrans(); if($status==4){ $invlist = isset($post['inv_info'])&&$post['inv_info']!="" ? $post['inv_info'] :""; if($invlist==""){ Db::rollback(); return error_show(1004,"参数inv_info 不能为空"); } } $invinfo['status']=$status; $invinfo['exam_remark']=$remark; $invinfo['updatetime']=date("Y-m-d H:i:s"); $update =Db::name("invoice_pool")->save($invinfo); if($update){ if($status==5) { if ($invinfo['type_check'] == 1) { $assinfo = Db::name("assoc_list")->where([["viceNo", "=", $invNo], ["status", "=", 1], ["source", "=", 2], ["is_del", "=", "0"]])->find(); $assoc = Db::name("assoc_key")->where("assocNo", "=", $assinfo['assocNo'])->save (["status" => 3, "updatetime" => date("Y-m-d H:i:s")]); if ($assoc) { $invinfo['aorder_fee'] += $assinfo['cancel_fee']; $invinfo['order_used'] -= $assinfo['cancel_fee']; $invinfo['is_order'] = 1; $invinfo['order_status'] = $invinfo['worder_fee'] == 0 ? 3 : 2; Db::name("invoice_pool")->save($invinfo); $orderpool = Db::name("order_pool")->where([["orderNo", "=", $assinfo['codeNo']], ["status", "=", 0], ["is_del", "=", 0]])->find(); $orderpool['status'] = 1; $orderpool['inv_fee'] += $assinfo['cancel_total']; $orderpool['inv_used'] -= $assinfo['cancel_total']; $orderpool['inv_status'] = $orderpool['winv_fee'] == 0 ? 3 : 2; $orderpool['updatetime'] = date("Y-m-d H:i:s"); $pool = Db::name("order_pool")->save($orderpool); if ($pool) { $qrd = $this->qrd_sure($assinfo['codeNo'], $assinfo['cancel_fee']); if ($qrd) { Db::commit(); return app_show(0, "状态修改成功"); } } } Db::rollback(); return error_show(1005, "状态修改失败"); } if ($invinfo['type_check'] == 3) { $assoc = Db::name("assoc_list")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->select()->toArray(); if (!empty($assoc)) { $taotal = 0; foreach ($assoc as $value) { $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=", $value["viceNo"]]])->find(); $temp['inv_fee'] += $value['cancel_fee']; $temp['inv_used']-= $value['cancel_fee']; $temp['inv_status']= $temp['winv_fee']==0 ? 3 :2; $temp['updatetime'] = date("Y-m-d H:i:s"); $taotal = $value['cancel_total']; Db::name("trade_pool")->save($temp); } $invinfo['atrade_fee'] += $taotal; $invinfo['fund_used'] -= $taotal; $invinfo['trade_status'] = $invinfo['wtrade_fee'] == 0 ? 3 : 2; Db::name("invoice_pool")->save($invinfo); $ass_up = Db::name("assoc_key")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->save(["status" => 3, "updatetime" => date("Y-m-d H:i:s")]); if ($ass_up) { Db::commit(); return app_show(0, "状态修改成功"); } } Db::rollback(); return error_show(1005, "状态修改失败"); } } Db::commit(); return app_show(0,"状态修改成功"); }else{ Db::rollback(); return error_show(1005,"状态修改失败"); } } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invNo =isset($post['invNo']) && $post['invNo']!="" ? trim($post['invNo']):""; if($invNo==""){ return error_show(1003,"参数invNo 不能为空"); } $inv = Db::name("invoice_pool")->where("invNo","=",$invNo)->find(); if(empty($inv)){ return error_show(1004,"未找到发票数据"); } if($inv['status']>2){ return error_show(1004,"财务审核已通过无法取消"); } Db::startTrans(); if($inv['type_check']==1){ $assoc= Db::name("assoc_list")->where([["type","=",1],["is_del","=",0],["rela_form","=",1],["viceNo","=", $invNo]]) ->find(); if(!empty($assoc)) { $update = Db::name("order_pool")->where('orderNo', "=", $assoc['codeNo'])->save(['is_del' => 1, "updatetime" => date("Y-m-d H:i:s")]); if (!$update) { Db::rollback(); return error_show(1004, "订单删除失败"); } $ass_up = Db::name("assoc_key")->where("id", "=", $assoc['aid'])->save(["is_del" => 1, "updatetime" => date("Y-m-d H:i:s")]); if (!$ass_up) { Db::rollback(); return error_show(1004, "订单发票关联表删除失败"); } $del= $this->qrd_delet($assoc['codeNo'],$assoc['cancel_total']); if(!$del){ Db::rollback(); return error_show(1006,"确认单数据修改失败"); } } } if($inv['type_check']==3){ $assoc= Db::name("assoc_list")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$invNo]])->select()->toArray(); if(!empty($assoc)) { foreach ($assoc as $value){ $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",$value["viceNo"]]])->find(); $temp['winv_fee'] += $value['cancel_fee']; $temp['inv_used'] -= $value['cancel_fee']; $temp['updatetime'] = date("Y-m-d H:i:s"); Db::name("trade_pool")->save($temp); } $ass_up = Db::name("assoc_key")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$invNo]])->save(["is_del" => 1, "updatetime" => date("Y-m-d H:i:s")]); if (!$ass_up) { Db::rollback(); return error_show(1004, "订单发票关联表删除失败"); } } } $inv['is_del']=1; $inv['updatetime']=date("Y-m-d H:i:s"); $update = Db::name("invoice_pool")->save($inv); if($update){ Db::commit(); return app_show(0,"取消申请成功"); }else{ Db::rollback(); return error_show(1003,"取消申请失败"); } // return $update? app_show(0,"取消申请成功"):error_show(1003,"取消申请失败"); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function InvoPost(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invNo=isset($post['invNo'])&& $post['invNo']!=""? trim($post['invNo']):""; if($invNo==""){ return error_show(1004,"参数invNo 不能为空"); } $invinfo = Db::name("invoice_pool")->where("invNo","=",$invNo)->find(); if(empty($invinfo)){ return error_show(1003,"未找到发票数据"); } $postcode = isset($post["code"])&&$post['code']!="" ? $post["code"] :""; $postname = isset($post['company']) && $post['company']!="" ? $post['company']:""; if ($postcode==""){ return error_show(1005,"参数code 不能为空"); } if ($postname==""){ return error_show(1005,"参数company 不能为空"); } // if($invinfo['status']!=4){ // return error_show(1005,"发票数据还未上传"); // } $data=[ "postNo"=>$postcode, "post_company"=>$postname, "invNo"=>$invNo, "contactor"=>"", "mobile"=>"", "status"=>1, "addtime"=>date("y-m-d H:i:s"), "updatetime"=>date("y-m-d H:i:s"), ]; Db::startTrans(); $post= Db::name("inv_post")->insert($data); if($post){ $invinfo['status']=5; $invinfo["updatetime"]=date("Y-m-d H:i:s"); $sav= Db::name("invoice_pool")->save($invinfo); if($sav){ if ($invinfo['type_check'] == 1) { $assinfo = Db::name("assoc_list")->where([["viceNo", "=", $invNo], ["status", "=", 1], ["source", "=", 2], ["is_del", "=", "0"]])->find(); $assoc = Db::name("assoc_key")->where("assocNo", "=", $assinfo['assocNo'])->save (["status" => 3, "updatetime" => date("Y-m-d H:i:s")]); if ($assoc) { $invinfo['aorder_fee'] += $assinfo['cancel_fee']; $invinfo['order_used'] -= $assinfo['cancel_fee']; $invinfo['is_order'] = 1; $invinfo['order_status'] = $invinfo['worder_fee'] == 0 ? 3 : 2; Db::name("invoice_pool")->save($invinfo); $orderpool = Db::name("order_pool")->where([["orderNo", "=", $assinfo['codeNo']], ["status", "=", 0], ["is_del", "=", 0]])->find(); $orderpool['status'] = 1; $orderpool['inv_fee'] += $assinfo['cancel_total']; $orderpool['inv_used'] -= $assinfo['cancel_total']; $orderpool['inv_status'] = $orderpool['winv_fee'] == 0 ? 3 : 2; $orderpool['updatetime'] = date("Y-m-d H:i:s"); $pool = Db::name("order_pool")->save($orderpool); if ($pool) { $qrd = $this->qrd_sure($assinfo['codeNo'], $assinfo['cancel_fee']); if ($qrd) { Db::commit(); return app_show(0, "状态修改成功"); } } } Db::rollback(); return error_show(1005, "状态修改失败"); } if ($invinfo['type_check'] == 3) { $assoc = Db::name("assoc_list")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->select()->toArray(); if (!empty($assoc)) { $taotal = 0; foreach ($assoc as $value) { $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=", $value["viceNo"]]])->find(); $temp['inv_fee'] += $value['cancel_fee']; $temp['inv_used']-= $value['cancel_fee']; $temp['inv_status']= $temp['winv_fee']==0 ? 3 :2; $temp['updatetime'] = date("Y-m-d H:i:s"); $taotal = $value['cancel_total']; Db::name("trade_pool")->save($temp); } $invinfo['atrade_fee'] += $taotal; $invinfo['fund_used'] -= $taotal; $invinfo['trade_status'] = $invinfo['wtrade_fee'] == 0 ? 3 : 2; Db::name("invoice_pool")->save($invinfo); $ass_up = Db::name("assoc_key")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->save(["status" => 3, "updatetime" => date("Y-m-d H:i:s")]); if ($ass_up) { Db::commit(); return app_show(0, "状态修改成功"); } } Db::rollback(); return error_show(1005, "状态修改失败"); } Db::commit(); return app_show(0,"添加成功"); }else{ Db::rollback(); return error_show(1003,"添加失败"); } } Db::rollback(); return error_show(1003,"添加失败"); } /** * @return \think\response\Json|void */ public function GetReceipt(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invNo=isset($post['inv_in'])&& $post['inv_in']!=""? trim($post['inv_in']):""; if($invNo==""){ return error_show(1004,"参数inv_in 不能为空"); } $type = isset($post['type_check'])&& $post['type_check']!=""? trim($post['type_check']) : 2; $condition = [["inv_in","=",$invNo],["type_check","=",$type],["lstatus","=",1]]; $list = Db::name("inv_list")->where($condition)->select(); return app_show(0,"获取成功",$list); } /** * 显示资源列表 * * @return \think\Response */ public function recepitlist() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $condition = [['is_del',"=",0],['refund_status',"=",0]]; $guserinfo =GetUserInfo($token); if(isset($guserinfo['code']) && $guserinfo['code']!=0){ return error_show($guserinfo['code'],$guserinfo['message']); } $check = checkRole($guserinfo['data']['roleid'],55); if($check){ $condition[]=["apply_id","=", $guserinfo['data']['id']]; } $no = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : ""; if ($no != "") { $condition[] = ["inv_in", "=", "{$no}"]; } $invNo = isset($post['invNo']) && $post['invNo'] != "" ? trim($post['invNo']) : ""; if ($invNo != "") { $condition[] = ["invNo", "like", "%{$invNo}%"]; } $type_check = isset($post['type_check']) && $post['type_check'] != "" ? $post['type_check'] : ""; if ($type_check != "") { $condition[] = ["type_check", "=", "{$type_check}"]; } $status = isset($post['status']) && $post['status'] != "" ? $post['status'] : ""; if ($status != "") { $condition[] = ["status", "=", "{$status}"]; } $order_status = isset($post['order_status']) && $post['order_status'] != "" ? intval($post['order_status']) : ""; if ($order_status != "") { if($order_status==4){ $condition[] = ["order_status", "in", [1,2]]; }else{ $condition[] = ["order_status", "=", "{$order_status}"]; } // $condition[] = ["order_status", "=", "{$order_status}"]; } $trade_status = isset($post['trade_status']) && $post['trade_status'] != "" ? intval($post['trade_status']) : ""; if ($trade_status != "") { if($trade_status==4){ $condition[] = ["trade_status", "in", [1,2]]; }else{ $condition[] = ["trade_status", "=", "{$trade_status}"]; } } $total_low = isset($post['total_low']) && $post['total_low'] != "" ? $post['total_low'] : ""; if ($total_low != "") { $condition[] = ["inv_value", ">=", "{$total_low}"]; } $total_up = isset($post['total_up']) && $post['total_up'] != "" ? $post['total_up'] : ""; if ($total_up != "") { $condition[] = ["inv_value", "<=", "{$total_up}"]; } $starttime = isset($post['starttime']) && $post['starttime'] != "" ? $post['starttime'] : ""; if ($starttime != "") { $condition[] = ["addtime", ">=", "{$starttime}"]; } $endtime = isset($post['endtime']) && $post['endtime'] != "" ? $post['endtime'] : ""; if ($endtime != "") { $condition[] = ["addtime", "<=", "{$endtime}"]; } $type = isset($post['type_check'])&& $post['type_check']!=""? $post['type_check'] : ""; if ($type != "") { $condition[] = ["type_check", "=", "{$type}"]; } $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1; $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10; $count = Db::name("invoice_pool")->where($condition)->count(); $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1; $page = $page >= $total ? intval($total) : $page; $list = Db::name("invoice_pool")->where($condition)->order("addtime desc")->page(intval($page), $size)->select(); $data=[]; foreach ($list as $value){ $customer= Db::name("customer_info")->where("companyNo","=",$value['inv_in'])->find(); $value['company'] = isset($customer['companyName']) ? $customer['companyName']:""; $value['contactor'] = isset($customer['contactor']) ? $customer['contactor']:""; // $value['invoice_bankNo'] = isset($customer['invoice_bankNo']) ? $customer['invoice_bankNo']:""; $value['mobile'] = isset($customer['mobile']) ? $customer['mobile']:""; $out = Db::name('company_info')->where('companyNo',"=",$value['inv_out'])->find(); $value['kp_company'] =isset($out['company_name']) ? $out['company_name']:""; $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,"count"=>$count]); } /** * @param $orderNo * @param $balance * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function updateQrd($orderNo,$balance) { $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find(); if (empty($orderinfo)) { return false; } $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select(); if (empty($orderlist)) { return false; } foreach ($orderlist as $value) { if($balance==0){ break; } if($value['winv_fee'] == 0){ continue; } $order_fee=0; if($value['winv_fee']<=$balance){ $order_fee = $value['winv_fee']; $balance -=$value['winv_fee']; $value['inv_fee'] += $value['winv_fee']; $value['winv_fee'] = 0; }else{ $value['inv_fee'] += $balance; $value['winv_fee']-= $balance; $order_fee = $balance; $balance=0; } $value['updatetime'] = date("Y-m-d H:i:s"); $orde = Db::name("order_info")->save($value); if($orde===false){ return false; } $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find(); if (($order_fee <= $qrdinfo['Number1618249205231'])||($order_fee <= $qrdinfo['Number1618249202608']&&$orderinfo['type']==4)) { $qrdinfo['inving_fee'] += $order_fee; if($orderinfo['type']==4){ $qrdinfo['Number1618249202608'] -= $order_fee; }else{ $qrdinfo['Number1618249205231'] -= $order_fee; $qrdinfo['number1618249258956'] += $value['good_num']; } // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3"; $qinfo = Db::name("qrd_info")->save($qrdinfo); if ($qinfo) { $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find(); if(($qrdp['winv_fee'] >= $order_fee)|| ($qrdp['ainv_fee'] >= $order_fee &&$orderinfo['type']==4 )) { if($orderinfo['type']==4){ $qrdp['ainv_fee'] -= $order_fee; $qrdp['inv_fee'] += $order_fee; }else{ $qrdp['winv_fee'] -= $order_fee; $qrdp['inv_fee'] += $order_fee; } // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2; $qrd = Db::name("qrd")->save($qrdp); if(!$qrd){ return false; } }else { return false; } }else { return false; } } else { return false; } } return true; } /** * @param $orderNo * @param $balance * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function qrd_sure($orderNo,$balance){ $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find(); if (empty($orderinfo)) { return false; } $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select(); if (empty($orderlist)) { return false; } foreach ($orderlist as $value) { if($balance==0){ break; } if($value['inv_fee'] == 0){ continue; } $order_fee=0; if($value['inv_fee']<=$balance){ $order_fee = $value['inv_fee']; $balance -=$value['inv_fee']; $value['ainv_fee'] += $value['inv_fee']; $value['inv_fee'] = 0; }else{ $value['ainv_fee'] += $balance; $value['inv_fee']-= $balance; $order_fee = $balance; $balance=0; } $value['updatetime'] = date("Y-m-d H:i:s"); $orde = Db::name("order_info")->save($value); if($orde===false){ return false; } $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find(); if (($order_fee <= $qrdinfo['inving_fee'])||($order_fee <= $qrdinfo['inving_fee']&&$orderinfo['type']==4 )) { if($orderinfo['type']==4 ){ $qrdinfo['inving_fee'] -= $order_fee; //$qrdinfo['number1618249149738'] -= $order_fee; $qrdinfo['Number1618249205231'] += $order_fee; //$qrdinfo['number1618249258956'] += $value['good_num']; $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249202608']>0 ? "2" : "1"; }else{ $qrdinfo['inving_fee'] -= $order_fee; //$qrdinfo['number1618249149738'] -= $order_fee; $qrdinfo['Number1618249202608'] += $order_fee; //$qrdinfo['number1618249258956'] += $value['good_num']; $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249205231']>0 ? "2" : "3"; } $qinfo = Db::name("qrd_info")->save($qrdinfo); if ($qinfo) { $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find(); if ($qrdp['inv_fee'] >= $order_fee || ($qrdp['inv_fee'] >= $order_fee &&$orderinfo['type']==4 )) { if($orderinfo['type']==4){ $qrdp['inv_fee'] -= $order_fee; $qrdp['winv_fee'] += $order_fee; $qrdp['inv_status'] = $qrdp['ainv_fee'] == 0 ? 1 : 2; }else{ $qrdp['inv_fee'] -= $order_fee; $qrdp['ainv_fee'] += $order_fee; $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2; } $qrd = Db::name("qrd")->save($qrdp); if(!$qrd){ return false; } }else { return false; } }else { return false; } } else { return false; } } return true; } /** * @param $orderNo * @param $balance * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function qrd_delet($orderNo,$balance){ $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 1]])->find(); if (empty($orderinfo)) { return false; } $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select(); if (empty($orderlist)) { return false; } foreach ($orderlist as $value) { if($balance==0){ break; } if($value['inv_fee'] == 0){ continue; } $order_fee=0; if($value['inv_fee']<=$balance){ $order_fee = $value['inv_fee']; $balance -=$value['inv_fee']; $value['winv_fee'] += $value['inv_fee']; $value['inv_fee'] = 0; }else{ $value['inv_fee'] -= $balance; $value['winv_fee']+= $balance; $order_fee = $balance; $balance=0; } $value['updatetime'] = date("Y-m-d H:i:s"); $orde = Db::name("order_info")->save($value); if(!$orde){ return false; } $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find(); if ($order_fee <= $qrdinfo['inving_fee']) { $qrdinfo['inving_fee'] -= $order_fee; if($orderinfo['type']==4){ $qrdinfo['Number1618249202608'] += $order_fee; // $qrdinfo['number1618249258956'] += $value['good_num']; }else{ $qrdinfo['Number1618249205231'] += $order_fee; $qrdinfo['number1618249258956'] -= $value['good_num']; } // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3"; $qinfo = Db::name("qrd_info")->save($qrdinfo); if ($qinfo) { $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find(); if ($qrdp['inv_fee'] >= $order_fee) { if($orderinfo['type']==4){ $qrdp['ainv_fee'] += $order_fee; }else{ $qrdp['winv_fee'] += $order_fee; } $qrdp['inv_fee'] -= $order_fee; // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2; $qrd = Db::name("qrd")->save($qrdp); if(!$qrd){ return false; } }else { return false; } }else { return false; } } else { return false; } } return true; } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function DownReceipt(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $condition=[["type_check","=",1],["is_del","=",0],["status","=",3]]; $inid = isset($post['invid'])&& $post['invid']!="" ? $post['invid'] :""; if($inid!=""){ $condition[]=['id',"in",$inid]; } $invice = Db::name("invoice_pool")->where($condition)->select()->toArray(); if (empty($invice)){ return error_show(1003,"未找到数据"); } $data=[]; foreach ($invice as $value){ $temp=[]; $orderNo = Db::name("assoc_list")->where([["rela_form","=",1],["is_del","=",0],['viceNo',"=",$value['invNo']]])->find(); if(!$orderNo){ continue; } $good = Db::name("order_info")->where([['orderNo',"=",$orderNo['codeNo']],["status","=",1]])->select()->toArray(); if(empty($good)){ continue; } if(isset($value['inv_out'])&& $value['inv_out']!=''){ $invout = Db::name("company_info")->where([['companyNo',"=",$value['inv_out']]])->find(); } foreach ($good as $val){ $qrd = Db::name("qrd_list")->where("sequenceNo","=",$val['goodNo'])->find(); $temp['invNo'] = $value['invNo']; $temp['qrdNo'] = $val['qrdNo']; $temp['depart'] = $qrd['bumen']; $temp['apply_name'] =$value['apply_name']; $temp['code'] =""; $temp['invoice_title'] =$value['invoice_title']; $temp['invoice_code'] =$value['invoice_code']." "; $temp['invoice_addr'] =$value['invoice_addr']; $temp['invoice_mobile'] =$value['invoice_mobile']; $temp['invoice_bank'] =$value['invoice_bank']; $temp['invoice_bankNo'] =$value['invoice_bankNo']." "; $temp['company'] =$qrd['kehu']; $temp['goodname'] =$qrd['goodname']; $temp['tax'] =$qrd['taxPoint']; $temp['inv_name'] =$val['remark']; $temp['diff_weight'] =$qrd['diff_weight']; $temp['diff_price'] =$qrd['diff_price']; $temp['unit'] =$val['unit']; $temp['num'] =$val['good_num']; $temp['price'] =$val['price']; $temp['total_fee'] =$val['total_fee']; switch ($value['inv_type']){ case 1: $temp['inv_type'] = "增值税专用发票"; break; case 2: $temp['inv_type'] = "增值税普通发票"; break; case 3: $temp['inv_type'] = "增值税电子专用发票"; break; case 4: $temp['inv_type'] = "增值税电子普通发票"; break; default: $temp['inv_type'] = "-"; break; } // $temp['inv_type'] = $value['inv_type']==1?"增值税专用发票": "增值税普通发票"; // $temp['inv_value'] =$value['inv_value']; $temp['remark'] =$value['remark']; $temp['kp_companyName'] = isset($invout['company_name']) ? $invout['company_name']:""; $temp['kp_company_address'] = isset($invout['company_address']) ? $invout['company_address']:""; $temp['kp_company_license'] = isset($invout['company_license']) ? $invout['company_license'].' ':""; $temp['kp_bank_name'] = isset($invout['bank_name']) ? $invout['bank_name']:""; $temp['kp_bankNo'] = isset($invout['bankNo']) ? $invout['bankNo'].' ':""; $temp['kp_contector'] = isset($invout['contector']) ? $invout['contector']:""; $temp['kp_mobile'] = isset($invout['mobile']) ? $invout['mobile'].' ':""; $data[]=$temp; } } if (empty($data)){ return error_show(1003,"未找到数据"); } $header=[ "申请编号", "公司订单号", "申请部门(所属平台)", "申请人", "代码", "发票开具全称", "发票开具企业纳税识别号", "发票开具企业地址", "发票开具企业地址联系方式", "发票开具企业收款银行", "发票开具企业收款账户", "分公司", "采购商品名", "税率", "发票商品名", "工差重量", "工差金额", "单位", "数量", "单价", "总价", "开票种类", "备注说明", '开票企业名称', '开票企业地址', '开票企业纳税号', '开票企业银行名称', '开票企业银行账户', '开票企业法人', '开票企业联系方式' ]; $li = excelExport("待开票",$header,$data); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function ImportReceipt(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invlist = isset($post['data'])&& $post['data']!="" ? $post['data'] :""; if($invlist==""){ return error_show(1005, '参数data 不能为空'); } $list=[]; $total =[]; foreach ($invlist as $key=>$value){ if($value['invNo']==""){ return error_show(1005,"第".($key+1)."行缺少发票申请编号数据"); } if($value["inv_type"]===""){ return error_show(1005,"第".($key+1)."行缺少发票类型数据"); } if($value["inv_code"]==""){ return error_show(1005,"第".($key+1)."行缺少发票代码数据"); } if($value["inv_number"]==""){ return error_show(1005,"第".($key+1)."行缺少发票号码数据"); } if($value["inv_total"]==""){ return error_show(1005,"第".($key+1)."行缺少发票金额数据"); } if($value["createtime"]==""){ return error_show(1005,"第".($key+1)."行缺少发票开票日期数据"); } !isset($total[$value['invNo']]) ? $total[$value['invNo']]['total']=0:""; // $inv=Db::name("invoice_list")->where([["inv_code","=",$value['inv_code']],["inv_number","=",$value['inv_number']],["is_del","=",0]])->find(); // if($inv){ // return error_show(1005,"第".($key+1)."行发票已存在"); // } $temp=[]; $temp['invNo'] = $value["invNo"]; $temp['inv_type'] = $value['inv_type']; $temp['inv_code'] = $value['inv_code']; $temp['inv_number'] = $value['inv_number']; $temp['inv_total'] = $value['inv_total']; $temp['createtime'] = $value['createtime']; $temp['status'] = 1; $temp['is_del'] = 0; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $total[$value["invNo"]]['total']+=$value['inv_total']; $list[]=$temp; } Db::startTrans(); try{ foreach ($total as $key=>$value){ $inpool = Db::name("invoice_pool")->where([["invNo","=",$key],["is_del","=",0]])->find(); $invtotal=Db::name("invoice_list")->where([["invNo","=",$key],["is_del","=",0]])->sum('inv_total'); if($inpool['inv_value']!=$value['total']+$invtotal){ Db::rollback(); if($inpool['inv_value']>$value['total']+$invtotal){ return error_show(1005,"发票上传数据{$key}不足票面总额"); }else{ return error_show(1005,"发票上传数据{$key}超出票面总额"); } } $up =Db::name("invoice_pool")->where([["invNo","=",$key],["is_del","=",0]])->save(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]); if(!$up){ Db::rollback(); return error_show(1005,"发票状态更新失败"); } } $insert = Db::name("invoice_list")->insertAll($list); if(!$insert){ Db::rollback(); return error_show(1005,"发票数据录入失败"); }else{ Db::commit(); return app_show(0,"发票数据录入成功"); } }catch (\Exception $e){ Db::rollback(); return error_show(1005,$e->getMessage()); } } public function RefundAdd() { $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : ""; $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):""; $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1; // $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0"; $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):""; $userinfo = GetUserInfo($token); $username=""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } if(isset($userinfo['code'])&&$userinfo['code']==0){ $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: ""; } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1004,"未找到客户企业信息"); } $invoice=[]; // isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:""; // isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:""; // isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] = // $post['invoice_bankNo']:""; // isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:""; // isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] = // $post['invoice_mobile']:""; // isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] = // $post['invoice_title']:""; // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){ // return error_show(1004,"企业信息联系电话格式错误"); // } $total = isset($post['total'])&&$post['total']!=""?$post['total']:""; if($total==""){ return error_show(1004,"参数total 不能为空"); } Db::startTrans(); try{ // if(!empty($invoice) && $invoice!='') { // $invoice['updatetime'] = date("Y-m-d H:i:s"); // $invoice['checkNo'] = $companyNo; // if ($inv_add == 1) { // $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find(); // if($cust){ // Db::rollback(); // return error_show(1005,"企业财务信息已存在"); // } // $invoice['addtime'] = date("Y-m-d H:i:s"); // Db::name('customer_invoice')->insert($invoice); // } else { // Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice); // } // } $invNo = makeNo("INV"); $inv = [ "invNo" => $invNo, "inv_value" => $total, "inv_out" => "", "inv_in" => $companyNo, "apply_id" =>$effetc['data']['user']['id'], "apply_name" => $username, "status" => 0, "trade_status" => 1, "order_status" => 1, "worder_fee"=>$total, "wtrade_fee"=>$total, "invoice_title" => "", "invoice_addr" => "", "invoice_mobile" => "", "invoice_code" => "", "invoice_bank" => "", "invoice_bankNo" => "", "inv_add" => 0, "inv_type"=>$inv_type, "type_check"=>5, "is_order"=>0, "remark"=>$remark, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $invinsert = Db::name("invoice_pool")->insert($inv); if($invinsert){ Db::commit(); return app_show(0,"发票创建成功"); } Db::rollback(); return error_show(1004,"发票新建失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function SaveRefundInv(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $invNo = isset($post['invNo']) && $post['invNo']!="" ? $post['invNo']:""; if($invNo==""){ return error_show(1004,"参数invNo 不能为空"); } $companyNo = isset($post['companyNo']) && $post['companyNo']!="" ? $post['companyNo']:""; if($companyNo==""){ return error_show(1004,"参数companyNo 不能为空"); } $invfo = Db::name("invoice_pool")->where([["invNo","=",$invNo],["is_del","=",0]])->find(); if(empty($invfo)){ return error_show(1005,"未找到发票数据"); } // $total_fee = isset($post['total_fee'])&&$post['total_fee']!="" ? $post['total_fee']:""; // if($total_fee==""){ // return error_show(1004,"参数total_fee 不能为空"); // } // if($trade['balance']<$total_fee){ // return error_show(1005,"资金余额不足"); // } $refundid = isset($post['refundid']) && $post['refundid']!="" ? $post['refundid'] :""; if($refundid==""){ return error_show(1006,"参数refundid 不能为空"); } $refund =Db::name("refund")->where([["is_del","=",0],['refund_status',"=",3],['id',"in",$refundid]])->select()->toArray(); if(empty($refund)){ return error_show(1006,"退款资金数据未找到"); } $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find(); if(empty($customer)){ return error_show(1005,"未找到用户数据"); } $refund_fee = array_sum(array_column($refund,"refund_fee")); if($refund_fee!=$invfo['inv_value']){ return error_show(1005,"发票额度和退票额度不符"); } // if($refund_fee<$trade['balance']){ // return error_show(1005,"资金退款余额不足"); // } Db::startTrans(); try{ $invfo['inv_in'] = $companyNo; $invfo['updatetime'] = date("Y-m-d H:i:s"); $tra = Db::name("invoice_pool")->save($invfo); if($tra){ foreach ($refund as $value){ $value['backNo']= $invfo['invNo']; $value['back_fee']= $value['refund_fee']; $value['refund_status']= 4; $value['updatetime']= date("Y-m-d H:i:s"); $ref=Db::name("refund")->save($value); if($ref){ $tadpool = Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=", $value['relaNo']],['refund_status',"=",2]])->save(["refund_status"=>3, "updatetime"=>date("Y-m-d H:i:s")]); if(!$tadpool){ Db::rollback(); return error_show(1007,"资金退款状态更新失败"); } }else{ Db::rollback(); return error_show(1007,"资金退款状态更新失败"); } } Db::commit(); return app_show(0,"欠款资金认领成功"); } Db::rollback(); return error_show(1007,"资金退款认领失败"); }catch (\Exception $e){ Db::rollback(); return error_show(1006,$e->getMessage()); } } /** * 退票关联订单 * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function InvRefundCreate(){ $post = $this->request->post(); $token = isset($post['token']) ? trim($post['token']) : ""; if ($token == "") { return error_show(101, 'token不能为空'); } $effetc = VerifyTokens($token); if (!empty($effetc) && $effetc['code'] != 0) { return error_show($effetc['code'], $effetc['message']); } $guserinfo =GetUserInfo($token); if(isset($guserinfo['code']) && $guserinfo['code']!=0){ return error_show($guserinfo['code'],$guserinfo['message']); } $invNo = isset($post['invNo'])&&$post['invNo']!="" ? trim($post['invNo']) : ""; if($invNo==""){ return error_show(1005,"参数invNo 不能为空"); } $invinfo = Db::name("invoice_pool")->where([['invNo',"=",$invNo],['is_del',"=",0]])->find(); if(empty($invinfo)){ return error_show(1005,"未找到发票数据"); } if($invinfo['type_check']!=5){ return error_show(1005,"数据不是退票数据"); } $type = isset($post['type']) && $post['type']!=="" ? $post['type'] :1; $trade = isset($post['trade'])&& $post['trade']!=="" ? $post['trade'] :""; $good = isset($post['good'])&& $post['good']!=="" ? $post['good'] :""; if($type==1 &&$trade==""){ return error_show(1005,"参数trade 不能为空"); } if($type!=1 &&$good==""){ return error_show(1005,"参数good 不能为空"); } $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : ""; $userinfo = GetUserInfo($token); $username = ""; if ($companyNo == "") { return error_show(1004, "参数companyNo 不能为空"); } if (isset($userinfo['code']) && $userinfo['code'] == 0) { $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : ""; } $customer = Db::name("customer_info")->where("companyNo", "=", $companyNo)->find(); if (empty($customer)) { return error_show(1004, "未找到客户企业信息"); } Db::startTrans(); try{ if($type!=1) { $orderinfo = []; $orderNo = makeNo('ORD'); $total = 0; $fund_fee = 0; $wfund_fee = 0; $inv_fee = 0; $winv_fee = 0; foreach ($good as $value) { $temp = []; $temp['orderNo'] = $orderNo; $temp['goodNo'] = $value['goodNo']; $goocp = Db::name("qrd_list")->where("sequenceNo", "=", $value['goodNo'])->find(); if (!$goocp) { continue; } $temp['good_name'] = $goocp['goodname']; $temp['qrdNo'] = $goocp['qrdNo']; $temp['brand'] = $goocp['brand']; $temp['unit'] = $goocp['unit']; $temp['good_num'] = $value['num']; $temp['price'] = $goocp['price']; $temp['total_fee'] = $value['total_fee']; $temp['wfund_fee'] = $value['total_fee']; $temp['winv_fee'] = $value['total_fee']; $temp['other_fee'] = 0; $temp['status'] = 1; $temp['remark'] = ""; $temp['addtime'] = date("Y-m-d H:i:s"); $temp['updatetime'] = date("Y-m-d H:i:s"); $total += $value['total_fee']; $fund_fee += $value['apay_fee']; $winv_fee += $value['winv_fee']; $inv_fee += $value['ainv_fee']; $wfund_fee += $value['wpay_fee']; $orderinfo[] = $temp; } if ($total != $invinfo['worder_fee']) { Db::rollback(); return error_show(1004, "商品总额于发票面额不符"); } $orderins = Db::name("order_info")->insertAll($orderinfo); if ($orderins) { $order = [ "orderNo" => $orderNo, "companyNo" => $companyNo, "sales_id" => $effetc['data']['user']['id'], "sales_name" => $username, "total_amount" => $total, "inv_status" => 1, "fund_status" => 1, "fund_fee" => 0, "wfund_fee" => $total, "inv_fee" => 0, "winv_fee" => $total, "status" => 0, "type" => 3, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $orderpool = Db::name("order_pool")->insert($order, true); if ($orderpool > 0) { $rela = []; $assNo = makeNo("ASC"); $cancel = 0; $balance = $invinfo["worder_fee"] > $total ? $total : $invinfo["worder_fee"]; $total -= $balance; $sav = [ "worder_fee" => $invinfo['worder_fee'] - $balance, "order_used" => $invinfo['order_used'] + $balance, "is_order" => 1, "updatetime" => date("Y-m-d H:i:s") ]; Db::name("invoice_pool")->where([["invNo", "=", $invinfo['invNo']]])->save($sav); $rela = [ "assocNo" => $assNo, "viceNo" => $orderNo, "vice_total" => $order['total_amount'], "vice_fee" => $total, "cancel_fee" => $balance, "status" => 1, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $assoc = Db::name("assoc_rela")->insert($rela); if ($assoc) { $data = [ "assocNo" => $assNo, "companyNo" => $companyNo, "type" => 1, "rela_form" => 1, "codeNo" => $invinfo["invNo"], "total_fee" => $invinfo['inv_value'], "balance" => $invinfo['worder_fee'] - $balance, "cancel_total" => $balance, "status" => 1, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $realkey = Db::name("assoc_key")->insert($data); if ($realkey) { Db::name("invoice_pool")->where("invNo", "=", $invNo)->save(["wfund_fee" => $total, 'fund_used' => $balance, "updatetime" => date("Y-m-d H:i:s")]); $qrdup = $this->updateQrd($orderNo, $balance); if (!$qrdup) { Db::rollback(); return error_show(1004, "新建关联申请失败"); } Db::commit(); return app_show(0, "新建关联成功"); } } Db::rollback(); return error_show(1004, "新建关联申请失败"); } } Db::rollback(); return error_show(1004, "新建关联申请失败"); }else{ $rela = []; $trade = 0; $assNo = makeNo("ASC"); foreach ($trade as $value) { $balance = $invinfo['wtrade_fee'] > $value['cancel'] ? $value['cancel'] : $invinfo['wtrade_fee']; if ($invinfo['wtrade_fee'] <= 0) { Db::rollback(); return error_show(1005, "资金总额大于发票额度"); } if ($value['inv_fee'] <= 0) { Db::rollback(); return error_show(1005, "发票核销金额为0"); } $invinfo['wtrade_fee'] -= $balance; $invinfo['fund_used'] += $balance; $trade += $balance; $rela[] = [ "assocNo" => $assNo, "viceNo" => $value['traNo'], "vice_total" => $value['total_fee'], "vice_fee" => $value['inv_fee'] - $balance, "cancel_fee" => $balance, "status" => 1, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $value['inv_fee'] -= $balance; $value['inv_used'] += $balance; $value['updatetime'] = date("Y-m-d H:i:s"); Db::name("trade_pool")->save($value); } $assoc = Db::name("assoc_rela")->insertAll($rela); if ($assoc) { $data = [ "assocNo" => $assNo, "companyNo" => $companyNo, "type" => 2, "rela_form" => $type, "codeNo" => $invinfo["invNo"], "total_fee" => $invinfo['inv_value'], "balance" => $invinfo['wtrade_fee'], "cancel_total" => $trade, "status" => 1, "addtime" => date("Y-m-d H:i:s"), "updatetime" => date("Y-m-d H:i:s") ]; $realkey = Db::name("assoc_key")->insert($data); if ($realkey) { $invinfo['updatetime'] = date("Y-m-d H:i:s"); $order_up = Db::name("invoice_pool")->save($invinfo); Db::commit(); return app_show(0, "新建关联成功"); } } Db::rollback(); return error_show(1004, "新建关联申请失败"); } }catch (\Exception $e){ Db::rollback(); return error_show(1004,$e->getMessage()); } } }