1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\CgdInfo;
- use app\admin\model\FhdChild;
- use app\admin\model\GoodCombind;
- use app\admin\model\InvoiceOrder;
- use app\admin\model\InvoicePay;
- use app\admin\model\InvoicePool;
- use app\admin\model\OrderCategory;
- use app\admin\model\Pay;
- use app\admin\model\InvoiceInfo;
- use app\admin\model\PayInvoice;
- use app\admin\model\ReportCode;
- use think\App;use think\Exception;
- use think\facade\Config;
- use think\facade\Db;
- use think\facade\Validate;
- class Payment extends Base
- {
- protected $invoiceType;
- protected $invName;
- // 发票状态,取值范围:
- //
- // 正常:valid
- // 已作废:invalidated
- // 已红冲:reversed
- protected $invStatus=[0=>"待验证","1"=>'正常',"2"=>'已作废',"3"=>'已红冲'];
-
- public function __construct(App $app) {
- parent::__construct($app);
- $invoice =Config::get("invoiceType");
- $this->invoiceType = $invoice['invoiceName'];
- $this->invName = $invoice['invoiceType'];
- }
- /**
- *付款详细列表
- * @return \think\Response
- */
- public function paymentList()
- {
- $post = $this->post;
- $condition = [["a.is_del","=",0],['pay_type','=',$post['pay_type']??1]];
- $check = checkRole($this->roleid,[79,119]);
- if($check){
- $condition[]=["b.apply_id","=",$this->uid];
- }
- $startTime= isset($post['startTime'])&&$post['startTime']!="" ? date("Y-m-d 00:00:00",strtotime($post['startTime']))
- :"";
- $endTime= isset($post['endTime'])&&$post['endTime']!="" ? date("Y-m-d 23:59:59",strtotime($post['endTime']))
- :"";
- $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
- $supplierName= isset($post['supplierName'])&&$post['supplierName']!="" ? trim($post['supplierName']) :"";
- $companyNo= isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
- $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
- $apply= isset($post['apply_name'])&&$post['apply_name']!="" ? trim($post['apply_name']) :"";
- $paystatus= isset($post['status'])&&$post['status']!="" ? $post['status'] :"";
- $dzNo= isset($post['dzNo'])&&$post['dzNo']!="" ? trim($post['dzNo']) :"";
- if($startTime!=""){
- $condition[]=['b.addtime','>=',$startTime];
- }
- if($endTime!=""){
- $condition[]=['b.addtime','<=',$endTime];
- }
- if($supplierNo!=""){
- $condition[]=['a.supplierNo','=',$supplierNo];
- }
- if($supplierName!=""){
- $condition[]=['a.supplierName','like',"%$supplierName%"];
- }
- if($companyNo!=""){
- $condition[]=['a.companyNo','=',$companyNo];
- }
- $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!=""){
- $condition[]=['a.companyNo|a.supplierNo','=',$relaComNo];
- }
- if($payNo!=""){
- $condition[]=['a.payNo','like',"%$payNo%"];
- }
- if($dzNo!=""){
- $condition[]=['b.dzNo','like',"%$dzNo%"];
- }
- if($apply!=""){
- $condition[]=['b.apply_name','like',"%$apply%"];
- }
- if($paystatus!=""){
- $condition[]=['b.status','=',$paystatus];
- }
- if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
- $count = Db::name("pay_payment")->alias('b')
- ->join("pay a","`a`.`payNo` = `b`.`payNo` AND b.is_del = 0 ",'left')
- ->where($condition)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("pay_payment")->alias('b')
- ->join("pay a","`a`.`payNo` = `b`.`payNo` AND ( `b`.`is_del` = 0 ) ",'left')
- ->where($condition)->page(intval($page),$size)->order("b.addtime desc")
- ->field(" `b`.`id` AS `id`,
- `a`.`payNo` AS `payNo`,
- `a`.`supplierNo`,
- `a`.`supplierName`,
- `a`.`apay_fee` ,
- `a`.`total_fee` AS `total_fee`,
- `b`.`apply_name`,
- `b`.`apply_id`,
- `a`.`is_comon`,
- `a`.`winv_fee` ,
- `a`.`ainv_fee` ,
- `a`.`wpay_fee` ,
- `a`.`pay_status` ,
- `a`.`inv_status` ,
- `b`.`pay_fee` AS `dpay_fee`,
- `b`.`return_img`,
- `b`.`return_time`,
- `b`.`status` AS `dstatus`,
- `a`.`status`,
- `a`.`remark` AS `remark`,
- `b`.`addtime` ,
- `a`.`companyNo` ,
- `a`.`companyName` ,
- `b`.`dzNo` AS `dzNo`
- ")->select()->toArray();
- //校验是否开通了供应商账号
- $supp_account = check_has_account_by_supplierNos(array_unique(array_column($list,'supplierNo')));
- $data=[];
- foreach ($list as $key=>$value){
- $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count();
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- $data[]=$value;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- /**
- *对账单列表
- * @return \think\Response
- */
- public function payList()
- {
- $post = $this->post;
- $condition = [["is_del","=",0],['pay_type','=',$post['pay_type']??1]];
- $check = checkRole($this->roleid,[77,117]);
- if($check){
- $condition[]=["apply_id","=",$this->uid];
- }
- $startTime= isset($post['startTime'])&&$post['startTime']!="" ? date("Y-m-d 00:00:00",strtotime($post['startTime'])) :"";
- $endTime= isset($post['endTime'])&&$post['endTime']!="" ? date("Y-m-d 23:59:59",strtotime($post['endTime'])) :"";
- $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
- $supplierName= isset($post['supplierName'])&&$post['supplierName']!="" ? trim($post['supplierName']) :"";
- $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
- $paystatus= isset($post['pay_status'])&&$post['pay_status']!="" ? $post['pay_status'] :"";
- $inv_status= isset($post['inv_status'])&&$post['inv_status']!="" ? $post['inv_status'] :"";
- $status= isset($post['status'])&&$post['status']!="" ? $post['status'] :"";
- $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
- if($tag_id!==''){
- if($tag_id==1) $condition[]=["inv_tag","=",1];
- if($tag_id==2) $condition[]=["pay_tag","=",1];
- if($tag_id==3) $condition[]=["pay_tag|inv_tag","=",1];
- if($tag_id==4) $condition[]=["pay_tag&inv_tag","=",1];
- }
- if($startTime!=""){
- $condition[]=["addtime",">=",$startTime];
- }
- if($endTime!=""){
- $condition[]=["addtime","<=",$endTime];
- }
- if($supplierNo!=""){
- $condition[]=["supplierNo","like","%$supplierNo%"];
- }
- if($supplierName!=""){
- $condition[]=["supplierName","like","%$supplierName%"];
- }
- if($payNo!=""){
- $condition[]=["payNo","like","%$payNo%"];
- }
- if($inv_status!==''){
- if($inv_status==0){
- $condition[]=["inv_status","<>",3];
- }else{
- $condition[]=["inv_status","=",$inv_status];
- }
- }
- if($paystatus!==''){
- if($paystatus==0){
- $condition[]=["pay_status","<>",3];
- }else{
- $condition[]=["pay_status","=",$paystatus];
- }
- }
- $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
- if($companyNo!==''){
- $condition[]=["companyNo","=",$companyNo];
- }
- $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!=""){
- $condition[]=["companyNo|supplierNo","=",$relaComNo];
- }
- $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
- if($companyName !=''){
- $condition[]=["companyName","like","%$companyName%"];
- }
- if($status!=""){
- $condition[]=["status","=",$status];
- }
- if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
- $count = Db::name("pay")->where($condition)->count();
- $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
- $page = $page>=$total?intval($total):$page;
- $list = Db::name("pay")->where($condition)->page(intval($page),$size)->order("addtime desc")->select()->toArray();
- //校验是否开通了供应商账号
- $supp_account = check_has_account_by_supplierNos(array_unique(array_column($list,'supplierNo')));
- $data=[];
- foreach ($list as $key=>$value){
- $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0],['status','=',1]])->count();
- $value['inv_tag_name']='';
- $value['pay_tag_name']='';
- $value['pay_tag_img']='';
- $value['inv_tag_id']='0';
- $value['pay_tag_id']='0';
- $value['pay_tag_remark']='';
- $value['inv_tag_img']='';
- $value['inv_tag_remark']='';
- if($value['pay_tag']==1 || $value['inv_tag']==1){
- $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
- (['code'=>$value['payNo'],"a.status"=>[1,2]])->order('a.id desc')->column('a.id,b.tag_name,a.tag_img,a
- .tag_remark','b.type');
- if($value['inv_tag']==1){
- $value['inv_tag_name']=$tag[2]['tag_name']??'';
- $value['inv_tag_id']=$tag[2]['id']??'0';
- $value['inv_tag_img']=$tag[2]['tag_img']??'';
- $value['inv_tag_remark']=$tag[2]['tag_remark']??'';
- }
- if($value['pay_tag']==1){
- $value['pay_tag_id']=$tag[1]['id']??'0';
- $value['pay_tag_name']=$tag[1]['tag_name']??'';
- $value['pay_tag_img']=$tag[1]['tag_img']??'';
- $value['pay_tag_remark']=$tag[1]['tag_remark']??'';
- }
- }
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- $data[]=$value;
- }
- return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
- }
- /**
- * 新建对账付款数据
- * @return \think\Response
- */
- public function PayAdd()
- {
- $post = $this->post;
- $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :"";
- if($cids==""){
- return error_show(1003,"参数cids不能为空");
- }
- $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids)])->select()->toArray();
- if(empty($cgdall)){
- return error_show(1003,"采购单数据不能为空");
- }
- $statusAll = array_column($cgdall,"status");
- $isComonAll = array_unique(array_column($cgdall,'is_comon')) ;
- if(count($isComonAll)>1){
- return error_show(1003,"采购单业务类型不一致");
- }
- if(in_array(1,$statusAll)){
- return error_show(1003,'采购单存在已对账数据');
- }
- if(in_array(2,$statusAll)){
- return error_show(1003,"采购单存在不核算数据");
- }
- $supplierNo= array_column($cgdall,"supplierNo");
- $supplierName= array_column($cgdall,"supplierName");
- if(count(array_unique($supplierNo))>1){
- return error_show(1003,"采购单数据供应商不一致");
- }
- $companyNo= array_column($cgdall,"companyNo");
- $companyName= array_column($cgdall,"companyName");
- if(count(array_unique($companyNo))>1){
- return error_show(1003,"采购单数据业务公司不一致");
- }
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$supplierNo[0]]);
- if (isset($temp['data'][$supplierNo[0]])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- $goodNo= array_column($cgdall,'goodNo');
- $good_info = \app\admin\model\Good::where(['spuCode'=>$goodNo])->column("status","spuCode");
- $payNo = makeNo("PAY");
- Db::startTrans();
- try {
- $data=[];
- $paydata=[
- "payNo"=>$payNo,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "total_fee"=>0,
- "is_comon"=>$isComonAll[0],
- "supplierNo"=>$supplierNo[0],
- "supplierName"=>$supplierName[0],
- "companyNo"=>$companyNo[0],
- "companyName"=>$companyName[0],
- "wpay_fee"=>0,
- "apay_fee"=>0,
- "ainv_fee"=>0,
- "winv_fee"=>0,
- "remark"=>"",
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- foreach ($cgdall as $key=>$value){
- if(!isset($good_info[$value['goodNo']])|| $good_info[$value['goodNo']]==0){
- Db::rollback();
- return error_show(1004,"采购单商品{$value['goodNo']}商品未确认开票类目");
- }
- $temp=[];
- $temp['cgdNo']=$value['sequenceNo'];
- $temp['total_fee']=$value['totalPrice'];
- $temp['apay_fee']=round($value['apay_fee'],2);
- $temp['wpay_fee']=round($value['wpay_fee'],2);
- $temp['winv_fee']=round($value['winv_fee'],2);
- $temp['ainv_fee']=round($value['ainv_fee'],2);
- $temp['payNo']=$payNo;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $data[]=$temp;
- $paydata['total_fee']+= $temp['total_fee'];
- $paydata['apay_fee']+= $temp['apay_fee'];
- $paydata['wpay_fee']+= $temp['wpay_fee'];
- $paydata['ainv_fee']+= $temp['ainv_fee'];
- $paydata['winv_fee']+= $temp['winv_fee'];
- }
- ReportCode::where(['cgdNo'=>array_column($cgdall,"sequenceNo")])->update(['payNo'=>$payNo]);
- $paydata['total_fee']= round($paydata['total_fee'],2);
- $paydata['apay_fee']= round($paydata['apay_fee'],2);
- $paydata['wpay_fee']= round($paydata['wpay_fee'],2);
- $paydata['ainv_fee']= round($paydata['ainv_fee'],2);
- $paydata['winv_fee']= round($paydata['winv_fee'],2);
- $info = Db::name("pay_info")->insertAll($data);
- if($info!=0){
- $payDA=Db::name("pay")->insert($paydata);
- if($payDA){
- $cgddup= Db::name("cgd_info")->where("id","in",$cids)->save(['status'=>1,"updatetime"=>date("Y-m-d
- H:i:s")]);
- if($cgddup){
- Db::commit();
- return app_show(0,"添加成功",["payNo"=>$payNo]);
- }
- }
- }
- Db::rollback();
- return error_show(1003,"添加失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1003,$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 PaySave()
- {
- $post = $this->post;
- $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :"";
- if($cids==""){
- return error_show(1003,"参数cids不能为空");
- }
- $payNo = isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
- if($payNo==""){
- return error_show(1003,"参数 payNo 不能为空");
- }
- $payinfo = Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1003,"未找到对账单数据");
- }
- if($payinfo['status']!=1){
- return error_show(1003,"对账单已提交审核");
- }
- $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids)])->select()->toArray();
- if(empty($cgdall)){
- return error_show(1003,"采购单数据不能为空");
- }
- $supplierNo= array_column($cgdall,"supplierNo");
- $supplierName= array_column($cgdall,"supplierName");
- if(count(array_unique($supplierNo))>1){
- return error_show(1003,"采购单数据供应商不一致");
- }
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
- if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- $companyNo= array_column($cgdall,"companyNo");
- $companyName= array_column($cgdall,"companyName");
- if(count(array_unique($companyNo))>1){
- return error_show(1003,"采购单数据业务公司不一致");
- }
- $cgdArr=array_column($cgdall,"sequenceNo");
- $cgdNo = Db::name("pay_info")->where([["payNo","=",$payNo],["is_del","=",0]])->column("cgdNo");
- $add=[];
- $remove=[];
- if(!empty($cgdNo)){
- $remove = array_diff($cgdNo,$cgdArr);
- $add = array_diff($cgdArr,$cgdNo);
- }
- Db::startTrans();
- try {
- $data=[];
- $paydata=[
- "supplierNo"=>$supplierNo[0],
- "supplierName"=>$supplierName[0],
- "companyNo"=>$companyNo[0],
- "companyName"=>$companyName[0],
- "wpay_fee"=>0,
- "apay_fee"=>0,
- "ainv_fee"=>0,
- "winv_fee"=>0,
- "total_fee"=>0,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- foreach ($cgdall as $key=>$value){
- if(!empty($add)&& in_array($value['sequenceNo'],$add)){
- $temp=[];
- $temp['cgdNo']=$value['sequenceNo'];
- $temp['total_fee']=$value['totalPrice'];
- $temp['apay_fee']=round($value['apay_fee'],2);
- $temp['wpay_fee']=round($value['wpay_fee'],2);
- $temp['winv_fee']=round($value['winv_fee'],2);
- $temp['ainv_fee']=round($value['ainv_fee'],2);
- $temp['payNo']=$payNo;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $data[]=$temp;
- $report=ReportCode::where(["cgdNo"=>$value['sequenceNo']])->find();
- if($report)$report->setField("payNo",$payNo);
- }
- $paydata['total_fee']+= $value['totalPrice'];
- $paydata['apay_fee']+= $value['apay_fee'];
- $paydata['wpay_fee']+= $value['wpay_fee'];
- $paydata['ainv_fee']+= $value['ainv_fee'];
- $paydata['winv_fee']+= $value['winv_fee'];
- }
- $paydata['total_fee']= round($paydata['total_fee'],2);
- $paydata['apay_fee']= round($paydata['apay_fee'],2);
- $paydata['wpay_fee']= round($paydata['wpay_fee'],2);
- $paydata['ainv_fee']= round($paydata['ainv_fee'],2);
- $paydata['winv_fee']= round($paydata['winv_fee'],2);
- $payDA=Db::name("pay")->where($payinfo)->update($paydata);
- if($payDA){
- if(!empty($remove)){
- foreach ($remove as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("payNo",$payNo);
- }
- $payrm = Db::name("pay_info")->where(["cgdNo"=>$remove,"is_del"=>0])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($payrm==false){
- Db::rollback();
- return error_show(1004,"修改失败");
- }
- $cgdrm= Db::name("cgd_info")->where([["sequenceNo","in",$remove],["status","=",1]])->save(['status'=>0, "updatetime"=>date("Y-m-d H:i:s")]);
- if($cgdrm==false){
- Db::rollback();
- return error_show(1005,"修改失败");
- }
- }
- if(!empty($add)){
- $cgddup= Db::name("cgd_info")->where([["sequenceNo","in",$add],["status","=",0]])->save(['status'=>1, "updatetime"=>date("Y-m-d H:i:s")]);
- if($cgddup==false){
- Db::rollback();
- return error_show(1006,"修改失败");
- }
- }
- if(!empty($data)){
- $info = Db::name("pay_info")->insertAll($data);
- if($info==false){
- Db::rollback();
- return error_show(1003,"修改失败");
- }
- }
- Db::commit();
- return app_show(0,"修改成功",["payNo"=>$payNo]);
- }
- Db::rollback();
- return error_show(1007,"添加失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1003,$e->getMessage());
- }
- }
- /**
- * 对账付款状态审核 status 0 待提交 1 待买方审核 2 审核成功 3驳回 4 对账单撤销,释放采购单数据
- * @param \think\Request $request
- * @return \think\Response
- */
- public function PayStatus()
- {
- $post = $this->post;
- $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):"";
- if($payNo==""){
- return error_show(1004,"参数payNo不能为空");
- }
- $status= isset($post['status']) && $post['status']!=="" ? trim($post['status']):"";
- if($status===""){
- return error_show(1004,"参数status不能为空");
- }
- $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find();
- if($data==false){
- return error_show(1004,"未能找到对应数据");
- }
- $remark = isset($post['remark']) && $post['remark']!=""? trim($post['remark']):"";
- $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)){
- return error_show(1004,"未能找到对应对账数据");
- }
- if($status==4){
- $stages = Db::name("pay_payment")->where(['status'=>[0,1,2,3,4],"payNo"=>$payNo,"is_del"=>0])
- ->findOrEmpty();
- if(!empty($stages)) return error_show(1004,"对账单存在未解除的付款申请单");
- $hpinv = Db::name("pay_invoice")->where(['status'=>[0,1,2,3,4,9,11,12],"payNo"=>$payNo,"is_del"=>0])->findOrEmpty();
- if(!empty($hpinv)) return error_show(1004,"对账单存在未解除的回票申请单");
- if($data['inv_tag']==1)$this->error("存在回票标签未解除");
- if($data['pay_tag']==1)$this->error("存在付款标签未解除");
- if($data['is_comon']==1){
- $invoceAr=InvoicePay::where(["payNo"=>$payNo])->column("invNo");
- if(!empty($invoceAr)){
- $ist= InvoicePool::where([["invNo","in",$invoceAr],["status","in",[0,1,2,3,4]]])->select()
- ->isEmpty();
- if($ist==false)$this->error('通用订单存在开票申请未解除');
- }
- }
- }
- Db::startTrans();
- try{
- $update=[
- "status"=>$status,
- "remark"=>$remark,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $result = Db::name("pay")->where("payNo","=",$payNo)->update($update);
- if($result){
- if($status==3 || $status==4){
- if($data['pay_type']==1){
- CgdInfo::where(['sequenceNo'=>$cgdNo,'status'=>1])->update(['status'=>0,
- 'updatetime'=>date('Y-m-d H:i:s')]);
-
- }else{
- \app\admin\model\Track::where(["TrackCode"=>$cgdNo,"status"=>1])->update(["status"=>0]);
- }
-
- $payinfoup =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->update(['status'=>0,"updatetime"=>date("Y-m-d H:i:s")]);
- if($payinfoup==false){
- Db::rollback();
- return error_show(1004,"对账驳回失败");
- }
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("payNo",$payNo);
- }
- }
- Db::commit();
- if(($status==3 || $status==4)&&$data['is_comon']==1){
- event("comonOrder",["payNo"=>$payNo,"type"=>"check"]);
- }
- 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
- */
- public function payDel(){
- $post = $this->post;
- $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):"";
- if($payNo==""){
- return error_show(1004,"参数payNo不能为空");
- }
- $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find();
- if($data==false){
- return error_show(1004,"未能找到对应数据");
- }
- if($data['status']==2){
- return error_show(1004,"对账单已审核通过");
- }
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$data['supplierNo']]);
- if (isset($temp['data'][$data['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)){
- return error_show(1004,"未能找到对应对账数据");
- }
- Db::startTrans();
- try{
- $payDel = ["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
- $pay =Db::name("pay")->where($data)->update($payDel);
- if($pay){
- $infoup =Db::name("pay_info")->where(["cgdNo"=>$cgdNo,"payNo"=>$payNo,"is_del"=>0])->update($payDel);
- if($infoup==false){
- Db::rollback();
- return error_show(1004,"对账删除失败");
- }
- if(in_array($data['status'],[0,1,2])){
- if($data['pay_type']==1){
- CgdInfo::where(['sequenceNo'=>$cgdNo,'status'=>1])->update(['status'=>0,
- 'updatetime'=>date('Y-m-d H:i:s')]);
-
- }else{
- \app\admin\model\Track::where(['TrackCode'=>$cgdNo,'status'=>1])->update(['status'=>0]);
- }
- }
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("payNo",$payNo);
- }
- Db::commit();
- return error_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 stageAdd()
- {
- $post = $this->post;
- $payNo = isset($post['payNo'])&& $post['payNo']!="" ? trim($post['payNo']) :"";
- if($payNo==""){
- return error_show(1004,"参数payNo 不能为空");
- }
- $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"未找到对账信息");
- }
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- if($payinfo['status']!=2){
- return error_show(1004,"对账未审核完成");
- }
- $pay_fee = isset($post['pay_fee'])&& $post['pay_fee']!="" ? floatval($post['pay_fee']) :"";
- if($pay_fee==""){
- return error_show(1004,"参数 pay_fee 不能为空或零");
- }
- if($payinfo['wpay_fee']< $pay_fee){
- return error_show(1004,"对账单未付金额不足");
- }
- $dzno=makeNo("DZ");
- Db::startTrans();
- try {
- $ment =[
- "payNo"=>$payNo,
- "dzNo"=>$dzno,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "pay_fee"=>$pay_fee,
- "return_img"=>'',
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $payment =Db::name("pay_payment")->insert($ment);
- if($payment){
- $update=[
- "pay_fee"=> round($payinfo['pay_fee']+$pay_fee,2),
- "wpay_fee"=> round($payinfo['wpay_fee']-$pay_fee,2),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $payup = Db::name("pay")->where($payinfo)->update($update);
- if($payup){
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->setField("DzNo",$dzno);
- }
- Db::commit();
- return app_show(0,"付款申请添加成功",["dzNo"=>$dzno]);
- }
- }
- Db::rollback();
- return error_show(1004,"付款申请添加失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- /**
- * 付款申请审核状态
- * 付款审核状态 0待发起 1待业务审核 2带财务审核 3待回执 4付款完成 5 付款已退 6 业务驳回 7 财务驳回
- * @param int $id
- * @return \think\Response
- */
- public function stageStatus()
- {
- $post = $this->post;
- $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :"";
- if($dzNo==""){
- return error_show(1004,"参数 dzNo 不能为空");
- }
- $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
- if($status==""){
- return error_show(1004,"参数status 不能为空");
- }
- if(!in_array($status,[0,1,2,3,4,5,6,7])){
- return error_show(1004,"参数status 无效值");
- }
- $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find();
- if($payment==false){
- return error_show(1005,"未找到付款申请信息");
- }
- $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
- if($payinfo==false){
- return error_show(1005,"未找到对账信息");
- }
- if($payinfo['status']!=2){
- return error_show(1005,"对账信息未完成审核");
- }
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- $remark = isset($post['remark'])? trim($post['remark']) :"";
- $image = isset($post['return_image'])? trim($post['return_image']) :"";
- $return_time = isset($post['return_time'])? trim($post['return_time']) :date("Y-m-d H:i:s");
- if($status==4){
- if($image=="")return error_show(1005,"付款回单图片不能为空");
- if($return_time=="")return error_show(1005,"付款回单时间不能为空");
- if($payinfo['pay_fee']< $payment['pay_fee'])return error_show(1005,"对账付款申请金额有误,请确认对账申请金额");
- }
- Db::startTrans();
- try{
- $payment= Db::name('pay_payment')->where([['dzNo','=',$dzNo],['is_del','=',0]])->lock(true)->find();
- $mentupdate =["status"=>$status,"remark"=>$remark,"return_img"=>$image,"updatetime"=>date("Y-m-d H:i:s")];
- if($status==3) $mentupdate['return_time'] = $return_time;
- $payup=Db::name("pay_payment")->where($payment)->update($mentupdate);
- if($payup){
- if (in_array($status,[4,5,6,7])){
- if($payinfo['pay_fee']<$payment['pay_fee']) throw new Exception("对账单付款中金额不足");
- if($status==4){ //审核通过 扣减对账付款中的金额 添加到已付金额
- $payupdate =[
- "apay_fee"=>$payinfo['apay_fee']+$payment['pay_fee'],
- "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'],
- "pay_status" => ($payinfo['pay_fee']-$payment['pay_fee'])==0 && $payinfo['wpay_fee']==0 ?3:2,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- }
- if(in_array($status,[5,6,7])){//审核驳回 扣减对账付款中的金额 返回到待付金额中
- $payupdate =[
- "wpay_fee"=>$payinfo['wpay_fee']+$payment['pay_fee'],
- "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'],
- "pay_status" => $payinfo['apay_fee']==0 ?1:2,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("DzNo",$dzNo);
- }
- }
- $pay = Db::name("pay")->where($payinfo)->update($payupdate);
- if($pay==false){
- Db::rollback();
- return error_show(1003,"对账状态修改失败");
- }
- }
- Db::commit();
- if($payinfo['is_comon']==1 && $status==4){
- event("comonOrder",["payNo"=>$payinfo['payNo'],"pay_fee"=>$payment['pay_fee'],"type"=>"pay"]);
- }
- return app_show(0,"状态修改成功");
- }else{
- Db::rollback();
- return error_show(1003,"状态修改失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1008,$e->getMessage());
- }
- }
- /**对账申请删除
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function stageDel(){
- $post = $this->post;
- $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :"";
- if($dzNo==""){
- return error_show(1004,"参数 dzNo 不能为空");
- }
- $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find();
- if($payment==false){
- return error_show(1005,"未找到付款申请信息");
- }
- $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
- if($payinfo==false){
- return error_show(1005,"未找到付款信息");
- }
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- Db::startTrans();
- try{
- $paym = Db::name("pay_payment")->where($payment)->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- if($paym){
- if(in_array($payment['status'],[1,2,3,4])){
- if(in_array($payment['status'],[1,2,3])){
- $payinfo['wpay_fee']+=$payment['pay_fee'];
- $payinfo['pay_fee']-=$payment['pay_fee'];
- $payinfo['updatetime']=date("Y-m-d H:i:s");
- }
- if($payment['status']==4){
- $payinfo['wpay_fee']+=$payment['pay_fee'];
- $payinfo['apay_fee']-=$payment['pay_fee'];
- $payinfo['pay_status']=$payinfo['apay_fee']==0? 1 : 2 ;
- $payinfo['updatetime']=date("Y-m-d H:i:s");
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("DzNo",$dzNo);
- }
- }
- $pay = Db::name("pay")->save($payinfo);
- if($pay==false){
- Db::rollback();
- return error_show(1003,"对账状态修改失败");
- }
- }
- Db::commit();
- return app_show(0,"对账申请删除成功");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1003,$e->getMessage());
- }
- }
- /**
- * 采购单列表
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function CgdList()
- {
- $post = $this->post;
- $condition = [["cgdSource|cgdType","<>",1],['a.is_del',"=",0]];
- $check = checkRole($this->roleid,[76,116]);
- if($check){
- $condition []=["ownerid","=",$this->uid];
- }
- $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo']!='' ? trim($post['sequenceNo']) :"";
- if($sequenceNo!=""){
- $condition []=["a.sequenceNo","like","%$sequenceNo%"];
- }
-
- $Total = isset($post['total']) && $post['total']!='' ? trim($post['total']) :'';
- if($Total!=''){
- $condition []=['totalPrice',$Total==1?"=":'>',0];
- }
- $orderCode = isset($post['qrdCode']) && $post['qrdCode']!='' ? trim($post['qrdCode']) :"";
- if($orderCode!=""){
- $condition []=["qrdCode","like","%$orderCode%"];
- }
- $status = isset($post['status']) && $post['status']!=='' ? intval($post['status']) :"";
- $cgd_status = isset($post['cgd_status']) && $post['cgd_status']!=='' ? intval($post['cgd_status']) :"";
- if($cgd_status!==''){
- $condition[]=['cgd_status','=',$cgd_status];
- }
- if($status!==""){
- if($status!==''){
- if($status==3){
- $condition[]=["a.status","<>",2];
- }else{
- $condition[]=["a.status","=",$status];
- }
- }
- }
- $companyNo = isset($post['companyNo']) && $post['companyNo']!='' ? trim($post['companyNo']) :"";
- if($companyNo!=""){
- $condition []=["companyNo","=",$companyNo];
- }
-
- $payNo=isset($post['payNo']) && $post['payNo'] != '' ? trim($post['payNo']) : '';
- if ($payNo != '') {
- $condition []=[
- 'payNo' ,'like' , "%$payNo%"
- ];
- }
- $cxCode = isset($post['cxCode'])&&$post['cxCode']!==''?trim($post['cxCode']):'';
- if($cxCode!==''){
- $condition[]=["cxCode","=",$cxCode];
- }
- $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!=""){
- $condition[]=["companyNo|supplierNo","=",$relaComNo];
- }
- $companyName = isset($post['companyName']) && $post['companyName']!='' ? trim($post['companyName']) :"";
- if($companyName!=""){
- $condition []=["companyName","like","%$companyName%"];
- }
- $bkCode = isset($post['bkCode']) && $post['bkCode']!='' ? trim($post['bkCode']) :"";
- if($bkCode!=""){
- $condition []=["bkCode","like","%$bkCode%"];
- }
- $goodNo = isset($post['goodNo']) && $post['goodNo']!='' ? trim($post['goodNo']) :"";
- if($goodNo!=""){
- $condition []=["goodNo","like","%$goodNo%"];
- }
- $goodName = isset($post['goodName']) && $post['goodName']!='' ? trim($post['goodName']) :"";
- if($goodName!=""){
- $condition []=["goodName","like","%$goodName%"];
- }
- $supplierName = isset($post['supplierName']) && $post['supplierName']!='' ? trim($post['supplierName']) :"";
- if($supplierName!=""){
- $condition []=["supplierName","like","%$supplierName%"];
- }
- $supplierNo = isset($post['supplierNo']) && $post['supplierNo']!='' ? trim($post['supplierNo']) :"";
- if($supplierNo!=""){
- $condition []=["supplierNo","=",$supplierNo];
- }
- $start=isset($post['start'])&& $post['start']!=''?trim($post['start']):"";
- $end=isset($post['end'])&& $post['end']!=''?trim($post['end']):"";
- if($start!='') $condition []=["cgdTime",">=",date("Y-m-d 00:00:00",strtotime($start))];
- if($end!='') $condition []=["cgdTime","<=",date("Y-m-d 23:59:59",strtotime($end))];
- $cgder= isset($post['cgder']) && $post['cgder']!='' ? trim($post['cgder']) :"";
- if($cgder!='') $condition []=["ownerName","like","%$cgder%"];
- $cgderid= isset($post['cgderid']) && $post['cgderid']!='' ? trim($post['cgderid']) :"";
- if($cgderid!='') $condition []=["ownerid","=",$cgderid];
- $cgdtype= isset($post['cgdtype']) && $post['cgdtype']!='' ? intval($post['cgdtype']) :"";
- if($cgdtype!='') $condition []=["cgdType","=",$cgdtype];
- $cgdsource= isset($post['cgdsource']) && $post['cgdsource']!=='' ? intval($post['cgdsource']) :"";
- if($cgdsource!=='') $condition []=["cgdSource","=",$cgdsource];
- $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
- if($sendstatus!='') $condition []=["qrdSend","=",$sendstatus];
- if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=["is_comon","=",$post['is_comon']];
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
-
- $list = CgdInfo::alias("a")
- ->leftJoin("pay_info b","a.sequenceNo=b.cgdNo and b.is_del=0 and b.status=1")
- ->where($condition)
- ->order("a.id","desc")
- ->field("a.*,b.payNo")
- ->paginate (["list_rows"=>$size,"page"=>$page])->each(function(&$item){
- $item['orderTax'] = OrderCategory::where(['code' => $item['sequenceNo'], 'spuCode' => $item['goodNo']])
- ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
- $item['catInfo'] = json_decode($item['catInfo'],true);
- });
- //校验是否开通了供应商账号
- $supplierAr=array_unique(array_column($list->items(),'supplierNo'));
- $supp_account = check_has_account_by_supplierNos($supplierAr);
- $payArr=Db::name('supplier_info')->whereIn('code',$supplierAr)->column('pay_method','code');
- foreach ($list->items() as &$value){
- $value["pay_type"]=$payArr[$value['supplierNo']]??"";
- $value['goodNum'] =$value['goodNum']- $value['thNum'];
- $value['sendNum'] =$value['sendNum']- $value['thNum'];
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- $value['inv_tag_name']='';
- $value['pay_tag_name']='';
- $value['pay_tag_img']='';
- $value['inv_tag_id']='0';
- $value['pay_tag_id']='0';
- $value['pay_tag_remark']='';
- $value['inv_tag_img']='';
- $value['inv_tag_remark']='';
- if($value['pay_tag']==1 || $value['inv_tag']==1){
- $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
- (['code'=>$value['sequenceNo'],'a.status'=>[5,6]])->order('a.id desc')->column('a.id,b.tag_name,a.tag_img,a
- .tag_remark','b.type');
- if($value['inv_tag']==1){
- $value['inv_tag_name']=$tag[6]['tag_name']??'';
- $value['inv_tag_id']=$tag[6]['id']??'0';
- $value['inv_tag_img']=$tag[6]['tag_img']??'';
- $value['inv_tag_remark']=$tag[6]['tag_remark']??'';
- }
- if($value['pay_tag']==1){
- $value['pay_tag_id']=$tag[5]['id']??'0';
- $value['pay_tag_name']=$tag[5]['tag_name']??'';
- $value['pay_tag_img']=$tag[5]['tag_img']??'';
- $value['pay_tag_remark']=$tag[5]['tag_remark']??'';
- }
- }
-
- }
- return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
- }
- public function cgdQuery(){
- $post = $this->request->only(["cgdNoArr"=>[],"qrdNoArr"=>[],"status"=>"","cgd_status"=>"","is_comon"=>"","relaComNo"=>'',"companyNo"=>"","supplierNo"=>""],"post");
- $valid=Validate::rule([
- "cgdNoArr|采购单编号集合"=>"requireWithout:qrdNoArr|array",
- "qrdNoArr|销售单编号集合"=>"requireWithout:cgdNoArr|array",
- "status|采购单对账状态"=>"number|in:0,1,2,3",
- "cgd_status|采购单状态"=>"number|in:0,1,2,3,4",
- "is_comon|是否通用订单"=>"number|in:0,1",
- ]);
- if($valid->check($post)==false) return error_show(1004,$valid->getError());
- if(!empty($post['qrdNoArr'])){
- $cgdNo = Db::name("qrd_info")->where(["sequenceNo"=>$post['qrdNoArr']])->column("cgdNo");
- $post["cgdNoArr"]=array_merge($post["cgdNoArr"],$cgdNo);
- }
-
- $condition = [["cgdSource|cgdType","<>",1],['is_del',"=",0],["sequenceNo","in",$post["cgdNoArr"]]];
- $companyNo = isset($post['companyNo']) && $post['companyNo']!='' ? trim($post['companyNo']) :"";
- if($companyNo!=""){
- $condition []=["companyNo","=",$companyNo];
- }
- $Total=isset($post['total']) && $post['total'] != '' ? trim($post['total']) : '';
- if ($Total != '') {
- $condition []=[
- 'totalPrice' ,
- $Total == 1 ? '=' : '>' ,
- 0
- ];
- }
- if($post['cgd_status']!==''){
- $condition []=[
- 'cgd_status' ,
- '=' ,
- $post['cgd_status']
- ];
- }
- if(isset($post['is_comon'])&& $post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
- $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!=""){
- $condition[]=["companyNo|supplierNo","=",$relaComNo];
- }
- $supplierNo = isset($post['supplierNo']) && $post['supplierNo']!='' ? trim($post['supplierNo']) :"";
- if($supplierNo!=""){
- $condition []=["supplierNo","=",$supplierNo];
- }
- $status = isset($post['status']) && $post['status']!=='' ? intval($post['status']) :"";
- if($status!==''){
- if($status==3){
- $condition[]=["status","<>",2];
- }else{
- $condition[]=["status","=",$status];
- }
- }
- $list = Db::name("cgd_info")->where($condition)->order('createdTime desc')->select()->toArray();
- $payArr=Db::name('supplier_info')->whereIn('code',array_unique(array_column($list,'supplierNo')))->column('pay_method','code');
- foreach ($list as &$value){
- $value['pay_type']=$payArr[$value['supplierNo']]??'';
- $value['goodNum'] =$value['goodNum']- $value['thNum'];
- $value['sendNum'] =$value['sendNum']- $value['thNum'];
- $value['inv_tag_name']='';
- $value['pay_tag_name']='';
- $value['pay_tag_img']='';
- $value['inv_tag_id']='0';
- $value['pay_tag_id']='0';
- $value['pay_tag_remark']='';
- $value['inv_tag_img']='';
- $value['inv_tag_remark']='';
- if($value['pay_tag']==1 || $value['inv_tag']==1){
- $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
- (['code'=>$value['sequenceNo'],'a.status'=>[5,6]])->order('a.id desc')->column('a.id,b.tag_name,a.tag_img,a
- .tag_remark','b.type');
- if($value['inv_tag']==1){
- $value['inv_tag_name']=$tag[6]['tag_name']??'';
- $value['inv_tag_id']=$tag[6]['id']??'0';
- $value['inv_tag_img']=$tag[6]['tag_img']??'';
- $value['inv_tag_remark']=$tag[6]['tag_remark']??'';
- }
- if($value['pay_tag']==1){
- $value['pay_tag_id']=$tag[5]['id']??'0';
- $value['pay_tag_name']=$tag[5]['tag_name']??'';
- $value['pay_tag_img']=$tag[5]['tag_img']??'';
- $value['pay_tag_remark']=$tag[5]['tag_remark']??'';
- }
- }
- }
- return app_show(0,"获取成功",$list);
- }
- //采购单信息
- public function cgdinfo(){
- $post=$this->post;
- $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo']!='' ? trim($post['sequenceNo']) :"";
- if($sequenceNo==''){
- return error_show(1004,"参数 sequenceNo 不能为空");
- }
- $cgdinfo = Db::name("cgd_info")->where(["sequenceNo"=>$sequenceNo])->findOrEmpty();
- if(empty($cgdinfo)){
- return error_show(1004,"采购单信息未找到");
- }
- $cgdinfo['catInfo'] = json_decode($cgdinfo['catInfo'],true);
- $payinfo =Db::name("pay_info")->alias("a")->leftJoin("pay b","a.payNo=b.payNo")
- ->where(["a.is_del"=>0,"b.is_del"=>0,"a.cgdNo"=>$sequenceNo])->field("b.inv_status,b.pay_status,b.status")
- ->find();
- $cgdinfo['pay_type']=Db::name('supplier_info')->where('code',$cgdinfo['supplierNo'])->value('pay_method','');
- $cgdinfo["cgd_pay_status"]=$payinfo['pay_status']??1;
- $cgdinfo["cgd_inv_status"]=$payinfo['inv_status']??1;
- $cgdinfo["pay_status"]=$payinfo['status']??0;
- $cgdinfo['goodNum'] =$cgdinfo['goodNum']- $cgdinfo['thNum'];
- $cgdinfo['sendNum'] =$cgdinfo['sendNum']- $cgdinfo['thNum'];
- $cgdinfo['child']=[];
- $cgdinfo['orderTax']= OrderCategory::where(['code' => $cgdinfo['sequenceNo'], 'spuCode' => $cgdinfo['goodNo']])
- ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
- $list=(new GoodCombind())->where("spuCode",$cgdinfo['goodNo'])->visible(["child"])->with(["child"])
- ->select();
- if($list->isEmpty()==false){
- $cgdinfo['child']=array_column($list->toArray(),'child');
- foreach ($cgdinfo['child'] as &$value){
- $value['orderTax'] = OrderCategory::where(['code' => $cgdinfo['sequenceNo'], 'spuCode' => $value['spuCode']])
- ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
- }
- }
- $cgdinfo['inv_tag_name']='';
- $cgdinfo['pay_tag_name']='';
- $cgdinfo['pay_tag_img']='';
- $cgdinfo['inv_tag_id']='0';
- $cgdinfo['pay_tag_id']='0';
- $cgdinfo['pay_tag_remark']='';
- $cgdinfo['inv_tag_img']='';
- $cgdinfo['inv_tag_remark']='';
- if($cgdinfo['pay_tag']==1 || $cgdinfo['inv_tag']==1){
- $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
- (['code'=>$cgdinfo['sequenceNo'],'a.status'=>[5,6]])->order('a.id desc')->column('a.id,b.tag_name,a.tag_img,a
- .tag_remark','b.type');
- if($cgdinfo['inv_tag']==1){
- $cgdinfo['inv_tag_name']=$tag[6]['tag_name']??'';
- $cgdinfo['inv_tag_id']=$tag[6]['id']??'0';
- $cgdinfo['inv_tag_img']=$tag[6]['tag_img']??'';
- $cgdinfo['inv_tag_remark']=$tag[6]['tag_remark']??'';
- }
- if($cgdinfo['pay_tag']==1){
- $cgdinfo['pay_tag_id']=$tag[5]['id']??'0';
- $cgdinfo['pay_tag_name']=$tag[5]['tag_name']??'';
- $cgdinfo['pay_tag_img']=$tag[5]['tag_img']??'';
- $cgdinfo['pay_tag_remark']=$tag[5]['tag_remark']??'';
- }
- }
- return app_show(0,"获取成功",$cgdinfo);
- }
- //todo
- public function PayInfo()
- {
- $post = $this->post;
- $payNo =isset($post['payNo'])&&$post['payNo']!='' ? trim($post['payNo']):"";
- if($payNo==""){
- return error_show(1004,"参数 payNo 不能为空");
- }
- $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"对账单数据未找到");
- }
- if($payinfo['pay_type']==1){
- $pay =Db::name("pay_info")->alias("a")->leftJoin("cgd_info b","a.cgdNo=b.sequenceNo")
- ->where(["a.is_del"=>0,"b.is_del"=>0,"a.payNo"=>$payNo])->field("b.*")
- ->select()->toArray();
- foreach ($pay as &$value){
- $value['orderTax'] = OrderCategory::where(["code"=>$value['sequenceNo'],"spuCode"=>$value['goodNo']])
- ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
- $value['catInfo'] = json_decode($value['catInfo'],true);
- $value['goodNum'] =$value['goodNum']- $value['thNum'];
- $value['sendNum'] =$value['sendNum']- $value['thNum'];
- if($payinfo['is_comon']==1){
- $value['qrdCode'] = (new \app\admin\model\ComonOrder())->where(['cgdNo'=>$value['sequenceNo']])->value("orderCode",'');
- }
- }
- }else{
- $pay =Db::name('pay_info')->alias('a')
- ->leftJoin('track b','a.cgdNo=b.TrackCode')
- ->leftJoin('fhd_child c','b.outChildCode=c.outChildCode')
- ->where(['a.is_del'=>0,"a.status"=>1,'a.payNo'=>$payNo])
- ->field('b.*,c.outCode,c.good_name,c.spuCode,c.post_name,c.post_code')
- ->select()->toArray();
- }
- $payinfo['pay_type']=Db::name('supplier_info')->where('code',$payinfo['supplierNo'])->value('pay_method','');
- $payinfo['inv_tag_name']='';
- $payinfo['pay_tag_name']='';
- $payinfo['pay_tag_img']='';
- $payinfo['inv_tag_id']='0';
- $payinfo['pay_tag_id']='0';
- $payinfo['pay_tag_remark']='';
- $payinfo['inv_tag_img']='';
- $payinfo['inv_tag_remark']='';
- if($payinfo['pay_tag']==1 || $payinfo['inv_tag']==1){
- $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
- (['code'=>$payNo,"a.status"=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a
- .tag_remark','b.type');
- if($payinfo['inv_tag']==1){
- $payinfo['inv_tag_name']=$tag[2]['tag_name']??'';
- $payinfo['inv_tag_id']=$tag[2]['id']??'0';
- $payinfo['inv_tag_img']=$tag[2]['tag_img']??'';
- $payinfo['inv_tag_remark']=$tag[2]['tag_remark']??'';
- }
- if($payinfo['pay_tag']==1){
- $payinfo['pay_tag_id']=$tag[1]['id']??'0';
- $payinfo['pay_tag_name']=$tag[1]['tag_name']??'';
- $payinfo['pay_tag_img']=$tag[1]['tag_img']??'';
- $payinfo['pay_tag_remark']=$tag[1]['tag_remark']??'';
- }
- }
- $payinfo['cgdlist'] = $pay;
- return app_show(0,"获取成功",$payinfo);
- }
- public function DzInfo()
- {
- $post = $this->post;
- $DzNo =isset($post['DzNo'])&&$post['DzNo']!='' ? trim($post['DzNo']):"";
- if($DzNo==""){
- return error_show(1004,"参数 DzNo 不能为空");
- }
- $payinfo =Db::name("pay_payment")->where(["dzNo"=>$DzNo,"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"对账单付款申请数据未找到");
- }
- $pay =Db::name("pay")->where(["payNo"=>$payinfo['payNo'],"is_del"=>0])->find();
- if($pay==false){
- return error_show(1004,"对账单数据未找到");
- }
- $payinfo['pay_apply_id'] = $pay['apply_id']??'';
- $payinfo['pay_apply_name'] = $pay['apply_name']??'';
- $payinfo['supplierNo'] = $pay['supplierNo']??'';
- $payinfo['supplierName'] = $pay['supplierName']??'';
- $payinfo['companyNo'] = $pay['companyNo']??'';
- $payinfo['companyName'] = $pay['companyName']??'';
- $payinfo['total_fee'] = $pay['total_fee']??'';
- return app_show(0,"获取成功",$payinfo);
- }
- /**发票新建添加
- * @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 invAdd(){
- $post = $this->post;
- $payNo = isset($post['payNo'])&&$post['payNo']!='' ? $post['payNo']:"";
- if($payNo==""){
- return error_show(1004,"参数 payNo 不能为空");
- }
- $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"对账单数据未找到");
- }
- if($payinfo['winv_fee']<=0) return error_show(1004,"对账单数据未开票金额为0");
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
- if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- // $result=$this->checkSupplier($payinfo['supplierNo']);
- // if($result['code']!=0){
- // return error_show($result['code'],$result['message']);
- // }
- if($payinfo['status']!=2){
- return error_show(1004,"对账单数据未完成审核");
- }
- $invArr=isset($post['invArr']) && !empty($post['invArr']) ? $post['invArr'] :'';
- if($invArr==''|| empty($invArr)){
- return error_show(1004,"参数 invArr 不能为空");
- }
- $daList=[];
- foreach ($invArr as $item){
- if(!isset($item['invType'])||$item['invType']=='') return error_show(1004,"参数 invType 不能为空");
- // if(in_array($item['invoiceType'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic']) && $item['invType']!=1){
- // return error_show(1004,"全电发票暂不支持图片识别");
- // }
- if($item['invType']==1){
- if(!isset($item['invoiceType'])||$item['invoiceType']=='') return error_show(1004,"参数 invoiceType 不能为空");
- if (!in_array($item['invoiceType'],$this->invName)) return error_show(1004,"发票类型有误");
- //全电票没有发票代码
- if(!in_array($item['invoiceType'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
- if(!isset($item['invCode'])||$item['invCode']=='') return error_show(1004,"参数 invCode 不能为空");
- }
- if(!isset($item['invNumber'])||$item['invNumber']=='') return error_show(1004,"参数 invNumber 不能为空");
- if(!isset($item['invoiceType'])||$item['invoiceType']=='') return error_show(1004,"参数 invoiceType 不能为空");
- if(!isset($item['open_time'])||$item['open_time']=='') return error_show(1004,"参数 open_time 不能为空");
- if(!isset($item['subtotal_amount'])||$item['subtotal_amount']=='') return error_show(1004,"参数 subtotal_amount 不能为空");
- $invamount=0;
- if(in_array($item['invoiceType'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
- $invamount = $item['subtotal_amount']??0;
- $item['subtotal_amount']=0;
- }
- //普票需要校验码
- if(in_array($item['invoiceType'],['normal','roll',"toll",'electronic'])){
- if(!isset($item['checkNumber'])||$item['checkNumber']=='') return error_show(1004,"参数 checkNumber 不能为空");
- }
- }
- if($item['invType']==2){
- if(!isset($item['inv_img'])||$item['inv_img']=='') return error_show(1004,"参数 inv_img 不能为空");
- if(!isset($item['invName'])||$item['invName']=='') return error_show(1004,"参数 invName 不能为空");
- }
- if($item['invType']==3){
- if(!isset($item['inv_img'])||$item['inv_img']=='') return error_show(1004,"参数 inv_img 不能为空");
- if(!isset($item['invName'])||$item['invName']=='') return error_show(1004,"参数 invName 不能为空");
- }
- $hpNo=makeNo("hp");
- $data=[
- "payNo"=>$payNo,
- "hpNo"=>$hpNo,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "inv_fee"=> 0,//核算金额
- "inv_subtotal_amount"=> $item['subtotal_amount']??0, //票面金额
- "inv_amount"=> $invamount, //票面金额
- "invType"=> $item['invType'],
- "invoiceType"=>$item['invoiceType']??"",
- "inv_img"=>$item['inv_img']??'',
- "invName"=>$item['invName']??'',
- "invoiceNumber"=>$item['invNumber']??'',
- "invoiceCode"=>$item['invCode']??'',
- "status"=>$item['invType']==2 ?0:1,
- "checkNumber"=>$item['checkNumber']??'',
- "open_time"=>isset($item['open_time'])&&$item['open_time']!=''? date("Y-m-d",strtotime($item['open_time'])):'',
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $daList[]=$data;
- }
- if(empty($daList)) return error_show(1004,"录入数据不能为空");
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- Db::startTrans();
- try{
- $inadd =Db::name("pay_invoice")->insertAll($daList);
- if ($inadd){
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->setField("hpNo",$hpNo);
- }
- Db::commit();
- return app_show(0,"回票新建成功");
- }
- Db::rollback();
- return error_show(1004,"回票申请新建失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- //批量添加发票信息
- public function invAddBatchByImport()
- {
- try {
- $param = $this->request->only(['list', 'companyNo', 'is_comon'], 'post', 'trim');
- $validate = Validate::rule([
- 'list' => 'require|array|max:100',
- 'companyNo|卖出方公司编号' => 'require|max:255|checkCompanyNo:',
- 'is_comon|是否通用对账' => 'require|number|in:0,1',
- ]);
- $validate->extend('checkCompanyNo', function ($val, $rule, $da) {
- $tmp = Db::name('user_role')
- ->field('id,status')
- ->where(['is_del' => 0, 'uid' => $this->uid, 'companyNo' => $val])
- ->findOrEmpty();
- if (empty($tmp)) return '账号尚未绑定当前公司';
- if ($tmp['status'] == 0) return '当前公司已禁用';
- return true;
- });
- if (!$validate->check($param)) throw new Exception($validate->getError());
- $val = Validate::rule([
- 'payNo|对账编号' => 'require|max:255',
- 'invoiceType|发票类型' => 'require|in:' . implode(',', array_values($this->invName)),
- 'invoiceCode|发票代码' => 'max:255|checkInvoiceCode:',
- 'invoiceNumber|发票号码' => 'require|max:255',
- 'inv_subtotal_amount|发票税前金额' => 'require|float|max:9999999.99',
- 'open_time|开票日期' => 'require|date',
- 'checkNumber|校验码' => 'checkNumberCallback:',
- ]);
- $val->extend('checkNumberCallback', function ($val, $rule, $da) {
-
- if (in_array($da['invoiceType'], ['special', 'normal', 'roll', 'special_electronic', 'electronic', 'toll'])) {
- if (empty($val)) return '电子票时校验码必填';
- }
- return true;
- });
- $val->extend('checkInvoiceCode', function ($val, $rule, $da) {
- if (in_array($da['invoiceType'], ['special', 'normal', 'roll', 'special_electronic', 'electronic', 'toll'])) {
- if (empty($val)) return '发票代码必填';
- }
- return true;
- });
- //所有的payNo(对账编码)
- $payNo = array_column($param['list'], 'payNo');
- $payinfo = Db::name('pay')
- ->where('is_del', 0)
- ->whereIn('payNo', $payNo)
- ->column('id,payNo,supplierNo,supplierName,status,is_comon', 'payNo');
- $Supp=[];
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $suppArr=array_unique(array_column($payinfo,'supplierNo'));
- $temp = check_has_account_by_supplierNos(array_unique(array_column($payinfo,"supplierNo")));
- $Supp = $temp['data']??[];
- }
- //$da_insert 批量新增的数据,$payNo_hpNo对账编码=>回票编码
- $da_insert = $payNo_hpNo = [];
- $date = date('Y-m-d H:i:s');
- $unique=[];
- $diesa=[];
- foreach ($param['list'] as $item) {
- if (!$val->check($item)) throw new Exception($val->getError());
- if(in_array($item['invoiceNumber'],$unique))throw new Exception("{$item['invoiceNumber']} 发票重复提交");
- $unique[]=$item['invoiceNumber'];
- if (!isset($payinfo[$item['payNo']])) throw new Exception('对账单数据未找到');
- if ($payinfo[$item['payNo']]['status'] != 2) throw new Exception('对账单数据未完成审核');
- if($payinfo[$item['payNo']]['is_comon'] != $param['is_comon']){
- $diesa[]=$item['payNo'];
- }
- if ($this->level == 2) {
- if ( isset($Supp[$payinfo[$item['payNo']]['supplierNo']])) throw new Exception("该供应商{$payinfo[$item['payNo']]['supplierName']}已经开通账号,不允许当前账号操作");
- }
- $invamount=0;
- if(in_array($item['invoiceType'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
- $invamount = $item['inv_subtotal_amount']??0;
- $item['inv_subtotal_amount']=0;
- }
- $hpNo = makeNo('hp');
- $da_insert[] = [
- 'payNo' => $item['payNo'],
- 'hpNo' => $hpNo,
- 'apply_id' => $this->uid,
- 'apply_name' => $this->uname,
- 'inv_fee' => 0,//核算金额
- 'inv_subtotal_amount' => $item['inv_subtotal_amount'] ?? 0, //票面金额
- 'inv_amount' => $invamount, //票面金额
- 'invType' => 1,
- 'invoiceType' => $item['invoiceType'],
- 'inv_img' => '',
- 'invName' => '',
- 'invoiceNumber' => $item['invoiceNumber'],
- 'invoiceCode' => $item['invoiceCode'],
- 'status' => 1,
- 'checkNumber' => $item['checkNumber'],
- 'open_time' => date('Y-m-d', strtotime($item['open_time'])),
- 'addtime' => $date,
- 'updatetime' => $date
- ];
- $payNo_hpNo[$item['payNo']] = $hpNo;
- }
- if(empty($diesa)==false){
- $this->error("对账单不符合对账要求",10004,$diesa);
- }
- $cgdNo = Db::name('pay_info')
- ->where('is_del', 0)
- ->whereIn('payNo', $payNo)
- ->column('cgdNo', 'payNo');
- if (empty($cgdNo)) throw new Exception('未找到对账数据信息');
- Db::startTrans();
- try {
- Db::name('pay_invoice')->insertAll($da_insert);
- foreach ($cgdNo as $payNoTmp => $cgdNoTmp) {
- Db::name('report_code')
- ->where('cgdNo', $cgdNoTmp)
- ->update(['hpNo' => $payNo_hpNo[$payNoTmp]]);
- }
- Db::commit();
- return app_show(0, '回票新建成功');
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1004, '回票新建失败,' . $e->getMessage());
- }
- } catch (Exception $exception) {
- return error_show(1005, $exception->getMessage());
- }
- }
- /**
- * 发票审核状态 //发票验证通过 才会扣减待开票金额 失败的开票申请不用处理
- * // 1待系统验证 2 买方公司审核 3带买方公司认证 4 认证成功 5验证失败 6买方审核驳回 7 认证失败 8 回票流程终止 9 验证超次数 10 回票已退
- * 11 待关联订单 12 订单关联完毕待财务审核 13 订单关联完毕财务驳回
- * @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 invStatus(){
- $param = $this->request->param(["hpNo"=>"","status"=>"","remark"=>"","ItemRemark"=>[]],"post","trim");
- $valid = Validate::rule(["hpNo|回票申请编号"=>"require|max:255","status"=>"require|number|in:1,2,3,4,6,7,8,13"]);
- if(!$valid->check($param))$this->error($valid->getError());
- $info = PayInvoice::where(["hpNo"=>$param['hpNo'],"is_del"=>0])->findOrEmpty();
- if ($info->isEmpty())$this->error("未找到回票申请信息");
- $payinfo = Pay::where(['payNo'=>$info['payNo'],"is_del"=>0])->findOrEmpty();
- if ($payinfo->isEmpty())$this->error("未找到对账单信息");
- if($payinfo['status']!=2&&$param['status']==3)$this->error("对账信息未完成审核");
- if($payinfo['inv_fee']< $info['inv_fee']) $this->error("回票金额不能大于对账单回票金额");
- $invup =['remark'=>$param['remark'],'updatetime'=>date('Y-m-d H:i:s')];
- if($param['status']==3) $invup['check_time']=date("Y-m-d H:i:s");
- if(in_array($info['invoiceType'],['normal','electronic','toll','roll']) && $param['status']==3){
- $param['status']=4; //普票无需认证
- }
- $invup['status']=$param['status'];
- Db::startTrans();
- try {
- $save=$info->save($invup);
- if($save){
- if($param['status']==4){
- Pay::addAinv($info['payNo'],$info->inv_fee);
- }
- if($param['status']==3){
- if (!empty($param['ItemRemark'])){
- (new InvoiceOrder)->saveAll($param['ItemRemark']);
- };
- }
- if(in_array($param['status'],[5,6,7,8,13])){
- Pay::subInv($info['payNo'],$info->inv_fee);
- if($param['status']==13||$param['status']==7)\app\admin\model\InvoiceItem::rmInvoice($param['hpNo']);
- event("reportCode",["param"=>["key"=>"hpNo","value"=>$param['hpNo']],"type"=>"sub"]);
- }
- }else throw new \Exception("回票审核失败");
- Db::commit();
-
- }catch (\Exception $e){
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success("回票审核成功");
- }
- // public function invStatus(){
- // $post = $this->post;
- // $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? trim($post['hpNo']) :"";
- // if($hpNo==""){
- // return error_show(1004,"参数 hpNo 不能为空");
- // }
- // $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
- // if($status==""){
- // return error_show(1004,"参数status 不能为空");
- // }
- //// if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){
- //// return error_show(1004,"参数status 无效值");
- //// }
- // if(!in_array($status,[0,1,2,3,4,5,6,7])){
- // return error_show(1004,"参数status 无效值");
- // }
- // $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find();
- //
- // if($payment==false){
- // return error_show(1005,"未找到回票申请信息");
- // }
- // $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
- //
- // if($payinfo==false){
- // return error_show(1005,"未找到对账信息");
- // }
- // if($payinfo['status']!=2){
- // return error_show(1005,"对账信息未完成审核");
- // }
- // $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
- // if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- // if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
- // $remark = $post['remark']??'';
- // Db::startTrans();
- // try {
- // Db::name('pay_invoice')->where([['hpNo','=',$hpNo],['is_del','=',0]])->lock(true)->find();
- // $invup =["remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
- // if($status==3) $invup['check_time']=date("Y-m-d H:i:s");
- // if(in_array($payment['invoiceType'],['normal','electronic','toll','roll']) && $status==3){
- // $status=4; //普票无需认证
- // }
- // $invup['status']=$status;
- // $inv =Db::name("pay_invoice")->where($payment)->update($invup);
- // if($inv){
- // if($status==4){
- // $payupdate =[
- // "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'],
- // "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
- // "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2,
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $pay =Db::name("pay")->where($payinfo)->update($payupdate);
- // if($pay==false){
- // Db::rollback();
- // return error_show(1003,"回票申请状态更新失败");
- // }
- // }
- // if($status==6 || $status==5|| $status==7){
- // $payupdate =[
- // "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'],
- // "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
- // "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2,
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $pay =Db::name("pay")->where($payinfo)->update($payupdate);
- // if($pay==false){
- // Db::rollback();
- // return error_show(1003,"回票申请状态更新失败");
- // }
- // foreach ($cgdNo as $value){
- // $report=ReportCode::where(["cgdNo"=>$value])->find();
- // if($report)$report->rmField("hpNo",$hpNo);
- // }
- // }
- // Db::commit();
- // return app_show(0,"回票申请更新成功");
- // }throw new \Exception("回票申请状态更新失败");
- // }catch (\Exception $e){
- // Db::rollback();
- // return error_show(1004,$e->getMessage());
- // }
- //
- // }
- /**发票列表识别
- * @param int $id
- * @return \think\Response
- */
- public function InvList()
- {
- $post = $this->post;
- $condition = [["a.is_del","=",0 ],['a.invType','<>',4 ],["b.is_del","=",0 ],['pay_type','=',$post['pay_type']??1]];
- $invtype = isset($post['invType'])&&$post['invType']!='' ? intval($post['invType']):"";
- $check = checkRole($this->roleid,[82,120]);
- if($check){
- $condition []=["a.apply_id","=",$this->uid];
- }
- if ($invtype!=''){
- $condition[]=["a.invType","=",$invtype];
- }
-
- $companyNo = isset($post['companyNo'])&&$post['companyNo']!='' ? trim($post['companyNo']):"";
- if($companyNo!=""){
- $condition[]=["b.companyNo","=",$companyNo];
- }
- $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
- if($relaComNo!=""){
- $condition[]=["b.companyNo|b.supplierNo","=",$relaComNo];
- }
- $supplierNo = isset($post['supplierNo'])&&$post['supplierNo']!='' ? trim($post['supplierNo']):"";
- if($supplierNo!=""){
- $condition[]=["b.supplierNo","=",$supplierNo];
- }
- $hpNo = isset($post['hpNo'])&&$post['hpNo']!='' ? trim($post['hpNo']):"";
- if ($hpNo!=''){
- $condition[]=["a.hpNo","like","%$hpNo%"];
- }
- $payNo = isset($post['payNo'])&&$post['payNo']!='' ? trim($post['payNo']):"";
- if ($payNo!=''){
- $condition[]=["a.payNo","like","%$payNo%"];
- }
- $invoiceType = isset($post['invoiceType'])&&$post['invoiceType']!='' ? intval($post['invoiceType']):"";
- if ($invoiceType!=''){
- $condition[]=["a.invoiceType","=",$invoiceType];
- }
- $status = isset($post['status'])&&$post['status']!=="" ? intval($post['status']):"";
- if($status!==""){
- $condition[]=["a.status","=",$status];
- }
- $invNumber = isset($post['invNumber'])&&$post['invNumber']!="" ? trim($post['invNumber']):"";
- if($invNumber!=''){
- $condition[]=["invoiceNumber","=",$invNumber];
- }
- $checkApi = isset($post['checkApi'])&&$post['checkApi']!="" ? intval($post['checkApi']):"";
- if($checkApi!==''){
- $condition[]=["checkApi","=",$checkApi];
- }
- $invCode = isset($post['invCode'])&&$post['invCode']!="" ? trim($post['invCode']):"";
- if($invCode!=''){
- $condition[]=["invoiceCode","=",$invCode];
- }
- $start = isset($post['start']) && $post['start']!="" ? $post['start'] :"";
- if($start!=""){
- $condition[]=["a.addtime",">=",$start." 00:00:00"];
- }
- $end = isset($post['end']) && $post['end']!="" ? $post['end'] :"";
- if($end!=""){
- $condition[]=["a.addtime","<=",$end." 23:59:59"];
- }
- $open_start = isset($post['open_start']) && $post['open_start']!="" ? $post['open_start'] :"";
- if($open_start!=""){
- $condition[]=["a.open_time",">=",$open_start];
- }
- $open_end = isset($post['open_end']) && $post['open_end']!="" ? $post['open_end'] :"";
- if($open_end!=""){
- $condition[]=["a.open_time","<=",$open_end];
- }
- $apply_id = isset($post['apply_id']) && $post['apply_id']!="" ? $post['apply_id'] :"";
- if($apply_id!=""){
- $condition[]=["a.apply_id","=",$apply_id];
- }
- $apply_name = isset($post['apply_name']) && $post['apply_name']!="" ? trim($post['apply_name']):"";
- if($apply_name!=""){
- $condition[]=["a.apply_name","like","%$apply_name%"];
- }
- if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
- $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']):1;
- $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']):10;
- $count =Db::name("pay_invoice")
- ->alias("a")
- ->leftJoin("pay b","a.payNo=b.payNo")
- ->where($condition)
- ->count();
- $total = ceil($count/$size);
- $page = $page>$total? intval($total):$page;
- $list = Db::name("pay_invoice")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo")
- ->field("a.*,b.supplierNo,b.supplierName,b.companyName,b.is_comon,b.companyNo")
- ->where($condition)
- ->page($page,$size)
- ->order("addtime desc")
- ->select()
- ->toArray();
- //校验是否开通了供应商账号
- $supp_account = check_has_account_by_supplierNos(array_unique(array_column($list,'supplierNo')));
- $inv_fee=$inv_subtotal_amount = $total = 0;
- foreach ($list as &$value){
- $invoinfo =InvoiceInfo::where(["hpNo"=>$value['hpNo'],"status"=>1])->find();
- $value['buyer_name'] = $invoinfo['buyer_name']??"";
- $value['buyer_id'] = $invoinfo['buyer_id']??"";
- $value['buyer_address'] = $invoinfo['buyer_address']??"";
- $value['buyer_bank'] = $invoinfo['buyer_bank']??"";
- $value['seller_name'] = $invoinfo['seller_name']??"";
- $value['seller_id'] = $invoinfo['seller_id']??"";
- $value['seller_address'] = $invoinfo['seller_address']??"";
- $value['seller_bank'] = $invoinfo['seller_bank']??"";
- $value['subtotal_amount'] = $invoinfo['subtotal_amount']??"";
- $value['subtotal_tax'] = $invoinfo['subtotal_tax']??"";
- $value['total'] = $invoinfo['total']??"";
- $value['receiver'] = $invoinfo['receiver']??"";
- $value['issuer'] = $invoinfo['issuer']??"";
- $value['reivewer'] = $invoinfo['reivewer']??"";
- $value['remarks'] = $invoinfo['remarks']??"";
- $value['invoiceType_cn'] = $this->invoiceType[$value['invoiceType']]??'';
- $value['invStatus_cn'] = $this->invStatus[$value['invStatus']]??'';
- $value['item_list'] = $invoinfo['item_list']??[];
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- if($value['status']==4){
- $inv_fee += $value['inv_fee'];
- $inv_subtotal_amount += intval($value['inv_subtotal_amount']??0);
- $total += intval($value['total']??0);
- }
- }
- //结算invlist这个接口当用payNo筛选的时候,返回列表里需要加一项统计筛选后列表的inv_subtotal_amount、total字段的和
- // $inv_fee=$inv_subtotal_amount = $total = 0;
- // if ($payNo != '') {
- // $inv_subtotal_amount = round(array_sum(array_column($list, 'inv_subtotal_amount')), 2);
- // $total = round(array_sum(array_column($list, 'total')), 2);
- // }
- return app_show(0, "获取成功", [
- "count" => $count,
- "list" => $list,
- 'inv_subtotal_amount' => $inv_subtotal_amount,
- 'total' => $total,
- "inv_fee"=>$inv_fee
- ]);
- }
- /**发票删除
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function invDel(){
- $post = $this->post;
- $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :"";
- if ($hpNo==""){
- return error_show(1004,"参数 hpNo 不能为空");
- }
- $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find();
- if($payinv==false){
- return error_show(1004,"对账单回票申请未找到数据");
- }
- $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find();
- if($payinfo==false){
- return error_show(1005,"未找到对账信息");
- }
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
- if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- if($payinfo['status']!=2){
- return error_show(1005,"对账信息未完成审核");
- }
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payinv['payNo'],"is_del"=>0])->column("cgdNo");
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
- Db::startTrans();
- try{
- $update=["status"=>8,"updatetime"=>date("Y-m-d H:i:s")]; //删除状态 流程终止
- $invup =Db::name("pay_invoice")->where($payinv)->update($update);
- if($invup){
- if($payinv['status']==4){
- if($payinfo['ainv_fee']< $payinv['inv_fee']){
- Db::rollback();
- return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
- }
- $payupdate =[
- "ainv_fee"=>$payinfo['ainv_fee']-$payinv['inv_fee'],
- "winv_fee"=>$payinfo['winv_fee']+$payinv['inv_fee'],
- "inv_status" => ($payinfo['ainv_fee']-$payinv['inv_fee'])==0?1:2,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $pay =Db::name("pay")->where($payinfo)->update($payupdate);
- if($pay==false){
- Db::rollback();
- return error_show(1003,"删除失败");
- }
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("hpNo",$hpNo);
- }
- }
- if(in_array($payinv['status'], [1,2,3,11,12])){
- if($payinfo['inv_fee']< $payinv['inv_fee']){
- Db::rollback();
- return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
- }
- Pay::subInv($payinfo['payNo'],$payinv['inv_fee']);
- if(in_array($payinv['status'], [2,3,12])) \app\admin\model\InvoiceItem::rmInvoice($param['hpNo']);
- foreach ($cgdNo as $value){
- $report=ReportCode::where(["cgdNo"=>$value])->find();
- if($report)$report->rmField("hpNo",$hpNo);
- }
- }
- Db::commit();
- return app_show(0,"删除成功");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1003,$e->getMessage());
- }
- }
- public function HpInfo(){
- $post = $this->post;
- $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :"";
- if ($hpNo==""){
- return error_show(1004,"参数 hpNo 不能为空");
- }
- $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find();
- if($payinv==false){
- return error_show(1004,"对账单回票申请未找到数据");
- }
- $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find();
- if($payinfo==false){
- return error_show(1005,"未找到对账信息");
- }
- $payinv['pay_apply_id'] = $payinfo['apply_id']??'';
- $payinv['pay_apply_name'] = $payinfo['apply_name']??'';
- $payinv['supplierNo'] = $payinfo['supplierNo']??'';
- $payinv['supplierName'] = $payinfo['supplierName']??'';
- $payinv['companyNo'] = $payinfo['companyNo']??'';
- $payinv['companyName'] = $payinfo['companyName']??'';
- $payinv['total_fee'] = $payinfo['total_fee']??'';
- $invinfo =InvoiceInfo::where(["hpNo"=>$hpNo])->findOrEmpty();
- $payinv['invoiceType_cn'] = $this->invoiceType[$payinv['invoiceType']]??'';
- $payinv['invStatus_cn'] = $this->invStatus[$payinv['invStatus']]??'';
- $payinv["info"]=$invinfo;
- return app_show(0,'获取成功',$payinv);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DbException
- */
- public function UnPay(){
- $post = $this->post;
- $codeNo = isset($post['id'])&&$post['id']!=="" ? trim($post['id']) :'';
- if($codeNo===""){
- return error_show(1004,'参数 id 不能为空');
- }
- $update = Db::name('cgd_info')->where("id","in",$codeNo)->update(['status'=>2,"updatetime"=>date("Y-m-d H:i:s")]);
- if($update){
- return app_show(0,'更新成功');
- }else{
- return error_show(1004,'更新失败');
- }
- }
- /**
- * @return \think\|\think\response\Json|void
- */
- public function ticketInfo(){
- $num =isset($this->post['number'])&&$this->post['number']!=''?trim($this->post['number']):"";
- if($num==''){
- return error_show(1004,'参数 number 不能为空');
- }
- $condition=[];
- $condition[]=["number","=",$num];
- $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
- if($invNo!=='')$condition[]=["hpNo","=",$invNo];
- $info =InvoiceInfo::where($condition)->findOrEmpty();
- return empty($info)?error_show(1005,"为找到数据"):app_show(0,"获取成功",$info);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function hpinvList(){
- $post=$this->request->only(["hpNo"=>"","page"=>1,"size"=>15],"post","trim");
- $where=[];
- if($post["hpNo"]!="") $where[]=["hpNo","=",$post['hpNo']];
- $count=InvoiceInfo::where($where)->count();
- $total =ceil($count/$post['size']);
- $page= $post['page']>$total ? intval($total):intval($post['page']);
- $list = InvoiceInfo::where($where)
- ->page($page,intval($post['size']))
- ->order("id desc")
- ->select()->toArray();
- foreach ($list as &$value){
- $value['type_name'] = $this->invoiceType[$value['type']]??"";
- }
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function hpinvReturn(){
- $param =$this->request->only(["hpNo"=>"","reason"=>""],"post","trim");
- $valide=Validate::rule([
- "hpNo|回票编号"=>"require|max:255",
- "reason|申请原因"=>"require|max:255"
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $hpinfo =Db::name("pay_invoice")->where([["hpNo","=",$param['hpNo']],["is_del","=",0]])->findOrEmpty();
- if(empty($hpinfo)) return error_show(1004,"回票信息未找到");
- $payinfo =Db::name("pay")->where(["payNo"=>$hpinfo['payNo'],"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"对账单数据未找到");
- }
- if ($this->level == 2) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
- if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- if($hpinfo['status']!=4)return error_show(1004,"回票信息流程未完成");
- $isR=Db::name("pay_return")->where(["orderCode"=>$param['hpNo'],"status"=>[1,2],"is_del"=>0])->findOrEmpty();
- if(!empty($isR))return error_show(1004,"回票信息退票流程已存在");
- $returnCode =makeNo("RP");
- $data = [
- "returnCode"=>$returnCode,
- "returnType"=>1,
- "payNo"=>$hpinfo['payNo'],
- "orderCode"=>$param['hpNo'],
- "reason"=>$param['reason'],
- "returnImg"=>'',
- "remark"=>'',
- "status"=>1,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $insert=Db::name("pay_return")->insert($data);
- if($insert){
- return app_show(0,"退票申请新建成功",$returnCode);
- }else{
- return error_show(1004,"退票申请新建失败");
- }
- }
- public function hpinvReturnList(){
- $param =$this->request->only(["relaComNo"=>"","companyNo"=>"","supplierNo"=>"","start"=>"","end"=>"","returnCode"=>"",
- "status"=>"","hpNo"=>"","is_comon"=>"","payNo"=>"","pay_type"=>"","page"=>1,"size"=>15],"post","trim");
- $condition=[["a.is_del","=",0],['a.returnType',"=",1],['pay_type','=',$param['pay_type']?:1]];
- $check = checkRole($this->roleid,[132,130]);
- if($check){
- $condition []=["a.apply_id","=",$this->uid];
- }
- if($param['relaComNo']!="") $condition[]=["b.companyNo|b.supplierNo","=",$param['relaComNo']];
- if($param['companyNo']!="") $condition[]=["b.companyNo","=",$param['companyNo']];
- if($param['supplierNo']!="") $condition[]=["b.supplierNo","=",$param['supplierNo']];
- if($param['start']!="") $condition[]=["a.addtime",">=",date("Y-m-d H:i:s",strtotime($param['start']))];
- if($param['end']!="") $condition[]=["a.addtime","<=",date("Y-m-d 23:59:59",strtotime($param['end']))];
- if($param['status']!="") $condition[]=["a.status","=",$param['status']];
- if($param['is_comon']!="") $condition[]=["b.is_comon","=",$param['is_comon']];
- if($param['hpNo']!="") $condition[]=["a.orderCode","like","%{$param['hpNo']}%"];
- if($param['returnCode']!="") $condition[]=["a.returnCode","like","%{$param['returnCode']}%"];
- if($param['payNo']!="") $condition[]=["a.payNo","like","%{$param['payNo']}%"];
- if(isset($param['is_comon'])&&$param['is_comon']!=='') $condition []=['is_comon','=',$param['is_comon']];
- $count = Db::name("pay_return")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_invoice c", "a.orderCode=c.hpNo")
- ->where($condition)
- ->count();
- $total = ceil($count / $param['size']);
- $page = $param['page'] >= $total ? intval($total) : intval($param['page']);
- $list = Db::name("pay_return")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_invoice c", "a.orderCode=c.hpNo")
- ->where($condition)
- ->page($page, intval($param['size']))
- ->order('id desc')
- ->field("a.*,b.is_comon,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.ainv_fee,b.winv_fee,b.inv_fee,c.inv_fee pay_inv_fee")
- ->select()
- ->toArray();
- //校验是否开通了供应商账号
- $supp_account = check_has_account_by_supplierNos(array_unique(array_column($list, 'supplierNo')));
- foreach ($list as &$value) {
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- $value['inv_number']= \app\admin\model\InvoiceInfo::where(["hpNo"=>$value['orderCode']])->value("number",'');
- }
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function hpinvReturnStatus(){
- $param =$this->request->only(["returnCode"=>"","status"=>"","remark"=>"","returnImg"=>""],"post","trim");
- $valide=Validate::rule([
- "returnCode|退票申请编号"=>"require|max:255",
- "status|状态"=>"require|number|in:1,2,3",
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $returninfo =Db::name("pay_return")->where(["is_del"=>0,"returnCode"=>$param['returnCode']])->findOrEmpty();
- if(empty($returninfo))return error_show(1004,"退票详情未找到");
- Db::startTrans();
- try{
- $update=[
- "status"=>$param['status'],
- "remark"=>$param['remark'],
- "returnImg"=>$param['returnImg'],
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $up =Db::name("pay_return")->where($returninfo)->update($update);
- if($up==false)throw new Exception("退票申请审核失败");
- if($param['status']==2){
- $invinfo =Db::name('pay_invoice')->where(['hpNo'=>$returninfo['orderCode'],'is_del'=>0])->findOrEmpty();
- if(empty($invinfo))throw new Exception('回票详情未找到');
- $pay =Db::name('pay')->where(['payNo'=>$returninfo['payNo'],'is_del'=>0])->findOrEmpty();
- if(empty($pay))throw new Exception('对账详情未找到');
- $invup =Db::name('pay_invoice')->where($invinfo)->update(['status'=>10,'updatetime'=>date('Y-m-d H:i:s')]);
- if($invup==false)throw new Exception('回票更新失败');
- Pay::subAinv($returninfo['payNo'],$invinfo['inv_fee']);
- \app\admin\model\InvoiceItem::rmInvoice($returninfo['orderCode'],2);
- }
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- $this->success("退票申请审核成功");
- }
- public function hpinvReturnInfo(){
- $param = $this->request->only(["returnCode"=>""],"post","trim");
- $valide=Validate::rule([
- "returnCode|退票申请编号"=>"require|max:255",
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $info = Db::name("pay_return")->alias("a")
- ->leftJoin("pay b","a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_invoice c","a.orderCode=c.hpNo")
- ->where(['returnCode'=>$param['returnCode']])
- ->field("a.*,b.supplierNo,b.supplierName,b.companyNo,b.companyName,c.check_remark,b.total_fee,b.ainv_fee,b.winv_fee,b.inv_fee,c.inv_fee pay_inv_fee")
- ->findOrEmpty();
- return app_show(0,"退票申请获取成功",$info);
- }
- //付款退回
- public function stageReturn(){
- $param =$this->request->only(["dzNo"=>"","reason"=>""],"post","trim");
- $valide=Validate::rule([
- "dzNo|付款编号"=>"require|max:255",
- "reason|申请原因"=>"require|max:255"
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $hpinfo =Db::name("pay_payment")->where([["dzNo","=",$param['dzNo']],["is_del","=",0]])->findOrEmpty();
- if(empty($hpinfo)) return error_show(1004,"付款信息未找到");
- $payinfo =Db::name("pay")->where(["payNo"=>$hpinfo['payNo'],"is_del"=>0])->find();
- if($payinfo==false){
- return error_show(1004,"对账单数据未找到");
- }
- if ($this->level == 2 && $payinfo['is_comon']==0) {
- //判断是否开通供应商账号
- $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
- if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
- }
- if(!in_array($hpinfo['status'],[3,4]))return error_show(1004,"付款信息流程未完成");
- $isR=Db::name("pay_return")->where(["orderCode"=>$param['dzNo'],"status"=>[1,2],"is_del"=>0])->findOrEmpty();
- if(!empty($isR))return error_show(1004,"付款信息退款流程已存在");
- $returnCode =makeNo("RP");
- $data = [
- "returnCode"=>$returnCode,
- "returnType"=>2,
- "payNo"=>$hpinfo['payNo'],
- "orderCode"=>$param['dzNo'],
- "reason"=>$param['reason'],
- "returnImg"=>'',
- "remark"=>'',
- "status"=>1,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $insert=Db::name("pay_return")->insert($data);
- if($insert){
- return app_show(0,"退款申请新建成功",$returnCode);
- }else{
- return error_show(1004,"退款申请新建失败");
- }
- }
- public function stageReturnList(){
- $param =$this->request->only(["relaComNo"=>"","companyNo"=>"","supplierNo"=>"","start"=>"","end"=>"","returnCode"=>"","payNo"=>"",
- "status"=>"","dzNo"=>"","pay_type"=>"","is_comon"=>"","page"=>1,"size"=>15],"post","trim");
- $condition=[["a.is_del","=",0],['a.returnType',"=",2],['pay_type','=',$param['pay_type']?:1]];
- $check = checkRole($this->roleid,[131,129]);
- if($check){
- $condition []=["a.apply_id","=",$this->uid];
- }
- if($param['relaComNo']!="") $condition[]=["b.companyNo|b.supplierNo","=",$param['relaComNo']];
- if($param['companyNo']!="") $condition[]=["b.companyNo","=",$param['companyNo']];
- if($param['supplierNo']!="") $condition[]=["b.supplierNo","=",$param['supplierNo']];
- if($param['start']!="") $condition[]=["a.addtime",">=",date("Y-m-d H:i:s",strtotime($param['start']))];
- if($param['end']!="") $condition[]=["a.addtime","<=",date("Y-m-d 23:59:59",strtotime($param['end']))];
- if($param['status']!="") $condition[]=["a.status","=",$param['status']];
- if($param['dzNo']!="") $condition[]=["a.orderCode","like","%{$param['dzNo']}%"];
- if($param['returnCode']!="") $condition[]=["a.returnCode","like","%{$param['returnCode']}%"];
- if($param['payNo']!="") $condition[]=["a.payNo","like","%{$param['payNo']}%"];
- if(isset($param['is_comon'])&&$param['is_comon']!=='') $condition []=['is_comon','=',$param['is_comon']];
- $count = Db::name("pay_return")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_payment c", "a.orderCode=c.dzNo")
- ->where($condition)
- ->count();
- $total = ceil($count / $param['size']);
- $page = $param['page'] >= $total ? intval($total) : intval($param['page']);
- $list = Db::name("pay_return")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_payment c", "a.orderCode=c.dzNo")
- ->where($condition)
- ->page($page, intval($param['size']))
- ->order('id desc')
- ->field("a.*,b.supplierNo,b.is_comon,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.apay_fee,b.wpay_fee,b.pay_fee,c.pay_fee pay_pay_fee")
- ->select()
- ->toArray();
- //校验是否开通了供应商账号
- $supp_account = check_has_account_by_supplierNos(array_unique(array_column($list, 'supplierNo')));
- foreach ($list as &$value) {
- $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
- }
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function stageReturnStatus(){
- $param =$this->request->only(["returnCode"=>"","status"=>"","remark"=>"","returnImg"=>""],"post","trim");
- $valide=Validate::rule([
- "returnCode|退票申请编号"=>"require|max:255",
- "status|状态"=>"require|number|in:1,2,3",
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $returninfo =Db::name("pay_return")->where(["is_del"=>0,"returnCode"=>$param['returnCode']])->findOrEmpty();
- if(empty($returninfo))return error_show(1004,"退票详情未找到");
- Db::startTrans();
- try{
- if($param['status']==2){
- $invinfo =Db::name("pay_payment")->where(["dzNo"=>$returninfo['orderCode'],"is_del"=>0])->findOrEmpty();
- if(empty($invinfo))throw new Exception("付款详情未找到");
- $pay =Db::name("pay")->where(["payNo"=>$returninfo['payNo'],"is_del"=>0])->findOrEmpty();
- if(empty($pay))throw new Exception("对账详情未找到");
- $invup =Db::name("pay_payment")->where($invinfo)->update(["status"=>5,"updatetime"=>date("Y-m-d H:i:s")]);
- if($invup==false)throw new Exception("付款更新失败");
- if($pay['apay_fee']<$invinfo['pay_fee'])throw new Exception('已付款金额不足');
- $paydata=[
- "apay_fee"=>$pay['apay_fee']-$invinfo['pay_fee'],
- "wpay_fee"=>$pay['wpay_fee']+$invinfo['pay_fee'],
- "pay_status" => $pay['pay_fee']==0 &&($pay['apay_fee']-$invinfo['pay_fee'])==0?1:2,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $oayup =Db::name("pay")->where($pay)->update($paydata);
- if($oayup==false)throw new Exception("对账更新失败");
- }
- $update=[
- "status"=>$param['status'],
- "remark"=>$param['remark'],
- "returnImg"=>$param['returnImg'],
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $up =Db::name("pay_return")->where($returninfo)->update($update);
- if($up==false)throw new Exception("退款申请审核失败");
- Db::commit();
- if($param['status']==2 && $pay['is_comon']==1){
- event('comonOrder', ['payNo' => $pay['payNo'], 'pay_fee' => $invinfo['pay_fee'], 'type' => 'repay']);
- }
- return app_show(0,"退款申请审核成功");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function stageReturnInfo(){
- $param = $this->request->only(["returnCode"=>""],"post","trim");
- $valide=Validate::rule([
- "returnCode|退票申请编号"=>"require|max:255",
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $info = Db::name("pay_return")->alias("a")
- ->leftJoin("pay b","a.payNo=b.payNo and b.is_del=0")
- ->leftJoin("pay_payment c","a.orderCode=c.dzNo")
- ->where(['returnCode'=>$param['returnCode']])
- ->field("a.*,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.apay_fee,b.wpay_fee,b.pay_fee,c.pay_fee pay_pay_fee")
- ->findOrEmpty();
- return app_show(0,"退款申请获取成功",$info);
- }
- /**批量上传待认证发票
- * @param hpNo array 回票申请编号集合 必传
- * @param relaComNo string 业务公司编号 企业账户
- * @param companyNo string 业务公司编号 超管账户
- * @return \think\response\Json|void
- */
- //回票申请批量认证
- public function hpBatchImport()
- {
- $post = $this->request->only(["list" => [], "relaComNo" => "", "companyNo" => ""], "post");
- $valid = Validate::rule([
- "list|回票申请编号集合" => "require|array|max:100",
- "relaComNo|关联公司" => "requireWithout:companyNo|max:255",
- "companyNo|公司编号" => "requireWithout:relaComNo|max:255",
- ]);
- if ($valid->check($post) == false) return error_show(1004, $valid->getError());
- $companyNo = $post["relaComNo"] ?: $post['companyNo'];
- $payArr = Db::name("pay_invoice")
- ->alias("a")
- ->leftJoin("pay b", "a.payNo=b.payNo")
- ->where(['a.is_del' => 0, 'b.is_del' => 0])
- ->whereIn('a.hpNo', array_column($post['list'], 'hpNo'))
- ->column("a.id,a.payNo,a.hpNo,a.invoiceType,a.inv_fee as invoice_fee,a.status,b.inv_status,b.inv_fee,b.companyNo,b.ainv_fee,b.winv_fee,a.hpNo", "a.hpNo");
- $val_hpNo = Validate::rule([
- 'hpNo|回票申请编号' => 'require',
- 'status|审核状态' => 'require|number|in:4,7',
- 'remark|审核备注' => 'requireIf:status,7|max:255'
- ]);
- $unique=[];
- foreach ($post['list'] as $item) {
- if (!$val_hpNo->check($item)) return error_show(1004, $val_hpNo->getError());
- if(in_array($item['hpNo'],$unique))return error_show(1004, "{$item['hpNo']} 发票重复提交");
- $unique[]=$item['hpNo'];
- }
- Db::startTrans();
- try {
- $pay_invoice_allow = [];
- foreach ($post['list'] as $val) {
- if (!$val_hpNo->check($val)) throw new \Exception($val_hpNo->getError());
- if (!isset($payArr[$val['hpNo']])) throw new \Exception("{$val['hpNo']}记录不存在");
- $value = $payArr[$val['hpNo']];
- $payinfo = Db::name("pay")->where(["payNo"=>$payArr[$val['hpNo']]['payNo'],"status"=>2,"is_del"=>0])->findOrEmpty();
- if(empty($payinfo)) throw new Exception("{$value['hpNo']}对账信息有误");
- if ($payinfo['companyNo'] == '') throw new Exception("{$value['hpNo']}对账信息有误");
- if ($payinfo['companyNo'] != $companyNo) throw new Exception("{$value['hpNo']}不属于当前业务公司发票");
- if ($value['status'] != '3') throw new Exception("{$value['hpNo']}状态有误");
- if ($value['invoice_fee'] > $payinfo['inv_fee']) throw new Exception("{$value['hpNo']}对账单开票中金额不足");
- if ($val['status'] == 4) {
- Pay::addAinv($payArr[$val['hpNo']]['payNo'],$value['invoice_fee']);
- $pay_invoice_allow[] = $value['id'];
- } else {
- Pay::subInv($payArr[$val['hpNo']]['payNo'],$value['invoice_fee']);
- Db::name("pay_invoice")
- ->where(["id" => $value['id'], "status" => 3, "is_del" => 0])
- ->update(["status" => $val['status'], "updatetime" => date("Y-m-d H:i:s"), 'remark' =>$val['remark']]);
- }
- }
- if ($pay_invoice_allow) Db::name("pay_invoice")->where(["id" => $pay_invoice_allow, "status" => 3, "is_del" => 0])->update(["status" => 4, "updatetime" =>date("Y-m-d H:i:s")]);
- // if ($update == false) throw new Exception("回票申请状态更新失败");
- Db::commit();
- return app_show(0, "回票申请认证成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- /**
- * 导出对账单采购单信息
- */
- public function payCgdExport(){
- $param = $this->request->only(["payNo"=>""],"post","trim");
- $valide=Validate::rule([
- "payNo|对账申请编号"=>"require|max:255",
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $payinfo =Db::name("pay")->where(["payNo"=>$param['payNo'],"is_del"=>0,"pay_type"=>1])->findOrEmpty();
- if(empty($payinfo)) return error_show(1005,'对账单信息未找到');
- $cgdlist =Db::name("pay_info")->alias("a")
- ->leftJoin("cgd_info b","a.cgdNo=b.sequenceNo")
- ->leftJoin("order_category c","a.cgdNo=c.code and order_type=2")
- ->leftJoin("good d","c.spuCode =d.spuCode")
- ->where(["a.payNo"=>$param['payNo'],"a.status"=>1,"a.is_del"=>0])
- ->field("a.payNo'对账单号',b.sequenceNo '采购单编号',b.qrdCode '销售单编号',b.supplierName '供货商',b.companyName '业务公司',
- b.goodUnit '单位',(b.goodNum-b.thNum) '商品数量',b.goodPrice'商品单价',b.totalPrice'总货款',
- if(b.cxCode='',b.qrdCode,b.cxCode) 销售主单号,b.goodNo 商品编码,b.goodName 商品名称,c.cat_name 货物和劳务名称,c.merge_code 商品开票类目,c.short_name 商品和服务分类简称,
- c.tax/100 开票税率,c.inv_good_name 开票商品名称,if(b.open_type =1,'原商品开票',if(b.open_type =2,'子商品开票','')) 开票类型")
- ->select()->toArray();
- if(empty($cgdlist))$cgdlist=["暂无数据"=>''];
- else{
- array_walk($cgdlist, function (&$item) {
- $item['采购单可关联金额']= bcsub($item['总货款'],InvoiceOrder::getInvoiceOrderTotalFee($item['采购单编号']),2);
- });
- }
- excelExport("{$param['payNo']}对账采购单详情",array_keys($cgdlist[0]),$cgdlist);
- }
- /** 导出对账单采购单信息
- */
- public function payTrackExport(){
- $param = $this->request->only(['payNo'=>''],'post','trim');
- $valide=Validate::rule([
- 'payNo|对账申请编号'=>'require|max:255',
- ]);
- if($valide->check($param)==false)return error_show(1004,$valide->getError());
- $payinfo =Db::name('pay')->where(['payNo'=>$param['payNo'],'is_del'=>0,'pay_type'=>2])->findOrEmpty();
- if(empty($payinfo)) return error_show(1005,'对账单信息未找到');
- $cgdlist =Pay::alias("e")
- ->leftJoin("pay_info a","a.payNo=e.payNo and a.status=1 and a.is_del=0")
- ->leftJoin("track b","a.cgdNo=b.TrackCode")
- ->leftJoin("fhd_child c","c.outChildCode=b.outChildCode")
- ->where(['e.payNo'=>$param['payNo']])
- ->field("a.payNo 对账单号,
- e.total_fee 对账单总金额,
- e.status 对账单状态,
- e.apply_name 对账单创建人,
- e.addtime 对账单创建时间,
- b.TrackCode 发货运单号,
- b.outChildCode 发货工单号,
- c.outCode 发货单号,
- c.num 发货数量,
- b.orderCode 销售单号,
- b.cgdNo 采购单号,
- c.order_source 订单来源,
- c.order_type 商品类型,
- c.good_name 商品名称,
- b.supplierNo 物流供应商编号,
- b.supplierName 物流供应商名称,
- b.companyNo 业务公司编号,
- b.companyName 业务公司名称,
- b.post_fee 物流费,
- b.apply_name 运费单创建人,
- b.create_time 运费单创建时间")
- ->withAttr("对账单状态",function ($v){
- return Pay::$status[$v]??"";
- })
- ->withAttr('订单来源',function ($v){
- return FhdChild::$order_source[$v]??'';
- })
- ->withAttr('商品类型',function ($v){
- return FhdChild::$order_type[$v]??'';
- })
- ->select()->toArray();
- // $this->success("",$cgdlist);
- if(empty($cgdlist))$cgdlist=['暂无数据'=>''];
- excelExport("{$param['payNo']}对账运费单详情",array_keys($cgdlist[0]),$cgdlist);
- }
- // /**校验供应商下面是否有操作账户
- // * @param $supplierNo 供应商账户
- // * @return array
- // */
- // private function checkSupplier($supplierNo){
- // $companyinfo = UserHandle("/userCompanyBasicList", ["companyNo" =>$supplierNo]);
- // if ($companyinfo['code'] != 0) return ["code"=>$companyinfo['code'],"message"=> $companyinfo['message']];
- // if (!empty($companyinfo['data']) && $companyinfo['data']['count'] > 0) {
- // return ["code"=>1004,"message"=> "供应商公司存在操作账户,请用供应商账户操作"];
- // }
- // else{
- // return ["code"=>0,"message"=> "业务账户可操作"];
- // }
- // }
- }
|