1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467 |
- <?php
- declare (strict_types = 1);
- namespace app\Admin\controller;
- use app\BaseController;
- use think\facade\Db;
- use think\Request;
- class Receipt extends BaseController
- {
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function list()
- {
- $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'],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());
- }
- }
- }
|