Receipt.php 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use think\Request;
  7. class Receipt extends BaseController
  8. {
  9. /**
  10. * 显示资源列表
  11. *
  12. * @return \think\Response
  13. */
  14. public function list()
  15. {
  16. $post = $this->request->post();
  17. $token = isset($post['token']) ? trim($post['token']) : "";
  18. if ($token == "") {
  19. return error_show(101, 'token不能为空');
  20. }
  21. $effetc = VerifyTokens($token);
  22. if (!empty($effetc) && $effetc['code'] != 0) {
  23. return error_show($effetc['code'], $effetc['message']);
  24. }
  25. $condition = [['is_del',"=",0],['refund_status',"=",0]];
  26. $guserinfo =GetUserInfo($token);
  27. if(isset($guserinfo['code']) && $guserinfo['code']!=0){
  28. return error_show($guserinfo['code'],$guserinfo['message']);
  29. }
  30. $check = checkRole($guserinfo['data']['roleid'],52);
  31. if($check){
  32. $condition[]=["apply_id","=", $guserinfo['data']['id']];
  33. }
  34. $no = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
  35. if ($no != "") {
  36. $condition[] = ["inv_in", "=", "{$no}"];
  37. }
  38. $status = isset($post['status']) && $post['status'] !== "" ? intval($post['status']) : "";
  39. if ($status !== "") {
  40. $condition[] = ["status", "=", "{$status}"];
  41. }
  42. $type_check = isset($post['type_check']) && $post['type_check'] != "" ? $post['type_check'] : "";
  43. if ($type_check != "") {
  44. $condition[] = ["type_check", "=", "{$type_check}"];
  45. }
  46. $starttime = isset($post['starttime']) && $post['starttime'] != "" ? $post['starttime'] : "";
  47. if ($starttime != "") {
  48. $starttime = $starttime." 00:00:00";
  49. $condition[] = ["addtime", ">=", "{$starttime}"];
  50. }
  51. $endtime = isset($post['endtime']) && $post['endtime'] != "" ? $post['endtime'] : "";
  52. if ($endtime != "") {
  53. $endtime = $endtime." 23:59:59";
  54. $condition[] = ["addtime", "<=", "{$endtime}"];
  55. }
  56. $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
  57. $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
  58. $count = Db::name("invoice_pool")->where($condition)->count();
  59. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  60. $page = $page >= $total ? intval($total) : $page;
  61. $list = Db::name("invoice_pool")->where($condition)->order("addtime desc")->page(intval($page), $size)->select();
  62. $data=[];
  63. foreach ($list as $value){
  64. $customer= Db::name("customer_info")->where("companyNo","=",$value['inv_in'])->field("companyName,contactor")
  65. ->find();
  66. $value['company'] = isset($customer['companyName']) ? $customer['companyName']:"";
  67. $value['contactor'] = isset($customer['contactor']) ? $customer['contactor']:"";
  68. $out = Db::name('company_info')->where('companyNo',"=",$value['inv_out'])->find();
  69. $value['kp_company'] =isset($out['company_name']) ? $out['company_name']:"";
  70. $post = Db::name("inv_post")->where("invNo","=",$value['invNo'])->find();
  71. $value['post_company']=isset($post['post_company'])&&$post['post_company']!="" ? $post['post_company']:"";
  72. $value['post_code']=isset($post['postNo'])&&$post['postNo']!="" ? $post['postNo']:"";
  73. $data[]=$value;
  74. }
  75. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  76. }
  77. /**
  78. * 显示创建资源表单页.
  79. *
  80. * @return \think\Response
  81. */
  82. public function create()
  83. {
  84. $post = $this->request->post();
  85. $token = isset($post['token']) ? trim($post['token']) : "";
  86. if ($token == "") {
  87. return error_show(101, 'token不能为空');
  88. }
  89. $effetc = VerifyTokens($token);
  90. if (!empty($effetc) && $effetc['code'] != 0) {
  91. return error_show($effetc['code'], $effetc['message']);
  92. }
  93. // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
  94. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  95. $type = isset($post['type'])&&$post['type']!=""?intval($post['type']):1;
  96. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  97. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1";
  98. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  99. $userinfo = GetUserInfo($token);
  100. $username="";
  101. if($companyNo==""){
  102. return error_show(1004,"参数companyNo 不能为空");
  103. }
  104. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  105. if($inv_out==""){
  106. return error_show(1004,"参数inv_out 不能为空");
  107. }
  108. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  109. if(empty($out)){
  110. return error_show(1004,"未找到开票企业信息");
  111. }
  112. if(isset($userinfo['code'])&&$userinfo['code']==0){
  113. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  114. }
  115. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  116. if(empty($customer)){
  117. return error_show(1004,"未找到客户企业信息");
  118. }
  119. $good = isset($post['good'])&&is_array($post['good'])?$post['good']:"";
  120. if($good==""&& empty($good)){
  121. return error_show(1004,"商品信息不能为空");
  122. }
  123. $invoice=[];
  124. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  125. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  126. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  127. $post['invoice_bankNo']:"";
  128. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  129. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  130. $post['invoice_mobile']:"";
  131. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  132. $post['invoice_title']:"";
  133. $orderinfo=[];
  134. $orderNo=makeNo('ORD');
  135. $total=0;
  136. $fund_fee=0;
  137. $wfund_fee=0;
  138. $inv_fee=0;
  139. $winv_fee=0;
  140. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  141. // return error_show(1004,"企业信息联系电话格式错误");
  142. // }
  143. Db::startTrans();
  144. try{
  145. foreach ($good as $value){
  146. $temp=[];
  147. if(!isset($value['num'])||$value['num']==0){
  148. return error_show(1004,"商品数量不能为空");
  149. }
  150. if(!isset($value['total_fee'])||$value['total_fee']==0){
  151. return error_show(1004,"商品总金额不能为空");
  152. }
  153. $temp['orderNo'] = $orderNo;
  154. $temp['goodNo']= $value['sequenceNo'];
  155. $goocp = Db::name("qrd_list")->where("sequenceNo","=",$value['sequenceNo'])->find();
  156. $temp['good_name']= $goocp['goodname'];
  157. $temp['qrdNo'] = $goocp['qrdNo'];
  158. $temp['brand']= $goocp['brand'];
  159. $temp['unit']= $value['unit'];
  160. $temp['good_num']= $value['num'];
  161. $temp['price']= $goocp['price'];
  162. $temp['total_fee']= $value['total_fee'];
  163. $temp['wfund_fee'] =$value['total_fee'];
  164. $temp['winv_fee'] = $value['total_fee'];
  165. $temp['other_fee']= 0;
  166. $temp['status']= 1;
  167. $temp['remark']= isset($value['remark']) ? $value['remark'] : "";
  168. $temp['addtime']= date("Y-m-d H:i:s");
  169. $temp['updatetime']= date("Y-m-d H:i:s");
  170. $total+= $value['total_fee'];
  171. $fund_fee+= $goocp['apay_fee'];
  172. $winv_fee+= $goocp['winv_fee'];
  173. $inv_fee+= $goocp['ainv_fee'];
  174. $wfund_fee+= $goocp['wpay_fee'];
  175. $orderinfo[]=$temp;
  176. }
  177. if(!empty($invoice) && $invoice!=''){
  178. $invoice['updatetime'] = date("Y-m-d H:i:s");
  179. $invoice['checkNo'] = $companyNo;
  180. if($inv_add==1){
  181. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  182. if($cust){
  183. Db::rollback();
  184. return error_show(1005,"企业财务信息已存在");
  185. }
  186. $invoice['addtime'] = date("Y-m-d H:i:s");
  187. Db::name('customer_invoice')->insert($invoice);
  188. }else{
  189. Db::name('customer_invoice')->where('invoice_code',"=",$invoice['invoice_code'])->save($invoice);
  190. }
  191. }
  192. $orderins = Db::name("order_info")->insertAll($orderinfo);
  193. //if($total<0){
  194. // Db::rollback();
  195. // return error_show(1005,"发票核销数据为不能为负值");
  196. // }
  197. if($orderins) {
  198. $order = [
  199. "orderNo" => $orderNo,
  200. "companyNo" => $companyNo,
  201. "sales_id" => $effetc['data']['user']['id'],
  202. "sales_name" => $username,
  203. "total_amount" => $total,
  204. "inv_status" => 1,
  205. "fund_status" => 1,
  206. "fund_fee"=>0,
  207. "wfund_fee"=>$total,
  208. "inv_fee"=>0,
  209. "inv_used"=>$total,
  210. "winv_fee"=>0,
  211. "status" => 0,
  212. "type" => $type,
  213. "addtime" => date("Y-m-d H:i:s"),
  214. "updatetime" => date("Y-m-d H:i:s")
  215. ];
  216. $orderpool = Db::name("order_pool")->insert($order, true);
  217. if ($orderpool > 0) {
  218. $invNo = makeNo("INV");
  219. $inv = [
  220. "invNo" => $invNo,
  221. "inv_value" => $total,
  222. "inv_out" => $inv_out,
  223. "inv_in" => $companyNo,
  224. "apply_id" =>$effetc['data']['user']['id'],
  225. "apply_name" => $username,
  226. "status" => 0,
  227. "worder_fee"=>0,
  228. "order_used"=>$total,
  229. "wtrade_fee"=>$total,
  230. "remark" => $remark,
  231. "invoice_title" => $invoice['invoice_title'],
  232. "invoice_addr" => $invoice['invoice_addr'],
  233. "invoice_mobile" => $invoice['invoice_mobile'],
  234. "invoice_code" => $invoice['invoice_code'],
  235. "invoice_bank" => $invoice['invoice_bank'],
  236. "invoice_bankNo" => $invoice['invoice_bankNo'],
  237. "inv_add" => $inv_add,
  238. "is_order" =>1,
  239. "inv_type"=>$inv_type,
  240. "type_check"=>$type,
  241. "addtime" => date("Y-m-d H:i:s"),
  242. "updatetime" => date("Y-m-d H:i:s")
  243. ];
  244. $invinsert = Db::name("invoice_pool")->insert($inv);
  245. if ($invinsert) {
  246. if($type==2){
  247. Db::commit();
  248. return app_show(0,"发票新建成功");
  249. }
  250. $assocNo = makeNo("ASC");
  251. $asslog = [
  252. "assocNo"=>$assocNo,
  253. "type"=>1,
  254. "apply_id" =>$effetc['data']['user']['id'],
  255. "apply_name" => $username,
  256. "companyNo"=>$companyNo,
  257. "codeNo"=>$orderNo,
  258. "rela_form"=>1,
  259. "total_fee"=>$total,
  260. "balance"=>0,
  261. "cancel_total"=>$total,
  262. "status"=>1,
  263. "source"=>2,
  264. "addtime"=>date("Y-m-d H:i:s"),
  265. "updatetime"=>date("Y-m-d H:i:s")
  266. ];
  267. $logassc = Db::name("assoc_key")->insert($asslog);
  268. if($logassc){
  269. $assrela =[
  270. "assocNo"=>$assocNo,
  271. "viceNo"=>$invNo,
  272. "vice_total"=>$total,
  273. "vice_fee"=>0,
  274. "cancel_fee"=>$total,
  275. "addtime"=>date("Y-m-d H:i:s"),
  276. "updatetime"=>date("Y-m-d H:i:s")
  277. ];
  278. $relas = Db::name("assoc_rela")->insert($assrela);
  279. if($relas){
  280. $resula= $this->updateQrd($orderNo,$total);
  281. if($resula){
  282. Db::commit();
  283. return app_show(0,"发票新建申请成功");
  284. }
  285. }
  286. }
  287. }
  288. }
  289. }
  290. Db::rollback();
  291. return error_show(1004,"发票新建申请失败");
  292. }catch (\Exception $e) {
  293. Db::rollback();
  294. return error_show(1004, $e->getMessage());
  295. }
  296. }
  297. /**
  298. * 保存新建的资源
  299. * @param \think\Request $request
  300. * @return \think\Response
  301. */
  302. public function save()
  303. {
  304. $post = $this->request->post();
  305. $token = isset($post['token']) ? trim($post['token']) : "";
  306. if ($token == "") {
  307. return error_show(101, 'token不能为空');
  308. }
  309. $effetc = VerifyTokens($token);
  310. if (!empty($effetc) && $effetc['code'] != 0) {
  311. return error_show($effetc['code'], $effetc['message']);
  312. }
  313. // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : "";
  314. $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):"";
  315. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  316. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1;
  317. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  318. $type = isset($post['type'])&&$post['type']!=""?intval($post['type']):1;
  319. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  320. $userinfo = GetUserInfo($token);
  321. $username="";
  322. if($companyNo==""){
  323. return error_show(1004,"参数companyNo 不能为空");
  324. }
  325. if($invNo==""){
  326. return error_show(1004,"参数invNo 不能为空");
  327. }
  328. if(isset($userinfo['code'])&&$userinfo['code']==0){
  329. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  330. }
  331. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  332. if($inv_out==""){
  333. return error_show(1004,"参数inv_out 不能为空");
  334. }
  335. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  336. if(empty($out)){
  337. return error_show(1004,"未找到开票企业信息");
  338. }
  339. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  340. if(empty($customer)){
  341. return error_show(1004,"未找到客户企业信息");
  342. }
  343. $invinfo =Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->find();
  344. if(empty($invinfo)){
  345. return error_show(1004,"发票信息未找到");
  346. }
  347. if($invinfo['status']>=3){
  348. return error_show(1004,"发票信息已通过财务审核,无法修改!");
  349. }
  350. $good = isset($post['good'])&&is_array($post['good'])?$post['good']:"";
  351. if($good==""&& empty($good)){
  352. return error_show(1004,"商品信息不能为空");
  353. }
  354. $assc = Db::name("assoc_list")->where([["viceNo","=",$invNo],["is_del","=",0],["type","=",1]])->find();
  355. if(empty($assc)){
  356. return error_show(1005,"未找到对应的关联数据");
  357. }
  358. $invoice=[];
  359. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  360. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  361. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  362. $post['invoice_bankNo']:"";
  363. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  364. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  365. $post['invoice_mobile']:"";
  366. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  367. $post['invoice_title']:"";
  368. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  369. // return error_show(1004,"企业信息联系电话格式错误");
  370. // }
  371. $total=0;
  372. $fund_fee=0;
  373. $wfund_fee=0;
  374. $inv_fee=0;
  375. $winv_fee=0;
  376. Db::startTrans();
  377. try{
  378. if(!empty($invoice) && $invoice!='') {
  379. $invoice['updatetime'] = date("Y-m-d H:i:s");
  380. $invoice['checkNo'] = $companyNo;
  381. if ($inv_add == 1) {
  382. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  383. if($cust){
  384. Db::rollback();
  385. return error_show(1005,"企业财务信息已存在");
  386. }
  387. $invoice['addtime'] = date("Y-m-d H:i:s");
  388. Db::name('customer_invoice')->insert($invoice);
  389. } else {
  390. Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  391. }
  392. }
  393. // $reset = $this->qrd_delet($assc['codeNo'],$assc['cancel_total']);
  394. // if($reset){
  395. // Db::name("order_info")->where("orderNo","=",$assc['codeNo'])->save(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  396. // }else{
  397. // Db::rollback();
  398. // return error_show(1004,"确认单数据编辑失败");
  399. // }
  400. foreach ($good as $value){
  401. // $temp['goodNo']= $value['sequenceNo'];
  402. // $temp['orderNo']= $assc['codeNo'];
  403. //$goocp = Db::name("qrd_list")->where("sequenceNo","=",$value['sequenceNo'])->find();
  404. $goocp = Db::name("order_info")->where([["orderNo","=",$assc['codeNo']],["goodNo","=",$value['sequenceNo']]])
  405. ->find();
  406. // $goocp['good_name']= $value['remark'];
  407. // $temp['qrdNo'] = $goocp['qrdNo'];
  408. // $temp['brand']= $goocp['brand'];
  409. // $temp['unit']= $goocp['unit'];
  410. // $temp['good_num']= $value['num'];
  411. // $temp['price']= $goocp['price'];
  412. // $temp['total_fee']= $value['total_fee'];
  413. // $temp['wfund_fee'] = $value['total_fee'];
  414. // $temp['winv_fee'] = $value['total_fee'];
  415. // $temp['other_fee']= 0;
  416. // $temp['status']=1;
  417. $goocp['remark']= isset($value['remark']) ? $value['remark'] : "";
  418. $goocp['updatetime']= date("Y-m-d H:i:s");
  419. // $temp['addtime']= date("Y-m-d H:i:s");
  420. // $fund_fee+= $goocp['apay_fee'];
  421. // $winv_fee+= $goocp['winv_fee'];
  422. // $inv_fee+= $goocp['ainv_fee'];
  423. // $wfund_fee+= $goocp['wpay_fee'];
  424. Db::name("order_info")->save($goocp);
  425. $total+= $value['total_fee'];
  426. }
  427. $order = [
  428. "companyNo" => $companyNo,
  429. "total_amount" => $total,
  430. "fund_fee"=>0,
  431. "wfund_fee"=>$total,
  432. "inv_fee"=>0,
  433. "inv_used"=>$total,
  434. "winv_fee"=>0,
  435. "updatetime" => date("Y-m-d H:i:s")
  436. ];
  437. // if($total<0){
  438. // Db::rollback();
  439. // return error_show(1005,"发票核销数据为不能为负值");
  440. // }
  441. $orderpool = Db::name("order_pool")->where("orderNo","=",$assc['codeNo'])->save($order);
  442. if ($orderpool) {
  443. $invinfo['inv_value'] = $total;
  444. $invinfo['inv_in'] = $companyNo;
  445. $invinfo['inv_out'] = $inv_out;
  446. $invinfo['worder_fee'] = 0;
  447. $invinfo['inv_type'] = $inv_type;
  448. $invinfo['type_check'] = $type;
  449. $invinfo['wtrade_fee'] = $total;
  450. $invinfo['order_used'] = $total;
  451. $invinfo['invoice_title'] = $invoice['invoice_title'];
  452. $invinfo['invoice_addr'] = $invoice['invoice_addr'];
  453. $invinfo['invoice_mobile'] = $invoice['invoice_mobile'];
  454. $invinfo['invoice_code'] = $invoice['invoice_code'];
  455. $invinfo['invoice_bank'] = $invoice['invoice_bank'];
  456. $invinfo['invoice_bankNo'] = $invoice['invoice_bankNo'];
  457. $invinfo['inv_add'] = $inv_add;
  458. $invinfo['remark']=$remark;
  459. $invinfo['updatetime'] =date("Y-m-d H:i:s");
  460. $invinsert = Db::name("invoice_pool")->save($invinfo);
  461. if($invinsert){
  462. $asslog = [
  463. "cancel_fee" => $total,
  464. "vice_fee" => 0,
  465. "vice_total" => 0,
  466. "updatetime" => date("Y-m-d H:i:s")
  467. ];
  468. $logassc = Db::name("assoc_rela")->where("id","=", $assc['id'])->save($asslog);
  469. if ($logassc) {
  470. $keyas=[
  471. "total_fee"=>$total,
  472. "balance"=>0,
  473. "cancel_total"=>$total,
  474. "updatetime"=>date("Y-m-d H:i:s")
  475. ];
  476. $relas = Db::name("assoc_key")->where("id","=",$assc['aid'])->save($keyas);
  477. if($relas){
  478. // $resula= $this->updateQrd($assc['codeNo'],$total);
  479. // if($resula){
  480. Db::commit();
  481. return app_show(0,"发票编辑成功");
  482. // }
  483. }
  484. }
  485. }
  486. }
  487. Db::rollback();
  488. return error_show(1004,"发票编辑失败");
  489. }catch (\Exception $e) {
  490. Db::rollback();
  491. return error_show(1004, $e->getMessage());
  492. }
  493. }
  494. /**
  495. * @return \think\response\Json|void
  496. * @throws \think\db\exception\DataNotFoundException
  497. * @throws \think\db\exception\DbException
  498. * @throws \think\db\exception\ModelNotFoundException
  499. * @throws \think\exception\DbException
  500. */
  501. public function CreateByTrade(){
  502. $post = $this->request->post();
  503. $token = isset($post['token']) ? trim($post['token']) : "";
  504. if ($token == "") {
  505. return error_show(101, 'token不能为空');
  506. }
  507. $effetc = VerifyTokens($token);
  508. if (!empty($effetc) && $effetc['code'] != 0) {
  509. return error_show($effetc['code'], $effetc['message']);
  510. }
  511. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  512. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  513. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1";
  514. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  515. $userinfo = GetUserInfo($token);
  516. $username="";
  517. if($companyNo==""){
  518. return error_show(1004,"参数companyNo 不能为空");
  519. }
  520. if(isset($userinfo['code'])&&$userinfo['code']==0){
  521. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  522. }
  523. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  524. if(empty($customer)){
  525. return error_show(1004,"未找到客户企业信息");
  526. }
  527. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  528. if($inv_out==""){
  529. return error_show(1004,"参数inv_out 不能为空");
  530. }
  531. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  532. if(empty($out)){
  533. return error_show(1004,"未找到开票企业信息");
  534. }
  535. $traNo = isset($post['traNo'])&&$post['traNo']!=""?$post['traNo']:"";
  536. if($traNo==""){
  537. return error_show(1004,"参数traNo 不能为空");
  538. }
  539. $trade = Db::name("trade_pool")->where([["traNo","in",$traNo],["is_del","=",0],['status',"=",3]])->select()
  540. ->toArray();
  541. if(empty($trade)){
  542. return error_show(1004,"未找到资金信息");
  543. }
  544. $invoice=[];
  545. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  546. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  547. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  548. $post['invoice_bankNo']:"";
  549. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  550. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  551. $post['invoice_mobile']:"";
  552. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  553. $post['invoice_title']:"";
  554. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  555. // return error_show(1004,"企业信息联系电话格式错误");
  556. // }
  557. Db::startTrans();
  558. try{
  559. if(!empty($invoice) && $invoice!='') {
  560. $invoice['updatetime'] = date("Y-m-d H:i:s");
  561. $invoice['checkNo'] = $companyNo;
  562. if ($inv_add == 1) {
  563. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  564. if($cust){
  565. Db::rollback();
  566. return error_show(1005,"企业财务信息已存在");
  567. }
  568. $invoice['addtime'] = date("Y-m-d H:i:s");
  569. Db::name('customer_invoice')->insert($invoice);
  570. } else {
  571. Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  572. }
  573. }
  574. $total=0;
  575. $relas=[];
  576. $assocNo = makeNo("ASC");
  577. $invNo = makeNo("INV");
  578. foreach ($trade as $value){
  579. if($value['winv_fee']<=0){
  580. continue;
  581. }
  582. $relas[] =[
  583. "assocNo"=>$assocNo,
  584. "viceNo"=>$value['traNo'],
  585. "vice_total"=>$value['total_fee'],
  586. "vice_fee"=>0,
  587. "cancel_fee"=>$value['winv_fee'],
  588. "addtime"=>date("Y-m-d H:i:s"),
  589. "updatetime"=>date("Y-m-d H:i:s")
  590. ];
  591. $total+=$value['winv_fee'];
  592. $value['inv_used']+=$value['winv_fee'];
  593. $value['winv_fee']=0;
  594. $value['updatetime']=date("Y-m-d H:i:s");
  595. Db::name("trade_pool")->save($value);
  596. }
  597. $inv = [
  598. "invNo" => $invNo,
  599. "inv_value" => $total,
  600. "inv_out" => $inv_out,
  601. "inv_in" => $companyNo,
  602. "apply_id" =>$effetc['data']['user']['id'],
  603. "apply_name" => $username,
  604. "status" => 0,
  605. "worder_fee"=>$total,
  606. "order_used"=>0,
  607. "fund_used"=>$total,
  608. "wtrade_fee"=>0,
  609. "remark" => $remark,
  610. "invoice_title" => $invoice['invoice_title'],
  611. "invoice_addr" => $invoice['invoice_addr'],
  612. "invoice_mobile" => $invoice['invoice_mobile'],
  613. "invoice_code" => $invoice['invoice_code'],
  614. "invoice_bank" => $invoice['invoice_bank'],
  615. "invoice_bankNo" => $invoice['invoice_bankNo'],
  616. "inv_add" => $inv_add,
  617. "is_order" =>0,
  618. "inv_type"=>$inv_type,
  619. "type_check"=>3,
  620. "addtime" => date("Y-m-d H:i:s"),
  621. "updatetime" => date("Y-m-d H:i:s")
  622. ];
  623. $invinsert = Db::name("invoice_pool")->insert($inv);
  624. if ($invinsert) {
  625. $asslog = [
  626. "assocNo"=>$assocNo,
  627. "type"=>2,
  628. "apply_id" =>$effetc['data']['user']['id'],
  629. "apply_name" => $username,
  630. "companyNo"=>$companyNo,
  631. "codeNo"=>$invNo,
  632. "rela_form"=>4,
  633. "total_fee"=>$total,
  634. "balance"=>0,
  635. "cancel_total"=>$total,
  636. "status"=>1,
  637. "source"=>2,
  638. "addtime"=>date("Y-m-d H:i:s"),
  639. "updatetime"=>date("Y-m-d H:i:s")
  640. ];
  641. $logassc = Db::name("assoc_key")->insert($asslog);
  642. if($logassc){
  643. $relas = Db::name("assoc_rela")->insertAll($relas);
  644. if($relas){
  645. Db::commit();
  646. return app_show(0,"发票新建申请成功");
  647. }
  648. }
  649. }
  650. Db::rollback();
  651. return error_show(1005,"发票新建申请失败");
  652. }catch (\Exception $e){
  653. Db::rollback();
  654. return error_show(1005,$e->getMessage());
  655. }
  656. }
  657. /**
  658. * @return \think\response\Json|void
  659. * @throws \think\db\exception\DataNotFoundException
  660. * @throws \think\db\exception\DbException
  661. * @throws \think\db\exception\ModelNotFoundException
  662. * @throws \think\exception\DbException
  663. */
  664. public function EditByTrain(){
  665. $post = $this->request->post();
  666. $token = isset($post['token']) ? trim($post['token']) : "";
  667. if ($token == "") {
  668. return error_show(101, 'token不能为空');
  669. }
  670. $effetc = VerifyTokens($token);
  671. if (!empty($effetc) && $effetc['code'] != 0) {
  672. return error_show($effetc['code'], $effetc['message']);
  673. }
  674. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  675. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  676. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):"1";
  677. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  678. $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):"";
  679. $userinfo = GetUserInfo($token);
  680. $username="";
  681. if($companyNo==""){
  682. return error_show(1004,"参数companyNo 不能为空");
  683. }
  684. if($invNo==""){
  685. return error_show(1004,"参数invNo 不能为空");
  686. }
  687. if(isset($userinfo['code'])&&$userinfo['code']==0){
  688. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  689. }
  690. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  691. if(empty($customer)){
  692. return error_show(1004,"未找到客户企业信息");
  693. }
  694. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  695. if($inv_out==""){
  696. return error_show(1004,"参数inv_out 不能为空");
  697. }
  698. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  699. if(empty($out)){
  700. return error_show(1004,"未找到开票企业信息");
  701. }
  702. $invinfo =Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->find();
  703. if(empty($invinfo)){
  704. return error_show(1004,"发票信息未找到");
  705. }
  706. if($invinfo['status']>=3){
  707. return error_show(1004,"发票信息已通过财务审核,无法修改!");
  708. }
  709. $invoice=[];
  710. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  711. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  712. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  713. $post['invoice_bankNo']:"";
  714. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  715. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  716. $post['invoice_mobile']:"";
  717. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  718. $post['invoice_title']:"";
  719. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  720. // return error_show(1004,"企业信息联系电话格式错误");
  721. // }
  722. Db::startTrans();
  723. try{
  724. if(!empty($invoice) && $invoice!='') {
  725. $invoice['updatetime'] = date("Y-m-d H:i:s");
  726. $invoice['checkNo'] = $companyNo;
  727. if ($inv_add == 1) {
  728. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  729. if($cust){
  730. Db::rollback();
  731. return error_show(1005,"企业财务信息已存在");
  732. }
  733. $invoice['addtime'] = date("Y-m-d H:i:s");
  734. Db::name('customer_invoice')->insert($invoice);
  735. } else {
  736. Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  737. }
  738. }
  739. $invpool=[
  740. "invoice_title" => $invoice['invoice_title'],
  741. "invoice_addr" => $invoice['invoice_addr'],
  742. "invoice_mobile" => $invoice['invoice_mobile'],
  743. "invoice_code" => $invoice['invoice_code'],
  744. "invoice_bank" => $invoice['invoice_bank'],
  745. "invoice_bankNo" => $invoice['invoice_bankNo'],
  746. "inv_add" => $inv_add,
  747. "inv_out" => $inv_out,
  748. "remark"=>$remark,
  749. "updatetime"=>date("Y-m-d H:i:s")
  750. ];
  751. $up= Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",$invNo]])->save($invpool);
  752. if($up){
  753. Db::commit();
  754. return app_show(0,"更新成功");
  755. }else{
  756. Db::rollback();
  757. return error_show(1005,"更新失败");
  758. }
  759. }catch(\Exception $e){
  760. Db::rollback();
  761. return error_show(1005,$e->getMessage());
  762. }
  763. }
  764. /**
  765. * 显示指定的资源
  766. *
  767. * @param int $id
  768. * @return \think\Response
  769. */
  770. public function read()
  771. {
  772. $post = $this->request->post();
  773. $token = isset($post['token']) ? trim($post['token']) : "";
  774. if ($token == "") {
  775. return error_show(101, 'token不能为空');
  776. }
  777. $effetc = VerifyTokens($token);
  778. if (!empty($effetc) && $effetc['code'] != 0) {
  779. return error_show($effetc['code'], $effetc['message']);
  780. }
  781. $invid = isset($post['id'])&&$post['id']!=""?intval($post['id']):"";
  782. if($invid==""){
  783. return error_show(1004,"参数id 不能为空");
  784. }
  785. $inv = Db::name("invoice_pool")->where("id","=",$invid)->find();
  786. if(empty($inv)){
  787. return error_show(1005,"未找到发票信息");
  788. }
  789. $customer = Db::name("customer_info")->where("companyNo","=",$inv['inv_in'])->find();
  790. $inv['customer']=empty($customer)? []:$customer;
  791. $kp_company = Db::name("company_info")->where("companyNo","=",$inv['inv_out'])->find();
  792. $inv['kp_company']=empty($kp_company)? []:$kp_company;
  793. $inv['order']=[];
  794. $assoc = Db::name("assoc_list")->where([["type","=",1],['viceNo',"=",$inv["invNo"]],["is_del","=",0]])
  795. ->find();
  796. if(!empty($assoc)){
  797. $order= Db::name("order_pool")->where([['orderNo',"=",$assoc['codeNo']]])->find();
  798. $list=[];
  799. if($order['type']==1){
  800. $good = Db::name('order_info')->where([['orderNo',"=",$assoc['codeNo']],["status","=",1]])->select();
  801. foreach ($good as $key=>$value){
  802. $info = Db::name("qrd_list")->where("sequenceNo","=",$value['goodNo'])->find();
  803. $value['num'] = intval($info['num']);
  804. $value['ainv_fee'] =sprintf("%.2f", $info['ainv_fee']);
  805. $value['winv_fee'] = sprintf("%.2f",$info['winv_fee']);
  806. $value['total'] = sprintf("%.2f",$info['total_fee']);
  807. $value['inv_num'] = intval($info['inv_num']);
  808. $list[]=$value;
  809. }
  810. }
  811. $order['good'] = $list;
  812. $inv['order']=$order;
  813. }
  814. $inv['trade']=[];
  815. $assoc= Db::name("assoc_list")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$inv["invNo"]]])->select()->toArray();
  816. if(!empty($assoc)) {
  817. foreach ($assoc as $value) {
  818. $temp = Db::name("trade_list")->alias("a")->leftJoin("cfp_customer_info b","a.companyNo=b.companyNo")
  819. ->where([["a.is_del", "=", 0], ["a.traNo", "=", $value["viceNo"]]])->field("a.*,b.companyName")
  820. ->find();
  821. $inv['trade'][]=$temp;
  822. }
  823. }
  824. return app_show(0,"获取成功",$inv);
  825. }
  826. /**
  827. * 显示编辑资源表单页.
  828. *
  829. * @param int $id
  830. * @return \think\Response
  831. */
  832. public function add()
  833. {
  834. $post = $this->request->post();
  835. $token = isset($post['token']) ? trim($post['token']) : "";
  836. if ($token == "") {
  837. return error_show(101, 'token不能为空');
  838. }
  839. $effetc = VerifyTokens($token);
  840. if (!empty($effetc) && $effetc['code'] != 0) {
  841. return error_show($effetc['code'], $effetc['message']);
  842. }
  843. // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : "";
  844. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  845. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1;
  846. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  847. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  848. $userinfo = GetUserInfo($token);
  849. $username="";
  850. if($companyNo==""){
  851. return error_show(1004,"参数companyNo 不能为空");
  852. }
  853. if(isset($userinfo['code'])&&$userinfo['code']==0){
  854. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  855. }
  856. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  857. if(empty($customer)){
  858. return error_show(1004,"未找到客户企业信息");
  859. }
  860. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  861. if($inv_out==""){
  862. return error_show(1004,"参数inv_out 不能为空");
  863. }
  864. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  865. if(empty($out)){
  866. return error_show(1004,"未找到开票企业信息");
  867. }
  868. $invoice=[];
  869. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  870. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  871. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  872. $post['invoice_bankNo']:"";
  873. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  874. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  875. $post['invoice_mobile']:"";
  876. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  877. $post['invoice_title']:"";
  878. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  879. // return error_show(1004,"企业信息联系电话格式错误");
  880. // }
  881. $total = isset($post['total'])&&$post['total']!=""?$post['total']:"";
  882. if($total==""){
  883. return error_show(1004,"参数total 不能为空");
  884. }
  885. //if($total<0){
  886. // Db::rollback();
  887. // return error_show(1005,"发票核销数据为不能为负值");
  888. // }
  889. Db::startTrans();
  890. try{
  891. if(!empty($invoice) && $invoice!='') {
  892. $invoice['updatetime'] = date("Y-m-d H:i:s");
  893. $invoice['checkNo'] = $companyNo;
  894. if ($inv_add == 1) {
  895. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  896. if($cust){
  897. Db::rollback();
  898. return error_show(1005,"企业财务信息已存在");
  899. }
  900. $invoice['addtime'] = date("Y-m-d H:i:s");
  901. Db::name('customer_invoice')->insert($invoice);
  902. } else {
  903. Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  904. }
  905. }
  906. $invNo = makeNo("INV");
  907. $inv = [
  908. "invNo" => $invNo,
  909. "inv_value" => $total,
  910. "inv_out" => $inv_out,
  911. "inv_in" => $companyNo,
  912. "apply_id" =>$effetc['data']['user']['id'],
  913. "apply_name" => $username,
  914. "status" => 0,
  915. "trade_status" => 1,
  916. "order_status" => 1,
  917. "worder_fee"=>$total,
  918. "wtrade_fee"=>$total,
  919. "invoice_title" => $invoice['invoice_title'],
  920. "invoice_addr" => $invoice['invoice_addr'],
  921. "invoice_mobile" => $invoice['invoice_mobile'],
  922. "invoice_code" => $invoice['invoice_code'],
  923. "invoice_bank" => $invoice['invoice_bank'],
  924. "invoice_bankNo" => $invoice['invoice_bankNo'],
  925. "inv_add" => $inv_add,
  926. "inv_type"=>$inv_type,
  927. "type_check"=>2,
  928. "is_order"=>0,
  929. "remark"=>$remark,
  930. "addtime" => date("Y-m-d H:i:s"),
  931. "updatetime" => date("Y-m-d H:i:s")
  932. ];
  933. $invinsert = Db::name("invoice_pool")->insert($inv);
  934. if($invinsert){
  935. Db::commit();
  936. return app_show(0,"发票创建成功");
  937. }
  938. Db::rollback();
  939. return error_show(1004,"发票新建失败");
  940. }catch (\Exception $e){
  941. Db::rollback();
  942. return error_show(1004,$e->getMessage());
  943. }
  944. }
  945. /**
  946. * 显示编辑资源表单页.
  947. *
  948. * @param int $id
  949. * @return \think\Response
  950. */
  951. public function edit()
  952. {
  953. $post = $this->request->post();
  954. $token = isset($post['token']) ? trim($post['token']) : "";
  955. if ($token == "") {
  956. return error_show(101, 'token不能为空');
  957. }
  958. $effetc = VerifyTokens($token);
  959. if (!empty($effetc) && $effetc['code'] != 0) {
  960. return error_show($effetc['code'], $effetc['message']);
  961. }
  962. // $companyNo = isset($post['tradeNo'])&&$post['tradeNo']!=""?trim($post['tradeNo']):"";
  963. $invNo = isset($post['invNo'])&&$post['invNo']!=""?trim($post['invNo']):"";
  964. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  965. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1;
  966. $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  967. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  968. // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : "";
  969. $userinfo = GetUserInfo($token);
  970. $username="";
  971. if($companyNo==""){
  972. return error_show(1004,"参数companyNo 不能为空");
  973. }
  974. if($invNo==""){
  975. return error_show(1004,"参数companyNo 不能为空");
  976. }
  977. if(isset($userinfo['code'])&&$userinfo['code']==0){
  978. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  979. }
  980. $inv_out = isset($post['inv_out'])&&$post['inv_out']!=""?trim($post['inv_out']):"";
  981. if($inv_out==""){
  982. return error_show(1004,"参数inv_out 不能为空");
  983. }
  984. $out = Db::name('company_info')->where([['companyNo',"=",$inv_out],['status',"=",1]])->find();
  985. if(empty($out)){
  986. return error_show(1004,"未找到开票企业信息");
  987. }
  988. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  989. if(empty($customer)){
  990. return error_show(1004,"未找到客户企业信息");
  991. }
  992. $invinfo =Db::name("invoice_pool")->where("invNo","=",$invNo)->find();
  993. if(empty($invinfo)){
  994. return error_show(1004,"发票信息未找到");
  995. }
  996. if($invinfo['status']>=3){
  997. return error_show(1004,"发票信息已通过财务审核,无法修改!");
  998. }
  999. $total = isset($post['total'])&&$post['total']!=""?$post['total']:"";
  1000. if($total==""){
  1001. return error_show(1004,"参数total 不能为空");
  1002. }
  1003. //if($total<0){
  1004. // Db::rollback();
  1005. // return error_show(1005,"发票核销数据为不能为负值");
  1006. // }
  1007. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $customer['invoice_addr'] = $post['invoice_addr']:"";
  1008. $invoice=[];
  1009. isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  1010. isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  1011. isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  1012. $post['invoice_bankNo']:"";
  1013. isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  1014. isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  1015. $post['invoice_mobile']:"";
  1016. isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  1017. $post['invoice_title']:"";
  1018. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  1019. // return error_show(1004,"企业信息联系电话格式错误");
  1020. // }
  1021. $invinfo['inv_value']=$total;
  1022. $invinfo['worder_fee']=$total;
  1023. $invinfo['wtrade_fee']=$total;
  1024. $invinfo['inv_in']=$companyNo;
  1025. $invinfo['inv_out']=$inv_out;
  1026. $invinfo['invoice_title'] = $invoice['invoice_title'];
  1027. $invinfo['invoice_addr'] = $invoice['invoice_addr'];
  1028. $invinfo['invoice_mobile'] = $invoice['invoice_mobile'];
  1029. $invinfo['invoice_code'] = $invoice['invoice_code'];
  1030. $invinfo['invoice_bank'] = $invoice['invoice_bank'];
  1031. $invinfo['invoice_bankNo'] = $invoice['invoice_bankNo'];
  1032. $invinfo['inv_type']=$inv_type;
  1033. $invinfo['inv_add']=$inv_add;
  1034. $invinfo['remark']=$remark;
  1035. $invinfo['updatetime']= date("Y-m-d H:i:s");
  1036. Db::startTrans();
  1037. try{
  1038. if(!empty($invoice) && $invoice!='') {
  1039. $invoice['updatetime'] = date("Y-m-d H:i:s");
  1040. $invoice['checkNo'] = $companyNo;
  1041. if ($inv_add == 1) {
  1042. $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  1043. if($cust){
  1044. Db::rollback();
  1045. return error_show(1005,"企业财务信息已存在");
  1046. }
  1047. $invoice['addtime'] = date("Y-m-d H:i:s");
  1048. Db::name('customer_invoice')->insert($invoice);
  1049. } else {
  1050. Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  1051. }
  1052. }
  1053. $invinsert = Db::name("invoice_pool")->save($invinfo);
  1054. if($invinsert){
  1055. Db::commit();
  1056. return app_show(0,"发票编辑成功");
  1057. }
  1058. Db::rollback();
  1059. return error_show(1004,"发票编辑失败");
  1060. }catch (\Exception $e){
  1061. Db::rollback();
  1062. return error_show(1004,$e->getMessage());
  1063. }
  1064. }
  1065. /**
  1066. * 保存更新的资源
  1067. *
  1068. * @param \think\Request $request
  1069. * @param int $id
  1070. * @return \think\Response
  1071. */
  1072. public function status( )
  1073. {
  1074. $post = $this->request->post();
  1075. $token = isset($post['token']) ? trim($post['token']) : "";
  1076. if ($token == "") {
  1077. return error_show(101, 'token不能为空');
  1078. }
  1079. $effetc = VerifyTokens($token);
  1080. if (!empty($effetc) && $effetc['code'] != 0) {
  1081. return error_show($effetc['code'], $effetc['message']);
  1082. }
  1083. $invNo=isset($post['invNo'])&& $post['invNo']!=""? trim($post['invNo']):"";
  1084. if($invNo==""){
  1085. return error_show(1004,"参数invNo 不能为空");
  1086. }
  1087. $invinfo = Db::name("invoice_pool")->where("invNo","=",$invNo)->find();
  1088. if(empty($invinfo)){
  1089. return error_show(1003,"未找到发票数据");
  1090. }
  1091. $status = isset($post['status'])&&$post['status']!==""? intval($post['status']):"";
  1092. $remark = isset($post['remark'])&&$post['remark']!==""? trim($post['remark']):"";
  1093. if($status===""){
  1094. return error_show(1005,"参数status 不能为空");
  1095. }
  1096. if($status==$invinfo['status']){
  1097. return error_show(1005,"状态已修改");
  1098. }
  1099. if(!in_array($status,[0,1,2,3,4,5])){
  1100. return error_show(1005,"参数status 无效");
  1101. }
  1102. if($status===0&&$invinfo['status']>=3){
  1103. return error_show(1005,"发票已通过审核无法取消申请!");
  1104. }
  1105. // if($status===1&&$invinfo['status']>=3){
  1106. // return error_show(1005,"发票已通过审核无法取消申请!");
  1107. // }
  1108. Db::startTrans();
  1109. if($status==4){
  1110. $invlist = isset($post['inv_info'])&&$post['inv_info']!="" ? $post['inv_info'] :"";
  1111. if($invlist==""){
  1112. Db::rollback();
  1113. return error_show(1004,"参数inv_info 不能为空");
  1114. }
  1115. }
  1116. $invinfo['status']=$status;
  1117. $invinfo['exam_remark']=$remark;
  1118. $invinfo['updatetime']=date("Y-m-d H:i:s");
  1119. $update =Db::name("invoice_pool")->save($invinfo);
  1120. if($update){
  1121. if($status==5) {
  1122. if ($invinfo['type_check'] == 1) {
  1123. $assinfo = Db::name("assoc_list")->where([["viceNo", "=", $invNo], ["status", "=", 1], ["source",
  1124. "=", 2], ["is_del", "=", "0"]])->find();
  1125. $assoc = Db::name("assoc_key")->where("assocNo", "=", $assinfo['assocNo'])->save
  1126. (["status" => 3, "updatetime" => date("Y-m-d H:i:s")]);
  1127. if ($assoc) {
  1128. $invinfo['aorder_fee'] += $assinfo['cancel_fee'];
  1129. $invinfo['order_used'] -= $assinfo['cancel_fee'];
  1130. $invinfo['is_order'] = 1;
  1131. $invinfo['order_status'] = $invinfo['worder_fee'] == 0 ? 3 : 2;
  1132. Db::name("invoice_pool")->save($invinfo);
  1133. $orderpool = Db::name("order_pool")->where([["orderNo", "=", $assinfo['codeNo']],
  1134. ["status", "=", 0], ["is_del", "=", 0]])->find();
  1135. $orderpool['status'] = 1;
  1136. $orderpool['inv_fee'] += $assinfo['cancel_total'];
  1137. $orderpool['inv_used'] -= $assinfo['cancel_total'];
  1138. $orderpool['inv_status'] = $orderpool['winv_fee'] == 0 ? 3 : 2;
  1139. $orderpool['updatetime'] = date("Y-m-d H:i:s");
  1140. $pool = Db::name("order_pool")->save($orderpool);
  1141. if ($pool) {
  1142. $qrd = $this->qrd_sure($assinfo['codeNo'], $assinfo['cancel_fee']);
  1143. if ($qrd) {
  1144. Db::commit();
  1145. return app_show(0, "状态修改成功");
  1146. }
  1147. }
  1148. }
  1149. Db::rollback();
  1150. return error_show(1005, "状态修改失败");
  1151. }
  1152. if ($invinfo['type_check'] == 3) {
  1153. $assoc = Db::name("assoc_list")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->select()->toArray();
  1154. if (!empty($assoc)) {
  1155. $taotal = 0;
  1156. foreach ($assoc as $value) {
  1157. $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=", $value["viceNo"]]])->find();
  1158. $temp['inv_fee'] += $value['cancel_fee'];
  1159. $temp['inv_used']-= $value['cancel_fee'];
  1160. $temp['inv_status']= $temp['winv_fee']==0 ? 3 :2;
  1161. $temp['updatetime'] = date("Y-m-d H:i:s");
  1162. $taotal = $value['cancel_total'];
  1163. Db::name("trade_pool")->save($temp);
  1164. }
  1165. $invinfo['atrade_fee'] += $taotal;
  1166. $invinfo['fund_used'] -= $taotal;
  1167. $invinfo['trade_status'] = $invinfo['wtrade_fee'] == 0 ? 3 : 2;
  1168. Db::name("invoice_pool")->save($invinfo);
  1169. $ass_up = Db::name("assoc_key")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->save(["status" => 3, "updatetime" => date("Y-m-d H:i:s")]);
  1170. if ($ass_up) {
  1171. Db::commit();
  1172. return app_show(0, "状态修改成功");
  1173. }
  1174. }
  1175. Db::rollback();
  1176. return error_show(1005, "状态修改失败");
  1177. }
  1178. }
  1179. Db::commit();
  1180. return app_show(0,"状态修改成功");
  1181. }else{
  1182. Db::rollback();
  1183. return error_show(1005,"状态修改失败");
  1184. }
  1185. }
  1186. /**
  1187. * 删除指定资源
  1188. *
  1189. * @param int $id
  1190. * @return \think\Response
  1191. */
  1192. public function delete()
  1193. {
  1194. $post = $this->request->post();
  1195. $token = isset($post['token']) ? trim($post['token']) : "";
  1196. if ($token == "") {
  1197. return error_show(101, 'token不能为空');
  1198. }
  1199. $effetc = VerifyTokens($token);
  1200. if (!empty($effetc) && $effetc['code'] != 0) {
  1201. return error_show($effetc['code'], $effetc['message']);
  1202. }
  1203. $invNo =isset($post['invNo']) && $post['invNo']!="" ? trim($post['invNo']):"";
  1204. if($invNo==""){
  1205. return error_show(1003,"参数invNo 不能为空");
  1206. }
  1207. $inv = Db::name("invoice_pool")->where("invNo","=",$invNo)->find();
  1208. if(empty($inv)){
  1209. return error_show(1004,"未找到发票数据");
  1210. }
  1211. if($inv['status']>2){
  1212. return error_show(1004,"财务审核已通过无法取消");
  1213. }
  1214. Db::startTrans();
  1215. if($inv['type_check']==1){
  1216. $assoc= Db::name("assoc_list")->where([["type","=",1],["is_del","=",0],["rela_form","=",1],["viceNo","=",
  1217. $invNo]])
  1218. ->find();
  1219. if(!empty($assoc)) {
  1220. $update = Db::name("order_pool")->where('orderNo', "=", $assoc['codeNo'])->save(['is_del' => 1,
  1221. "updatetime" => date("Y-m-d H:i:s")]);
  1222. if (!$update) {
  1223. Db::rollback();
  1224. return error_show(1004, "订单删除失败");
  1225. }
  1226. $ass_up = Db::name("assoc_key")->where("id", "=", $assoc['aid'])->save(["is_del" => 1, "updatetime" => date("Y-m-d H:i:s")]);
  1227. if (!$ass_up) {
  1228. Db::rollback();
  1229. return error_show(1004, "订单发票关联表删除失败");
  1230. }
  1231. $del= $this->qrd_delet($assoc['codeNo'],$assoc['cancel_total']);
  1232. if(!$del){
  1233. Db::rollback();
  1234. return error_show(1006,"确认单数据修改失败");
  1235. }
  1236. }
  1237. }
  1238. if($inv['type_check']==3){
  1239. $assoc= Db::name("assoc_list")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$invNo]])->select()->toArray();
  1240. if(!empty($assoc)) {
  1241. foreach ($assoc as $value){
  1242. $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=",$value["viceNo"]]])->find();
  1243. $temp['winv_fee'] += $value['cancel_fee'];
  1244. $temp['inv_used'] -= $value['cancel_fee'];
  1245. $temp['updatetime'] = date("Y-m-d H:i:s");
  1246. Db::name("trade_pool")->save($temp);
  1247. }
  1248. $ass_up = Db::name("assoc_key")->where([["type","=",2],["source","=",2],["is_del","=",0],["rela_form","=",4],["codeNo","=",$invNo]])->save(["is_del" => 1, "updatetime" => date("Y-m-d H:i:s")]);
  1249. if (!$ass_up) {
  1250. Db::rollback();
  1251. return error_show(1004, "订单发票关联表删除失败");
  1252. }
  1253. }
  1254. }
  1255. $inv['is_del']=1;
  1256. $inv['updatetime']=date("Y-m-d H:i:s");
  1257. $update = Db::name("invoice_pool")->save($inv);
  1258. if($update){
  1259. Db::commit();
  1260. return app_show(0,"取消申请成功");
  1261. }else{
  1262. Db::rollback();
  1263. return error_show(1003,"取消申请失败");
  1264. }
  1265. // return $update? app_show(0,"取消申请成功"):error_show(1003,"取消申请失败");
  1266. }
  1267. /**
  1268. * @return \think\response\Json|void
  1269. * @throws \think\db\exception\DataNotFoundException
  1270. * @throws \think\db\exception\DbException
  1271. * @throws \think\db\exception\ModelNotFoundException
  1272. * @throws \think\exception\DbException
  1273. */
  1274. public function InvoPost(){
  1275. $post = $this->request->post();
  1276. $token = isset($post['token']) ? trim($post['token']) : "";
  1277. if ($token == "") {
  1278. return error_show(101, 'token不能为空');
  1279. }
  1280. $effetc = VerifyTokens($token);
  1281. if (!empty($effetc) && $effetc['code'] != 0) {
  1282. return error_show($effetc['code'], $effetc['message']);
  1283. }
  1284. $invNo=isset($post['invNo'])&& $post['invNo']!=""? trim($post['invNo']):"";
  1285. if($invNo==""){
  1286. return error_show(1004,"参数invNo 不能为空");
  1287. }
  1288. $invinfo = Db::name("invoice_pool")->where("invNo","=",$invNo)->find();
  1289. if(empty($invinfo)){
  1290. return error_show(1003,"未找到发票数据");
  1291. }
  1292. $postcode = isset($post["code"])&&$post['code']!="" ? $post["code"] :"";
  1293. $postname = isset($post['company']) && $post['company']!="" ? $post['company']:"";
  1294. if ($postcode==""){
  1295. return error_show(1005,"参数code 不能为空");
  1296. }
  1297. if ($postname==""){
  1298. return error_show(1005,"参数company 不能为空");
  1299. }
  1300. // if($invinfo['status']!=4){
  1301. // return error_show(1005,"发票数据还未上传");
  1302. // }
  1303. $data=[
  1304. "postNo"=>$postcode,
  1305. "post_company"=>$postname,
  1306. "invNo"=>$invNo,
  1307. "contactor"=>"",
  1308. "mobile"=>"",
  1309. "status"=>1,
  1310. "addtime"=>date("y-m-d H:i:s"),
  1311. "updatetime"=>date("y-m-d H:i:s"),
  1312. ];
  1313. Db::startTrans();
  1314. $post= Db::name("inv_post")->insert($data);
  1315. if($post){
  1316. $invinfo['status']=5;
  1317. $invinfo["updatetime"]=date("Y-m-d H:i:s");
  1318. $sav= Db::name("invoice_pool")->save($invinfo);
  1319. if($sav){
  1320. if ($invinfo['type_check'] == 1) {
  1321. $assinfo = Db::name("assoc_list")->where([["viceNo", "=", $invNo], ["status", "=", 1], ["source",
  1322. "=", 2], ["is_del", "=", "0"]])->find();
  1323. $assoc = Db::name("assoc_key")->where("assocNo", "=", $assinfo['assocNo'])->save
  1324. (["status" => 3, "updatetime" => date("Y-m-d H:i:s")]);
  1325. if ($assoc) {
  1326. $invinfo['aorder_fee'] += $assinfo['cancel_fee'];
  1327. $invinfo['order_used'] -= $assinfo['cancel_fee'];
  1328. $invinfo['is_order'] = 1;
  1329. $invinfo['order_status'] = $invinfo['worder_fee'] == 0 ? 3 : 2;
  1330. Db::name("invoice_pool")->save($invinfo);
  1331. $orderpool = Db::name("order_pool")->where([["orderNo", "=", $assinfo['codeNo']],
  1332. ["status", "=", 0], ["is_del", "=", 0]])->find();
  1333. $orderpool['status'] = 1;
  1334. $orderpool['inv_fee'] += $assinfo['cancel_total'];
  1335. $orderpool['inv_used'] -= $assinfo['cancel_total'];
  1336. $orderpool['inv_status'] = $orderpool['winv_fee'] == 0 ? 3 : 2;
  1337. $orderpool['updatetime'] = date("Y-m-d H:i:s");
  1338. $pool = Db::name("order_pool")->save($orderpool);
  1339. if ($pool) {
  1340. $qrd = $this->qrd_sure($assinfo['codeNo'], $assinfo['cancel_fee']);
  1341. if ($qrd) {
  1342. Db::commit();
  1343. return app_show(0, "状态修改成功");
  1344. }
  1345. }
  1346. }
  1347. Db::rollback();
  1348. return error_show(1005, "状态修改失败");
  1349. }
  1350. if ($invinfo['type_check'] == 3) {
  1351. $assoc = Db::name("assoc_list")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->select()->toArray();
  1352. if (!empty($assoc)) {
  1353. $taotal = 0;
  1354. foreach ($assoc as $value) {
  1355. $temp = Db::name("trade_pool")->where([["is_del", "=", 0], ["traNo", "=", $value["viceNo"]]])->find();
  1356. $temp['inv_fee'] += $value['cancel_fee'];
  1357. $temp['inv_used']-= $value['cancel_fee'];
  1358. $temp['inv_status']= $temp['winv_fee']==0 ? 3 :2;
  1359. $temp['updatetime'] = date("Y-m-d H:i:s");
  1360. $taotal = $value['cancel_total'];
  1361. Db::name("trade_pool")->save($temp);
  1362. }
  1363. $invinfo['atrade_fee'] += $taotal;
  1364. $invinfo['fund_used'] -= $taotal;
  1365. $invinfo['trade_status'] = $invinfo['wtrade_fee'] == 0 ? 3 : 2;
  1366. Db::name("invoice_pool")->save($invinfo);
  1367. $ass_up = Db::name("assoc_key")->where([["type", "=", 2], ["source", "=", 2], ["is_del", "=", 0], ["rela_form", "=", 4], ["codeNo", "=", $invNo]])->save(["status" => 3, "updatetime" => date("Y-m-d H:i:s")]);
  1368. if ($ass_up) {
  1369. Db::commit();
  1370. return app_show(0, "状态修改成功");
  1371. }
  1372. }
  1373. Db::rollback();
  1374. return error_show(1005, "状态修改失败");
  1375. }
  1376. Db::commit();
  1377. return app_show(0,"添加成功");
  1378. }else{
  1379. Db::rollback();
  1380. return error_show(1003,"添加失败");
  1381. }
  1382. }
  1383. Db::rollback();
  1384. return error_show(1003,"添加失败");
  1385. }
  1386. /**
  1387. * @return \think\response\Json|void
  1388. */
  1389. public function GetReceipt(){
  1390. $post = $this->request->post();
  1391. $token = isset($post['token']) ? trim($post['token']) : "";
  1392. if ($token == "") {
  1393. return error_show(101, 'token不能为空');
  1394. }
  1395. $effetc = VerifyTokens($token);
  1396. if (!empty($effetc) && $effetc['code'] != 0) {
  1397. return error_show($effetc['code'], $effetc['message']);
  1398. }
  1399. $invNo=isset($post['inv_in'])&& $post['inv_in']!=""? trim($post['inv_in']):"";
  1400. if($invNo==""){
  1401. return error_show(1004,"参数inv_in 不能为空");
  1402. }
  1403. $type = isset($post['type_check'])&& $post['type_check']!=""? trim($post['type_check']) : 2;
  1404. $condition = [["inv_in","=",$invNo],["type_check","=",$type],["lstatus","=",1]];
  1405. $list = Db::name("inv_list")->where($condition)->select();
  1406. return app_show(0,"获取成功",$list);
  1407. }
  1408. /**
  1409. * 显示资源列表
  1410. *
  1411. * @return \think\Response
  1412. */
  1413. public function recepitlist()
  1414. {
  1415. $post = $this->request->post();
  1416. $token = isset($post['token']) ? trim($post['token']) : "";
  1417. if ($token == "") {
  1418. return error_show(101, 'token不能为空');
  1419. }
  1420. $effetc = VerifyTokens($token);
  1421. if (!empty($effetc) && $effetc['code'] != 0) {
  1422. return error_show($effetc['code'], $effetc['message']);
  1423. }
  1424. $condition = [['is_del',"=",0],['refund_status',"=",0]];
  1425. $guserinfo =GetUserInfo($token);
  1426. if(isset($guserinfo['code']) && $guserinfo['code']!=0){
  1427. return error_show($guserinfo['code'],$guserinfo['message']);
  1428. }
  1429. $check = checkRole($guserinfo['data']['roleid'],55);
  1430. if($check){
  1431. $condition[]=["apply_id","=", $guserinfo['data']['id']];
  1432. }
  1433. $no = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
  1434. if ($no != "") {
  1435. $condition[] = ["inv_in", "=", "{$no}"];
  1436. }
  1437. $invNo = isset($post['invNo']) && $post['invNo'] != "" ? trim($post['invNo']) : "";
  1438. if ($invNo != "") {
  1439. $condition[] = ["invNo", "like", "%{$invNo}%"];
  1440. }
  1441. $type_check = isset($post['type_check']) && $post['type_check'] != "" ? $post['type_check'] : "";
  1442. if ($type_check != "") {
  1443. $condition[] = ["type_check", "=", "{$type_check}"];
  1444. }
  1445. $status = isset($post['status']) && $post['status'] != "" ? $post['status'] : "";
  1446. if ($status != "") {
  1447. $condition[] = ["status", "=", "{$status}"];
  1448. }
  1449. $order_status = isset($post['order_status']) && $post['order_status'] != "" ? intval($post['order_status']) :
  1450. "";
  1451. if ($order_status != "") {
  1452. if($order_status==4){
  1453. $condition[] = ["order_status", "in", [1,2]];
  1454. }else{
  1455. $condition[] = ["order_status", "=", "{$order_status}"];
  1456. }
  1457. // $condition[] = ["order_status", "=", "{$order_status}"];
  1458. }
  1459. $trade_status = isset($post['trade_status']) && $post['trade_status'] != "" ? intval($post['trade_status']) : "";
  1460. if ($trade_status != "") {
  1461. if($trade_status==4){
  1462. $condition[] = ["trade_status", "in", [1,2]];
  1463. }else{
  1464. $condition[] = ["trade_status", "=", "{$trade_status}"];
  1465. }
  1466. }
  1467. $total_low = isset($post['total_low']) && $post['total_low'] != "" ? $post['total_low'] : "";
  1468. if ($total_low != "") {
  1469. $condition[] = ["inv_value", ">=", "{$total_low}"];
  1470. }
  1471. $total_up = isset($post['total_up']) && $post['total_up'] != "" ? $post['total_up'] : "";
  1472. if ($total_up != "") {
  1473. $condition[] = ["inv_value", "<=", "{$total_up}"];
  1474. }
  1475. $starttime = isset($post['starttime']) && $post['starttime'] != "" ? $post['starttime'] : "";
  1476. if ($starttime != "") {
  1477. $condition[] = ["addtime", ">=", "{$starttime}"];
  1478. }
  1479. $endtime = isset($post['endtime']) && $post['endtime'] != "" ? $post['endtime'] : "";
  1480. if ($endtime != "") {
  1481. $condition[] = ["addtime", "<=", "{$endtime}"];
  1482. }
  1483. $type = isset($post['type_check'])&& $post['type_check']!=""? $post['type_check'] : "";
  1484. if ($type != "") {
  1485. $condition[] = ["type_check", "=", "{$type}"];
  1486. }
  1487. $page = isset($post['page']) && $post['page'] != "" ? intval($post['page']) : 1;
  1488. $size = isset($post['size']) && $post['size'] != "" ? intval($post['size']) : 10;
  1489. $count = Db::name("invoice_pool")->where($condition)->count();
  1490. $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
  1491. $page = $page >= $total ? intval($total) : $page;
  1492. $list = Db::name("invoice_pool")->where($condition)->order("addtime desc")->page(intval($page), $size)->select();
  1493. $data=[];
  1494. foreach ($list as $value){
  1495. $customer= Db::name("customer_info")->where("companyNo","=",$value['inv_in'])->find();
  1496. $value['company'] = isset($customer['companyName']) ? $customer['companyName']:"";
  1497. $value['contactor'] = isset($customer['contactor']) ? $customer['contactor']:"";
  1498. // $value['invoice_bankNo'] = isset($customer['invoice_bankNo']) ? $customer['invoice_bankNo']:"";
  1499. $value['mobile'] = isset($customer['mobile']) ? $customer['mobile']:"";
  1500. $out = Db::name('company_info')->where('companyNo',"=",$value['inv_out'])->find();
  1501. $value['kp_company'] =isset($out['company_name']) ? $out['company_name']:"";
  1502. $data[]=$value;
  1503. }
  1504. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1505. }
  1506. /**
  1507. * @param $orderNo
  1508. * @param $balance
  1509. * @return bool
  1510. * @throws \think\db\exception\DataNotFoundException
  1511. * @throws \think\db\exception\DbException
  1512. * @throws \think\db\exception\ModelNotFoundException
  1513. */
  1514. private function updateQrd($orderNo,$balance)
  1515. {
  1516. $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
  1517. if (empty($orderinfo)) {
  1518. return false;
  1519. }
  1520. $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
  1521. if (empty($orderlist)) {
  1522. return false;
  1523. }
  1524. foreach ($orderlist as $value) {
  1525. if($balance==0){
  1526. break;
  1527. }
  1528. if($value['winv_fee'] == 0){
  1529. continue;
  1530. }
  1531. $order_fee=0;
  1532. if($value['winv_fee']<=$balance){
  1533. $order_fee = $value['winv_fee'];
  1534. $balance -=$value['winv_fee'];
  1535. $value['inv_fee'] += $value['winv_fee'];
  1536. $value['winv_fee'] = 0;
  1537. }else{
  1538. $value['inv_fee'] += $balance;
  1539. $value['winv_fee']-= $balance;
  1540. $order_fee = $balance;
  1541. $balance=0;
  1542. }
  1543. $value['updatetime'] = date("Y-m-d H:i:s");
  1544. $orde = Db::name("order_info")->save($value);
  1545. if($orde===false){
  1546. return false;
  1547. }
  1548. $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
  1549. if (($order_fee <= $qrdinfo['Number1618249205231'])||($order_fee <=
  1550. $qrdinfo['Number1618249202608']&&$orderinfo['type']==4)) {
  1551. $qrdinfo['inving_fee'] += $order_fee;
  1552. if($orderinfo['type']==4){
  1553. $qrdinfo['Number1618249202608'] -= $order_fee;
  1554. }else{
  1555. $qrdinfo['Number1618249205231'] -= $order_fee;
  1556. $qrdinfo['number1618249258956'] += $value['good_num'];
  1557. }
  1558. // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
  1559. $qinfo = Db::name("qrd_info")->save($qrdinfo);
  1560. if ($qinfo) {
  1561. $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
  1562. if(($qrdp['winv_fee'] >= $order_fee)|| ($qrdp['ainv_fee'] >= $order_fee &&$orderinfo['type']==4
  1563. )) {
  1564. if($orderinfo['type']==4){
  1565. $qrdp['ainv_fee'] -= $order_fee;
  1566. $qrdp['inv_fee'] += $order_fee;
  1567. }else{
  1568. $qrdp['winv_fee'] -= $order_fee;
  1569. $qrdp['inv_fee'] += $order_fee;
  1570. }
  1571. // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
  1572. $qrd = Db::name("qrd")->save($qrdp);
  1573. if(!$qrd){
  1574. return false;
  1575. }
  1576. }else {
  1577. return false;
  1578. }
  1579. }else {
  1580. return false;
  1581. }
  1582. } else {
  1583. return false;
  1584. }
  1585. }
  1586. return true;
  1587. }
  1588. /**
  1589. * @param $orderNo
  1590. * @param $balance
  1591. * @return bool
  1592. * @throws \think\db\exception\DataNotFoundException
  1593. * @throws \think\db\exception\DbException
  1594. * @throws \think\db\exception\ModelNotFoundException
  1595. */
  1596. private function qrd_sure($orderNo,$balance){
  1597. $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 0]])->find();
  1598. if (empty($orderinfo)) {
  1599. return false;
  1600. }
  1601. $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
  1602. if (empty($orderlist)) {
  1603. return false;
  1604. }
  1605. foreach ($orderlist as $value) {
  1606. if($balance==0){
  1607. break;
  1608. }
  1609. if($value['inv_fee'] == 0){
  1610. continue;
  1611. }
  1612. $order_fee=0;
  1613. if($value['inv_fee']<=$balance){
  1614. $order_fee = $value['inv_fee'];
  1615. $balance -=$value['inv_fee'];
  1616. $value['ainv_fee'] += $value['inv_fee'];
  1617. $value['inv_fee'] = 0;
  1618. }else{
  1619. $value['ainv_fee'] += $balance;
  1620. $value['inv_fee']-= $balance;
  1621. $order_fee = $balance;
  1622. $balance=0;
  1623. }
  1624. $value['updatetime'] = date("Y-m-d H:i:s");
  1625. $orde = Db::name("order_info")->save($value);
  1626. if($orde===false){
  1627. return false;
  1628. }
  1629. $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
  1630. if (($order_fee <= $qrdinfo['inving_fee'])||($order_fee <= $qrdinfo['inving_fee']&&$orderinfo['type']==4
  1631. )) {
  1632. if($orderinfo['type']==4 ){
  1633. $qrdinfo['inving_fee'] -= $order_fee;
  1634. //$qrdinfo['number1618249149738'] -= $order_fee;
  1635. $qrdinfo['Number1618249205231'] += $order_fee;
  1636. //$qrdinfo['number1618249258956'] += $value['good_num'];
  1637. $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249202608']>0 ? "2" : "1";
  1638. }else{
  1639. $qrdinfo['inving_fee'] -= $order_fee;
  1640. //$qrdinfo['number1618249149738'] -= $order_fee;
  1641. $qrdinfo['Number1618249202608'] += $order_fee;
  1642. //$qrdinfo['number1618249258956'] += $value['good_num'];
  1643. $qrdinfo['ShortText1618559274859'] = $qrdinfo['Number1618249205231']>0 ? "2" : "3";
  1644. }
  1645. $qinfo = Db::name("qrd_info")->save($qrdinfo);
  1646. if ($qinfo) {
  1647. $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
  1648. if ($qrdp['inv_fee'] >= $order_fee || ($qrdp['inv_fee'] >= $order_fee &&$orderinfo['type']==4
  1649. )) {
  1650. if($orderinfo['type']==4){
  1651. $qrdp['inv_fee'] -= $order_fee;
  1652. $qrdp['winv_fee'] += $order_fee;
  1653. $qrdp['inv_status'] = $qrdp['ainv_fee'] == 0 ? 1 : 2;
  1654. }else{
  1655. $qrdp['inv_fee'] -= $order_fee;
  1656. $qrdp['ainv_fee'] += $order_fee;
  1657. $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
  1658. }
  1659. $qrd = Db::name("qrd")->save($qrdp);
  1660. if(!$qrd){
  1661. return false;
  1662. }
  1663. }else {
  1664. return false;
  1665. }
  1666. }else {
  1667. return false;
  1668. }
  1669. } else {
  1670. return false;
  1671. }
  1672. }
  1673. return true;
  1674. }
  1675. /**
  1676. * @param $orderNo
  1677. * @param $balance
  1678. * @return bool
  1679. * @throws \think\db\exception\DataNotFoundException
  1680. * @throws \think\db\exception\DbException
  1681. * @throws \think\db\exception\ModelNotFoundException
  1682. */
  1683. private function qrd_delet($orderNo,$balance){
  1684. $orderinfo = Db::name("order_pool")->where([["orderNo", "=", $orderNo], ["is_del", "=", 1]])->find();
  1685. if (empty($orderinfo)) {
  1686. return false;
  1687. }
  1688. $orderlist = Db::name("order_info")->where([["orderNo", "=", $orderNo], ["status", "=", 1]])->select();
  1689. if (empty($orderlist)) {
  1690. return false;
  1691. }
  1692. foreach ($orderlist as $value) {
  1693. if($balance==0){
  1694. break;
  1695. }
  1696. if($value['inv_fee'] == 0){
  1697. continue;
  1698. }
  1699. $order_fee=0;
  1700. if($value['inv_fee']<=$balance){
  1701. $order_fee = $value['inv_fee'];
  1702. $balance -=$value['inv_fee'];
  1703. $value['winv_fee'] += $value['inv_fee'];
  1704. $value['inv_fee'] = 0;
  1705. }else{
  1706. $value['inv_fee'] -= $balance;
  1707. $value['winv_fee']+= $balance;
  1708. $order_fee = $balance;
  1709. $balance=0;
  1710. }
  1711. $value['updatetime'] = date("Y-m-d H:i:s");
  1712. $orde = Db::name("order_info")->save($value);
  1713. if(!$orde){
  1714. return false;
  1715. }
  1716. $qrdinfo = Db::name("qrd_info")->where([["sequenceNo", "=", $value['goodNo']]])->field("id,ShortText1617650701648,Number1618249202608,Number1618249205231,Number1618249146997,number1618249149738,ShortText1618559043560,number1618249258956,ShortText1618559274859,inving_fee,paying_fee")->find();
  1717. if ($order_fee <= $qrdinfo['inving_fee']) {
  1718. $qrdinfo['inving_fee'] -= $order_fee;
  1719. if($orderinfo['type']==4){
  1720. $qrdinfo['Number1618249202608'] += $order_fee;
  1721. // $qrdinfo['number1618249258956'] += $value['good_num'];
  1722. }else{
  1723. $qrdinfo['Number1618249205231'] += $order_fee;
  1724. $qrdinfo['number1618249258956'] -= $value['good_num'];
  1725. }
  1726. // $qrdinfo['ShortText1618559043560'] = $value['total_fee'] < $qrdinfo['number1618249149738'] ? "2" : "3";
  1727. $qinfo = Db::name("qrd_info")->save($qrdinfo);
  1728. if ($qinfo) {
  1729. $qrdp = Db::name("qrd")->where([["sequenceNo", "=", $qrdinfo['ShortText1617650701648']]])->find();
  1730. if ($qrdp['inv_fee'] >= $order_fee) {
  1731. if($orderinfo['type']==4){
  1732. $qrdp['ainv_fee'] += $order_fee;
  1733. }else{
  1734. $qrdp['winv_fee'] += $order_fee;
  1735. }
  1736. $qrdp['inv_fee'] -= $order_fee;
  1737. // $qrdp['inv_status'] = $qrdp['winv_fee'] == 0 ? 3 : 2;
  1738. $qrd = Db::name("qrd")->save($qrdp);
  1739. if(!$qrd){
  1740. return false;
  1741. }
  1742. }else {
  1743. return false;
  1744. }
  1745. }else {
  1746. return false;
  1747. }
  1748. } else {
  1749. return false;
  1750. }
  1751. }
  1752. return true;
  1753. }
  1754. /**
  1755. * @return \think\response\Json|void
  1756. * @throws \think\db\exception\DataNotFoundException
  1757. * @throws \think\db\exception\DbException
  1758. * @throws \think\db\exception\ModelNotFoundException
  1759. * @throws \think\exception\DbException
  1760. */
  1761. public function DownReceipt(){
  1762. $post = $this->request->post();
  1763. $token = isset($post['token']) ? trim($post['token']) : "";
  1764. if ($token == "") {
  1765. return error_show(101, 'token不能为空');
  1766. }
  1767. $effetc = VerifyTokens($token);
  1768. if (!empty($effetc) && $effetc['code'] != 0) {
  1769. return error_show($effetc['code'], $effetc['message']);
  1770. }
  1771. $condition=[["type_check","=",1],["is_del","=",0],["status","=",3]];
  1772. $inid = isset($post['invid'])&& $post['invid']!="" ? $post['invid'] :"";
  1773. if($inid!=""){
  1774. $condition[]=['id',"in",$inid];
  1775. }
  1776. $invice = Db::name("invoice_pool")->where($condition)->select()->toArray();
  1777. if (empty($invice)){
  1778. return error_show(1003,"未找到数据");
  1779. }
  1780. $data=[];
  1781. foreach ($invice as $value){
  1782. $temp=[];
  1783. $orderNo = Db::name("assoc_list")->where([["rela_form","=",1],["is_del","=",0],['viceNo',"=",$value['invNo']]])->find();
  1784. if(!$orderNo){
  1785. continue;
  1786. }
  1787. $good = Db::name("order_info")->where([['orderNo',"=",$orderNo['codeNo']],["status","=",1]])->select()->toArray();
  1788. if(empty($good)){
  1789. continue;
  1790. }
  1791. if(isset($value['inv_out'])&& $value['inv_out']!=''){
  1792. $invout = Db::name("company_info")->where([['companyNo',"=",$value['inv_out']]])->find();
  1793. }
  1794. foreach ($good as $val){
  1795. $qrd = Db::name("qrd_list")->where("sequenceNo","=",$val['goodNo'])->find();
  1796. $temp['invNo'] = $value['invNo'];
  1797. $temp['qrdNo'] = $val['qrdNo'];
  1798. $temp['depart'] = $qrd['bumen'];
  1799. $temp['apply_name'] =$value['apply_name'];
  1800. $temp['code'] ="";
  1801. $temp['invoice_title'] =$value['invoice_title'];
  1802. $temp['invoice_code'] =$value['invoice_code']." ";
  1803. $temp['invoice_addr'] =$value['invoice_addr'];
  1804. $temp['invoice_mobile'] =$value['invoice_mobile'];
  1805. $temp['invoice_bank'] =$value['invoice_bank'];
  1806. $temp['invoice_bankNo'] =$value['invoice_bankNo']." ";
  1807. $temp['company'] =$qrd['kehu'];
  1808. $temp['goodname'] =$qrd['goodname'];
  1809. $temp['tax'] =$qrd['taxPoint'];
  1810. $temp['inv_name'] =$val['remark'];
  1811. $temp['diff_weight'] =$qrd['diff_weight'];
  1812. $temp['diff_price'] =$qrd['diff_price'];
  1813. $temp['unit'] =$val['unit'];
  1814. $temp['num'] =$val['good_num'];
  1815. $temp['price'] =$val['price'];
  1816. $temp['total_fee'] =$val['total_fee'];
  1817. switch ($value['inv_type']){
  1818. case 1:
  1819. $temp['inv_type'] = "增值税专用发票";
  1820. break;
  1821. case 2:
  1822. $temp['inv_type'] = "增值税普通发票";
  1823. break;
  1824. case 3:
  1825. $temp['inv_type'] = "增值税电子专用发票";
  1826. break;
  1827. case 4:
  1828. $temp['inv_type'] = "增值税电子普通发票";
  1829. break;
  1830. default:
  1831. $temp['inv_type'] = "-";
  1832. break;
  1833. }
  1834. // $temp['inv_type'] = $value['inv_type']==1?"增值税专用发票": "增值税普通发票";
  1835. // $temp['inv_value'] =$value['inv_value'];
  1836. $temp['remark'] =$value['remark'];
  1837. $temp['kp_companyName'] = isset($invout['company_name']) ? $invout['company_name']:"";
  1838. $temp['kp_company_address'] = isset($invout['company_address']) ? $invout['company_address']:"";
  1839. $temp['kp_company_license'] = isset($invout['company_license']) ? $invout['company_license'].' ':"";
  1840. $temp['kp_bank_name'] = isset($invout['bank_name']) ? $invout['bank_name']:"";
  1841. $temp['kp_bankNo'] = isset($invout['bankNo']) ? $invout['bankNo'].' ':"";
  1842. $temp['kp_contector'] = isset($invout['contector']) ? $invout['contector']:"";
  1843. $temp['kp_mobile'] = isset($invout['mobile']) ? $invout['mobile'].' ':"";
  1844. $data[]=$temp;
  1845. }
  1846. }
  1847. if (empty($data)){
  1848. return error_show(1003,"未找到数据");
  1849. }
  1850. $header=[
  1851. "申请编号",
  1852. "公司订单号",
  1853. "申请部门(所属平台)",
  1854. "申请人",
  1855. "代码",
  1856. "发票开具全称",
  1857. "发票开具企业纳税识别号",
  1858. "发票开具企业地址",
  1859. "发票开具企业地址联系方式",
  1860. "发票开具企业收款银行",
  1861. "发票开具企业收款账户",
  1862. "分公司",
  1863. "采购商品名",
  1864. "税率",
  1865. "发票商品名",
  1866. "工差重量",
  1867. "工差金额",
  1868. "单位",
  1869. "数量",
  1870. "单价",
  1871. "总价",
  1872. "开票种类",
  1873. "备注说明",
  1874. '开票企业名称',
  1875. '开票企业地址',
  1876. '开票企业纳税号',
  1877. '开票企业银行名称',
  1878. '开票企业银行账户',
  1879. '开票企业法人',
  1880. '开票企业联系方式'
  1881. ];
  1882. $li = excelExport("待开票",$header,$data);
  1883. }
  1884. /**
  1885. * @return \think\response\Json|void
  1886. * @throws \think\db\exception\DataNotFoundException
  1887. * @throws \think\db\exception\DbException
  1888. * @throws \think\db\exception\ModelNotFoundException
  1889. * @throws \think\exception\DbException
  1890. */
  1891. public function ImportReceipt(){
  1892. $post = $this->request->post();
  1893. $token = isset($post['token']) ? trim($post['token']) : "";
  1894. if ($token == "") {
  1895. return error_show(101, 'token不能为空');
  1896. }
  1897. $effetc = VerifyTokens($token);
  1898. if (!empty($effetc) && $effetc['code'] != 0) {
  1899. return error_show($effetc['code'], $effetc['message']);
  1900. }
  1901. $invlist = isset($post['data'])&& $post['data']!="" ? $post['data'] :"";
  1902. if($invlist==""){
  1903. return error_show(1005, '参数data 不能为空');
  1904. }
  1905. $list=[];
  1906. $total =[];
  1907. foreach ($invlist as $key=>$value){
  1908. if($value['invNo']==""){
  1909. return error_show(1005,"第".($key+1)."行缺少发票申请编号数据");
  1910. }
  1911. if($value["inv_type"]===""){
  1912. return error_show(1005,"第".($key+1)."行缺少发票类型数据");
  1913. }
  1914. if($value["inv_code"]==""){
  1915. return error_show(1005,"第".($key+1)."行缺少发票代码数据");
  1916. }
  1917. if($value["inv_number"]==""){
  1918. return error_show(1005,"第".($key+1)."行缺少发票号码数据");
  1919. }
  1920. if($value["inv_total"]==""){
  1921. return error_show(1005,"第".($key+1)."行缺少发票金额数据");
  1922. }
  1923. if($value["createtime"]==""){
  1924. return error_show(1005,"第".($key+1)."行缺少发票开票日期数据");
  1925. }
  1926. !isset($total[$value['invNo']]) ? $total[$value['invNo']]['total']=0:"";
  1927. // $inv=Db::name("invoice_list")->where([["inv_code","=",$value['inv_code']],["inv_number","=",$value['inv_number']],["is_del","=",0]])->find();
  1928. // if($inv){
  1929. // return error_show(1005,"第".($key+1)."行发票已存在");
  1930. // }
  1931. $temp=[];
  1932. $temp['invNo'] = $value["invNo"];
  1933. $temp['inv_type'] = $value['inv_type'];
  1934. $temp['inv_code'] = $value['inv_code'];
  1935. $temp['inv_number'] = $value['inv_number'];
  1936. $temp['inv_total'] = $value['inv_total'];
  1937. $temp['createtime'] = $value['createtime'];
  1938. $temp['status'] = 1;
  1939. $temp['is_del'] = 0;
  1940. $temp['addtime'] = date("Y-m-d H:i:s");
  1941. $temp['updatetime'] = date("Y-m-d H:i:s");
  1942. $total[$value["invNo"]]['total']+=$value['inv_total'];
  1943. $list[]=$temp;
  1944. }
  1945. Db::startTrans();
  1946. try{
  1947. foreach ($total as $key=>$value){
  1948. $inpool = Db::name("invoice_pool")->where([["invNo","=",$key],["is_del","=",0]])->find();
  1949. $invtotal=Db::name("invoice_list")->where([["invNo","=",$key],["is_del","=",0]])->sum('inv_total');
  1950. if($inpool['inv_value']!=$value['total']+$invtotal){
  1951. Db::rollback();
  1952. if($inpool['inv_value']>$value['total']+$invtotal){
  1953. return error_show(1005,"发票上传数据{$key}不足票面总额");
  1954. }else{
  1955. return error_show(1005,"发票上传数据{$key}超出票面总额");
  1956. }
  1957. }
  1958. $up =Db::name("invoice_pool")->where([["invNo","=",$key],["is_del","=",0]])->save(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
  1959. if(!$up){
  1960. Db::rollback();
  1961. return error_show(1005,"发票状态更新失败");
  1962. }
  1963. }
  1964. $insert = Db::name("invoice_list")->insertAll($list);
  1965. if(!$insert){
  1966. Db::rollback();
  1967. return error_show(1005,"发票数据录入失败");
  1968. }else{
  1969. Db::commit();
  1970. return app_show(0,"发票数据录入成功");
  1971. }
  1972. }catch (\Exception $e){
  1973. Db::rollback();
  1974. return error_show(1005,$e->getMessage());
  1975. }
  1976. }
  1977. public function RefundAdd()
  1978. {
  1979. $post = $this->request->post();
  1980. $token = isset($post['token']) ? trim($post['token']) : "";
  1981. if ($token == "") {
  1982. return error_show(101, 'token不能为空');
  1983. }
  1984. $effetc = VerifyTokens($token);
  1985. if (!empty($effetc) && $effetc['code'] != 0) {
  1986. return error_show($effetc['code'], $effetc['message']);
  1987. }
  1988. // $customer_w = isset($post['customer'])&& $post['customer']!='' ? $post['customer'] : "";
  1989. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=""?trim($post['companyNo']):"";
  1990. $inv_type = isset($post['inv_type'])&&$post['inv_type']!=""?trim($post['inv_type']):1;
  1991. // $inv_add = isset($post['inv_add'])&&$post['inv_add']!=""?trim($post['inv_add']):"0";
  1992. $remark = isset($post['remark'])&&$post['remark']!=""?trim($post['remark']):"";
  1993. $userinfo = GetUserInfo($token);
  1994. $username="";
  1995. if($companyNo==""){
  1996. return error_show(1004,"参数companyNo 不能为空");
  1997. }
  1998. if(isset($userinfo['code'])&&$userinfo['code']==0){
  1999. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname']: "";
  2000. }
  2001. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  2002. if(empty($customer)){
  2003. return error_show(1004,"未找到客户企业信息");
  2004. }
  2005. $invoice=[];
  2006. // isset($post['invoice_addr'])&& $post['invoice_addr']!='' ? $invoice['invoice_addr'] = $post['invoice_addr']:"";
  2007. // isset($post['invoice_bank'])&& $post['invoice_bank']!='' ? $invoice['invoice_bank'] = $post['invoice_bank']:"";
  2008. // isset($post['invoice_bankNo'])&& $post['invoice_bankNo']!='' ? $invoice['invoice_bankNo'] =
  2009. // $post['invoice_bankNo']:"";
  2010. // isset($post['invoice_code'])&& $post['invoice_code']!='' ? $invoice['invoice_code'] = $post['invoice_code']:"";
  2011. // isset($post['invoice_mobile'])&& $post['invoice_mobile']!='' ? $invoice['invoice_mobile'] =
  2012. // $post['invoice_mobile']:"";
  2013. // isset($post['invoice_title'])&& $post['invoice_title']!='' ? $invoice['invoice_title'] =
  2014. // $post['invoice_title']:"";
  2015. // if(!checkTel($invoice['invoice_mobile'])&&!checkMobile($invoice['invoice_mobile'])){
  2016. // return error_show(1004,"企业信息联系电话格式错误");
  2017. // }
  2018. $total = isset($post['total'])&&$post['total']!=""?$post['total']:"";
  2019. if($total==""){
  2020. return error_show(1004,"参数total 不能为空");
  2021. }
  2022. Db::startTrans();
  2023. try{
  2024. // if(!empty($invoice) && $invoice!='') {
  2025. // $invoice['updatetime'] = date("Y-m-d H:i:s");
  2026. // $invoice['checkNo'] = $companyNo;
  2027. // if ($inv_add == 1) {
  2028. // $cust = Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->find();
  2029. // if($cust){
  2030. // Db::rollback();
  2031. // return error_show(1005,"企业财务信息已存在");
  2032. // }
  2033. // $invoice['addtime'] = date("Y-m-d H:i:s");
  2034. // Db::name('customer_invoice')->insert($invoice);
  2035. // } else {
  2036. // Db::name('customer_invoice')->where('invoice_code', "=", $invoice['invoice_code'])->save($invoice);
  2037. // }
  2038. // }
  2039. $invNo = makeNo("INV");
  2040. $inv = [
  2041. "invNo" => $invNo,
  2042. "inv_value" => $total,
  2043. "inv_out" => "",
  2044. "inv_in" => $companyNo,
  2045. "apply_id" =>$effetc['data']['user']['id'],
  2046. "apply_name" => $username,
  2047. "status" => 0,
  2048. "trade_status" => 1,
  2049. "order_status" => 1,
  2050. "worder_fee"=>$total,
  2051. "wtrade_fee"=>$total,
  2052. "invoice_title" => "",
  2053. "invoice_addr" => "",
  2054. "invoice_mobile" => "",
  2055. "invoice_code" => "",
  2056. "invoice_bank" => "",
  2057. "invoice_bankNo" => "",
  2058. "inv_add" => 0,
  2059. "inv_type"=>$inv_type,
  2060. "type_check"=>5,
  2061. "is_order"=>0,
  2062. "remark"=>$remark,
  2063. "addtime" => date("Y-m-d H:i:s"),
  2064. "updatetime" => date("Y-m-d H:i:s")
  2065. ];
  2066. $invinsert = Db::name("invoice_pool")->insert($inv);
  2067. if($invinsert){
  2068. Db::commit();
  2069. return app_show(0,"发票创建成功");
  2070. }
  2071. Db::rollback();
  2072. return error_show(1004,"发票新建失败");
  2073. }catch (\Exception $e){
  2074. Db::rollback();
  2075. return error_show(1004,$e->getMessage());
  2076. }
  2077. }
  2078. /**
  2079. * @return \think\response\Json|void
  2080. * @throws \think\db\exception\DataNotFoundException
  2081. * @throws \think\db\exception\DbException
  2082. * @throws \think\db\exception\ModelNotFoundException
  2083. * @throws \think\exception\DbException
  2084. */
  2085. public function SaveRefundInv(){
  2086. $post = $this->request->post();
  2087. $token = isset($post['token']) ? trim($post['token']) : "";
  2088. if ($token == "") {
  2089. return error_show(101, 'token不能为空');
  2090. }
  2091. $effetc = VerifyTokens($token);
  2092. if (!empty($effetc) && $effetc['code'] != 0) {
  2093. return error_show($effetc['code'], $effetc['message']);
  2094. }
  2095. $invNo = isset($post['invNo']) && $post['invNo']!="" ? $post['invNo']:"";
  2096. if($invNo==""){
  2097. return error_show(1004,"参数invNo 不能为空");
  2098. }
  2099. $companyNo = isset($post['companyNo']) && $post['companyNo']!="" ? $post['companyNo']:"";
  2100. if($companyNo==""){
  2101. return error_show(1004,"参数companyNo 不能为空");
  2102. }
  2103. $invfo = Db::name("invoice_pool")->where([["invNo","=",$invNo],["is_del","=",0]])->find();
  2104. if(empty($invfo)){
  2105. return error_show(1005,"未找到发票数据");
  2106. }
  2107. // $total_fee = isset($post['total_fee'])&&$post['total_fee']!="" ? $post['total_fee']:"";
  2108. // if($total_fee==""){
  2109. // return error_show(1004,"参数total_fee 不能为空");
  2110. // }
  2111. // if($trade['balance']<$total_fee){
  2112. // return error_show(1005,"资金余额不足");
  2113. // }
  2114. $refundid = isset($post['refundid']) && $post['refundid']!="" ? $post['refundid'] :"";
  2115. if($refundid==""){
  2116. return error_show(1006,"参数refundid 不能为空");
  2117. }
  2118. $refund =Db::name("refund")->where([["is_del","=",0],['refund_status',"=",3],['id',"in",$refundid]])->select()->toArray();
  2119. if(empty($refund)){
  2120. return error_show(1006,"退款资金数据未找到");
  2121. }
  2122. $customer = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  2123. if(empty($customer)){
  2124. return error_show(1005,"未找到用户数据");
  2125. }
  2126. $refund_fee = array_sum(array_column($refund,"refund_fee"));
  2127. if($refund_fee!=$invfo['inv_value']){
  2128. return error_show(1005,"发票额度和退票额度不符");
  2129. }
  2130. // if($refund_fee<$trade['balance']){
  2131. // return error_show(1005,"资金退款余额不足");
  2132. // }
  2133. Db::startTrans();
  2134. try{
  2135. $invfo['inv_in'] = $companyNo;
  2136. $invfo['updatetime'] = date("Y-m-d H:i:s");
  2137. $tra = Db::name("invoice_pool")->save($invfo);
  2138. if($tra){
  2139. foreach ($refund as $value){
  2140. $value['backNo']= $invfo['invNo'];
  2141. $value['back_fee']= $value['refund_fee'];
  2142. $value['refund_status']= 4;
  2143. $value['updatetime']= date("Y-m-d H:i:s");
  2144. $ref=Db::name("refund")->save($value);
  2145. if($ref){
  2146. $tadpool = Db::name("invoice_pool")->where([["is_del","=",0],["invNo","=",
  2147. $value['relaNo']],['refund_status',"=",2]])->save(["refund_status"=>3,
  2148. "updatetime"=>date("Y-m-d H:i:s")]);
  2149. if(!$tadpool){
  2150. Db::rollback();
  2151. return error_show(1007,"资金退款状态更新失败");
  2152. }
  2153. }else{
  2154. Db::rollback();
  2155. return error_show(1007,"资金退款状态更新失败");
  2156. }
  2157. }
  2158. Db::commit();
  2159. return app_show(0,"欠款资金认领成功");
  2160. }
  2161. Db::rollback();
  2162. return error_show(1007,"资金退款认领失败");
  2163. }catch (\Exception $e){
  2164. Db::rollback();
  2165. return error_show(1006,$e->getMessage());
  2166. }
  2167. }
  2168. /**
  2169. * 退票关联订单
  2170. * @return \think\response\Json|void
  2171. * @throws \think\db\exception\DataNotFoundException
  2172. * @throws \think\db\exception\DbException
  2173. * @throws \think\db\exception\ModelNotFoundException
  2174. * @throws \think\exception\DbException
  2175. */
  2176. public function InvRefundCreate(){
  2177. $post = $this->request->post();
  2178. $token = isset($post['token']) ? trim($post['token']) : "";
  2179. if ($token == "") {
  2180. return error_show(101, 'token不能为空');
  2181. }
  2182. $effetc = VerifyTokens($token);
  2183. if (!empty($effetc) && $effetc['code'] != 0) {
  2184. return error_show($effetc['code'], $effetc['message']);
  2185. }
  2186. $guserinfo =GetUserInfo($token);
  2187. if(isset($guserinfo['code']) && $guserinfo['code']!=0){
  2188. return error_show($guserinfo['code'],$guserinfo['message']);
  2189. }
  2190. $invNo = isset($post['invNo'])&&$post['invNo']!="" ? trim($post['invNo']) : "";
  2191. if($invNo==""){
  2192. return error_show(1005,"参数invNo 不能为空");
  2193. }
  2194. $invinfo = Db::name("invoice_pool")->where([['invNo',"=",$invNo],['is_del',"=",0]])->find();
  2195. if(empty($invinfo)){
  2196. return error_show(1005,"未找到发票数据");
  2197. }
  2198. if($invinfo['type_check']!=5){
  2199. return error_show(1005,"数据不是退票数据");
  2200. }
  2201. $type = isset($post['type']) && $post['type']!=="" ? $post['type'] :1;
  2202. $trade = isset($post['trade'])&& $post['trade']!=="" ? $post['trade'] :"";
  2203. $good = isset($post['good'])&& $post['good']!=="" ? $post['good'] :"";
  2204. if($type==1 &&$trade==""){
  2205. return error_show(1005,"参数trade 不能为空");
  2206. }
  2207. if($type!=1 &&$good==""){
  2208. return error_show(1005,"参数good 不能为空");
  2209. }
  2210. $companyNo = isset($post['companyNo']) && $post['companyNo'] != "" ? trim($post['companyNo']) : "";
  2211. $userinfo = GetUserInfo($token);
  2212. $username = "";
  2213. if ($companyNo == "") {
  2214. return error_show(1004, "参数companyNo 不能为空");
  2215. }
  2216. if (isset($userinfo['code']) && $userinfo['code'] == 0) {
  2217. $username = isset($userinfo['data']['nickname']) ? $userinfo['data']['nickname'] : "";
  2218. }
  2219. $customer = Db::name("customer_info")->where("companyNo", "=", $companyNo)->find();
  2220. if (empty($customer)) {
  2221. return error_show(1004, "未找到客户企业信息");
  2222. }
  2223. Db::startTrans();
  2224. try{
  2225. if($type!=1) {
  2226. $orderinfo = [];
  2227. $orderNo = makeNo('ORD');
  2228. $total = 0;
  2229. $fund_fee = 0;
  2230. $wfund_fee = 0;
  2231. $inv_fee = 0;
  2232. $winv_fee = 0;
  2233. foreach ($good as $value) {
  2234. $temp = [];
  2235. $temp['orderNo'] = $orderNo;
  2236. $temp['goodNo'] = $value['goodNo'];
  2237. $goocp = Db::name("qrd_list")->where("sequenceNo", "=", $value['goodNo'])->find();
  2238. if (!$goocp) {
  2239. continue;
  2240. }
  2241. $temp['good_name'] = $goocp['goodname'];
  2242. $temp['qrdNo'] = $goocp['qrdNo'];
  2243. $temp['brand'] = $goocp['brand'];
  2244. $temp['unit'] = $goocp['unit'];
  2245. $temp['good_num'] = $value['num'];
  2246. $temp['price'] = $goocp['price'];
  2247. $temp['total_fee'] = $value['total_fee'];
  2248. $temp['wfund_fee'] = $value['total_fee'];
  2249. $temp['winv_fee'] = $value['total_fee'];
  2250. $temp['other_fee'] = 0;
  2251. $temp['status'] = 1;
  2252. $temp['remark'] = "";
  2253. $temp['addtime'] = date("Y-m-d H:i:s");
  2254. $temp['updatetime'] = date("Y-m-d H:i:s");
  2255. $total += $value['total_fee'];
  2256. $fund_fee += $value['apay_fee'];
  2257. $winv_fee += $value['winv_fee'];
  2258. $inv_fee += $value['ainv_fee'];
  2259. $wfund_fee += $value['wpay_fee'];
  2260. $orderinfo[] = $temp;
  2261. }
  2262. if ($total != $invinfo['worder_fee']) {
  2263. Db::rollback();
  2264. return error_show(1004, "商品总额于发票面额不符");
  2265. }
  2266. $orderins = Db::name("order_info")->insertAll($orderinfo);
  2267. if ($orderins) {
  2268. $order = [
  2269. "orderNo" => $orderNo,
  2270. "companyNo" => $companyNo,
  2271. "sales_id" => $effetc['data']['user']['id'],
  2272. "sales_name" => $username,
  2273. "total_amount" => $total,
  2274. "inv_status" => 1,
  2275. "fund_status" => 1,
  2276. "fund_fee" => 0,
  2277. "wfund_fee" => $total,
  2278. "inv_fee" => 0,
  2279. "winv_fee" => $total,
  2280. "status" => 0,
  2281. "type" => 3,
  2282. "addtime" => date("Y-m-d H:i:s"),
  2283. "updatetime" => date("Y-m-d H:i:s")
  2284. ];
  2285. $orderpool = Db::name("order_pool")->insert($order, true);
  2286. if ($orderpool > 0) {
  2287. $rela = [];
  2288. $assNo = makeNo("ASC");
  2289. $cancel = 0;
  2290. $balance = $invinfo["worder_fee"] > $total ? $total : $invinfo["worder_fee"];
  2291. $total -= $balance;
  2292. $sav = [
  2293. "worder_fee" => $invinfo['worder_fee'] - $balance,
  2294. "order_used" => $invinfo['order_used'] + $balance,
  2295. "is_order" => 1,
  2296. "updatetime" => date("Y-m-d H:i:s")
  2297. ];
  2298. Db::name("invoice_pool")->where([["invNo", "=", $invinfo['invNo']]])->save($sav);
  2299. $rela = [
  2300. "assocNo" => $assNo,
  2301. "viceNo" => $orderNo,
  2302. "vice_total" => $order['total_amount'],
  2303. "vice_fee" => $total,
  2304. "cancel_fee" => $balance,
  2305. "status" => 1,
  2306. "addtime" => date("Y-m-d H:i:s"),
  2307. "updatetime" => date("Y-m-d H:i:s")
  2308. ];
  2309. $assoc = Db::name("assoc_rela")->insert($rela);
  2310. if ($assoc) {
  2311. $data = [
  2312. "assocNo" => $assNo,
  2313. "companyNo" => $companyNo,
  2314. "type" => 1,
  2315. "rela_form" => 1,
  2316. "codeNo" => $invinfo["invNo"],
  2317. "total_fee" => $invinfo['inv_value'],
  2318. "balance" => $invinfo['worder_fee'] - $balance,
  2319. "cancel_total" => $balance,
  2320. "status" => 1,
  2321. "addtime" => date("Y-m-d H:i:s"),
  2322. "updatetime" => date("Y-m-d H:i:s")
  2323. ];
  2324. $realkey = Db::name("assoc_key")->insert($data);
  2325. if ($realkey) {
  2326. Db::name("invoice_pool")->where("invNo", "=", $invNo)->save(["wfund_fee" => $total, 'fund_used' => $balance, "updatetime" => date("Y-m-d H:i:s")]);
  2327. $qrdup = $this->updateQrd($orderNo, $balance);
  2328. if (!$qrdup) {
  2329. Db::rollback();
  2330. return error_show(1004, "新建关联申请失败");
  2331. }
  2332. Db::commit();
  2333. return app_show(0, "新建关联成功");
  2334. }
  2335. }
  2336. Db::rollback();
  2337. return error_show(1004, "新建关联申请失败");
  2338. }
  2339. }
  2340. Db::rollback();
  2341. return error_show(1004, "新建关联申请失败");
  2342. }else{
  2343. $rela = [];
  2344. $trade = 0;
  2345. $assNo = makeNo("ASC");
  2346. foreach ($trade as $value) {
  2347. $balance = $invinfo['wtrade_fee'] > $value['cancel'] ? $value['cancel'] : $invinfo['wtrade_fee'];
  2348. if ($invinfo['wtrade_fee'] <= 0) {
  2349. Db::rollback();
  2350. return error_show(1005, "资金总额大于发票额度");
  2351. }
  2352. if ($value['inv_fee'] <= 0) {
  2353. Db::rollback();
  2354. return error_show(1005, "发票核销金额为0");
  2355. }
  2356. $invinfo['wtrade_fee'] -= $balance;
  2357. $invinfo['fund_used'] += $balance;
  2358. $trade += $balance;
  2359. $rela[] = [
  2360. "assocNo" => $assNo,
  2361. "viceNo" => $value['traNo'],
  2362. "vice_total" => $value['total_fee'],
  2363. "vice_fee" => $value['inv_fee'] - $balance,
  2364. "cancel_fee" => $balance,
  2365. "status" => 1,
  2366. "addtime" => date("Y-m-d H:i:s"),
  2367. "updatetime" => date("Y-m-d H:i:s")
  2368. ];
  2369. $value['inv_fee'] -= $balance;
  2370. $value['inv_used'] += $balance;
  2371. $value['updatetime'] = date("Y-m-d H:i:s");
  2372. Db::name("trade_pool")->save($value);
  2373. }
  2374. $assoc = Db::name("assoc_rela")->insertAll($rela);
  2375. if ($assoc) {
  2376. $data = [
  2377. "assocNo" => $assNo,
  2378. "companyNo" => $companyNo,
  2379. "type" => 2,
  2380. "rela_form" => $type,
  2381. "codeNo" => $invinfo["invNo"],
  2382. "total_fee" => $invinfo['inv_value'],
  2383. "balance" => $invinfo['wtrade_fee'],
  2384. "cancel_total" => $trade,
  2385. "status" => 1,
  2386. "addtime" => date("Y-m-d H:i:s"),
  2387. "updatetime" => date("Y-m-d H:i:s")
  2388. ];
  2389. $realkey = Db::name("assoc_key")->insert($data);
  2390. if ($realkey) {
  2391. $invinfo['updatetime'] = date("Y-m-d H:i:s");
  2392. $order_up = Db::name("invoice_pool")->save($invinfo);
  2393. Db::commit();
  2394. return app_show(0, "新建关联成功");
  2395. }
  2396. }
  2397. Db::rollback();
  2398. return error_show(1004, "新建关联申请失败");
  2399. }
  2400. }catch (\Exception $e){
  2401. Db::rollback();
  2402. return error_show(1004,$e->getMessage());
  2403. }
  2404. }
  2405. }