Invoice.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\App;
  6. use think\facade\Log;
  7. use think\Request;
  8. use think\facade\Db;
  9. class Invoice extends BaseController
  10. {
  11. /**
  12. * 显示资源列表
  13. *
  14. * @return \think\Response
  15. */
  16. public function index()
  17. {
  18. $post =$this->request->post();
  19. $token = isset($post['token']) ? trim($post['token']) : "";
  20. if($token==""){
  21. return error_show(101,'token不能为空');
  22. }
  23. $effetc = VerifyTokens($token);
  24. if(!empty($effetc) && $effetc['code']!=0){
  25. return error_show($effetc['code'],$effetc['message']);
  26. }
  27. $sid = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :"";
  28. if($sid==""){
  29. return error_show(1004,"参数sid 不能为空");
  30. }
  31. $invoice = Db::name("invoice")->where([["payid","=",$sid]])->select();
  32. $list=["buyer"=>[],"seller"=>[],"invoice"=>[],"old"=>[]];
  33. foreach ($invoice as $key=>$value){
  34. $value['invoice_info']=isset($value['invoice_info'])&&$value['invoice_info']!="" ? json_decode
  35. ($value['invoice_info'],
  36. true) :[];
  37. $value['item_list']=isset($value['item_list'])&&$value['item_list']!="" ? json_decode
  38. ($value['item_list'],
  39. true) :[];
  40. if($value['status']==0){
  41. $list["buyer"]['buyer_name'] = $value['buyer_name'];
  42. $list["buyer"]['buyer_id'] = $value['buyer_id'];
  43. $list["buyer"]['buyer_address'] = $value['buyer_address'];
  44. $list["buyer"]['buyer_bank'] = $value['buyer_bank'];
  45. $list["seller"]['seller_name'] =$value["seller_name"];
  46. $list["seller"]['seller_id'] =$value["seller_id"];
  47. $list["seller"]['seller_address'] =$value["seller_address"];
  48. $list["seller"]['seller_bank'] =$value["seller_bank"];
  49. if($list["old"]==[]){
  50. $list["old"]['buyer_name'] = $value['invoice_info']['buyer_name'];
  51. $list["old"]['buyer_id'] = $value['invoice_info']['buyer_id'];
  52. $list["old"]['buyer_address'] = $value['invoice_info']['buyer_address'];
  53. $list["old"]['buyer_bank'] = $value['invoice_info']['buyer_bank'];
  54. $list["old"]['seller_name'] = $value['invoice_info']["seller_name"];
  55. $list["old"]['seller_id'] = $value['invoice_info']["seller_id"];
  56. $list["old"]['seller_address'] = $value['invoice_info']["seller_address"];
  57. $list["old"]['seller_bank'] = $value['invoice_info']["seller_bank"];
  58. }
  59. }
  60. $list["invoice"][]=$value;
  61. }
  62. return app_show(0,"获取成功",$list);
  63. }
  64. /**
  65. * 显示创建资源表单页.
  66. *
  67. * @return \think\Response
  68. */
  69. public function InvoiceAdd()
  70. {
  71. $post =$this->request->post();
  72. $token = isset($post['token']) ? trim($post['token']) : "";
  73. if($token==""){
  74. return error_show(101,'token不能为空');
  75. }
  76. $effetc = VerifyTokens($token);
  77. if(!empty($effetc) && $effetc['code']!=0){
  78. return error_show($effetc['code'],$effetc['message']);
  79. }
  80. $sid = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :"";
  81. if($sid==""){
  82. return error_show(1004,"参数sid 不能为空");
  83. }
  84. $image = isset($post['image'])&&is_array($post['image'])? $post['image'] :[];
  85. if(empty($image)){
  86. return error_show(1004,"参数image 不能为空");
  87. }
  88. $payifo = Db::name("pay_stages")->where("id","=",$sid)->find();
  89. if(empty($payifo)){
  90. return error_show(1004,"付款信息未找到");
  91. }
  92. if(!in_array($payifo['status'],[3,9])){
  93. return error_show(1004,"付款信息状态有误");
  94. }
  95. Db::startTrans();
  96. try{
  97. $data=[];
  98. foreach ($image as $value){
  99. $temp=[];
  100. $temp['payid']=$sid;
  101. $temp['invoice_type']=1;
  102. $temp['image']=$value['url'];
  103. $temp['name']=$value['name'];
  104. $temp['invoice_info']="";
  105. $temp['status']=3;
  106. $temp['addtime']=date("Y-m-d H:i:s");
  107. $temp['updatetime']=date("Y-m-d H:i:s");
  108. $data[]=$temp;
  109. }
  110. $insert= Db::name("invoice_img")->insertAll($data);
  111. if($insert){
  112. $upd=Db::name("pay_stages")->where([['id',"=",$sid],['status',"in",[3,9]]])->save(['status'=>4,
  113. "updatetime"=>date("Y-m-d H:i:s")]);
  114. if($upd){
  115. Db::commit();
  116. return app_show(0,"发票上传成功等待识别");
  117. }
  118. }
  119. Db::rollback();
  120. return error_show(1005,"发票提交失败");
  121. }catch(\Exception $e){
  122. Db::rollback();
  123. return error_show(1005,$e->getMessage());
  124. }
  125. }
  126. /**
  127. * 保存新建的资源
  128. *
  129. * @param \think\Request $request
  130. * @return \think\Response
  131. */
  132. public function InvoiceSave()
  133. {
  134. $post =$this->request->post();
  135. $token = isset($post['token']) ? trim($post['token']) : "";
  136. if($token==""){
  137. return error_show(101,'token不能为空');
  138. }
  139. $effetc = VerifyTokens($token);
  140. if(!empty($effetc) && $effetc['code']!=0){
  141. return error_show($effetc['code'],$effetc['message']);
  142. }
  143. $id = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  144. if($id==""){
  145. return error_show(1004,"参数id 不能为空");
  146. }
  147. $payifo = Db::name("invoice")->where("id","=",$id)->find();
  148. if(empty($payifo)){
  149. return error_show(1004,"发票信息未找到");
  150. }
  151. if($payifo['status']!=0){
  152. return error_show(1004,"发票信息未识别请等待");
  153. }
  154. $info=[];
  155. isset($post['type'])&&$post['type']!="" ?$info['type']= $post['type'] :"";
  156. isset($post['code'])&&$post['code']!=""? $info['code']= $post['code'] :"";
  157. isset($post['check_code'])&&$post['check_code']!=""? $info['check_code']= $post['check_code'] :"";
  158. isset($post['issue_date'])&&$post['issue_date']!=""? $info['issue_date']= $post['issue_date'] :"";
  159. isset($post['subtotal_amount'])&&$post['subtotal_amount']!=""? $info['subtotal_amount']= $post['subtotal_amount'] :"";
  160. isset($post['subtotal_tax'])&&$post['subtotal_tax']!=""? $info['subtotal_tax']= $post['subtotal_tax'] :"";
  161. isset($post['total'])&&$post['total']!=""? $info['total']= $post['total'] :"";
  162. isset($post['item_list'])&&$post['item_list']!=""? $info['item_list']= json_encode($post['item_list'],JSON_UNESCAPED_UNICODE) :"";
  163. if(isset($post['item_list'])){
  164. foreach ($post["item_list"] as $value){
  165. if($value['tax_rate']=='' || $value['tax_rate']==0){
  166. // var_dump($value['tax']!=''||$value['tax']!=0);
  167. if($value['tax']!=''&&$value['tax']!=0){
  168. return error_show(1004,"商品明细税率与税额不匹配");
  169. }
  170. }else{
  171. if($value['tax']==''|| $value['tax']==0){
  172. return error_show(1003,"商品明细税率与税额不匹配");
  173. }
  174. }
  175. }
  176. }
  177. isset($post['field']) ?$info['change_field']= $post['field'] :"" ;
  178. $info['status'] = isset($post['field'])&& $post['field']!="" ? 1 :0;
  179. $info['updatetime'] = date("Y-m-d H:i:s");
  180. $inse=[];
  181. if($info['change_field']!=""){
  182. $field = explode(",",$info['change_field']);
  183. $arr =["buyer_name","buyer_id","buyer_address","buyer_bank","seller_name","seller_id","seller_address","seller_bank"];
  184. $interset = array_intersect($field,$arr);
  185. if(!empty($interset)){
  186. $field = implode(",",$interset);
  187. isset($post['buyer_name'])&&$post['buyer_name']!=""? $inse['buyer_name']= $post['buyer_name'] :"";
  188. isset($post['buyer_id'])&&$post['buyer_id']!=""? $inse['buyer_id']= $post['buyer_id'] :"";
  189. isset($post['buyer_address'])&&$post['buyer_address']!=""? $inse['buyer_address']= $post['buyer_address'] :"";
  190. isset($post['buyer_bank'])&&$post['buyer_bank']!=""? $inse['buyer_bank']= $post['buyer_bank'] :"";
  191. isset($post['seller_name'])&&$post['seller_name']!=""? $inse['seller_name']= $post['seller_name'] :"";
  192. isset($post['seller_id'])&&$post['seller_id']!=""? $inse['seller_id']= $post['seller_id'] :"";
  193. isset($post['seller_address'])&&$post['seller_address']!=""? $inse['seller_address']= $post['seller_address'] :"";
  194. isset($post['seller_bank'])&&$post['seller_bank']!=""? $inse['seller_bank']= $post['seller_bank'] :"";
  195. $inse['change_field']= Db::raw("concat(IFNULL(change_field,''),',','{$field}')");
  196. $inse["status"]=1;
  197. $inse["updatetime"]=date("Y-m-d H:i:s");
  198. $check = $this->checkField($inse,$payifo['payid']);
  199. if($check['code']==false){
  200. return app_show(1005,"发票企业信息验证失败",$check['msg']);
  201. }
  202. }
  203. }
  204. Db::startTrans();
  205. try{
  206. $insert = Db::name("invoice_info")->where("invid","=",$id)->update($info);
  207. if($insert){
  208. if(!empty($inse)){
  209. $updat = Db::name("invoice_info")->where("payid","=",$payifo['payid'])->update($inse);
  210. if($updat){
  211. Db::commit();
  212. return app_show(0,"发票信息修改成功");
  213. }else{
  214. Db::rollback();
  215. return error_show(1005,"发票信息修改失败");
  216. }
  217. }
  218. Db::commit();
  219. return app_show(0,"发票信息修改成功");
  220. }
  221. Db::rollback();
  222. return error_show(1005,"发票信息修改失败");
  223. }catch(\Exception $e){
  224. Db::rollback();
  225. return error_show(1005,$e->getMessage());
  226. }
  227. }
  228. /**
  229. * 显示指定的资源
  230. *
  231. * @param int $id
  232. * @return \think\Response
  233. */
  234. public function InvoiceDel()
  235. {
  236. $post =$this->request->post();
  237. $token = isset($post['token']) ? trim($post['token']) : "";
  238. if($token==""){
  239. return error_show(101,'token不能为空');
  240. }
  241. $effetc = VerifyTokens($token);
  242. if(!empty($effetc) && $effetc['code']!=0){
  243. return error_show($effetc['code'],$effetc['message']);
  244. }
  245. $id = isset($post['id'])&& $post['id']!="" ? intval($post['id']) :"";
  246. if($id==""){
  247. return error_show(1004,"参数id 不能为空");
  248. }
  249. $payifo = Db::name("invoice")->where("id","=",$id)->find();
  250. if(empty($payifo)){
  251. return error_show(1004,"发票信息未找到");
  252. }
  253. $data = ["id"=>$id,"is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  254. $save = Db::name("invoice_img")->save($data);
  255. return $save? app_show(0,"发票删除成功"):error_show(1004,"发票删除失败");
  256. }
  257. /**
  258. * 显示编辑资源表单页.
  259. *
  260. * @param int $id
  261. * @return \think\Response
  262. */
  263. public function InvoiceCheck()
  264. {
  265. $post =$this->request->post();
  266. $token = isset($post['token']) ? trim($post['token']) : "";
  267. if($token==""){
  268. return error_show(101,'token不能为空');
  269. }
  270. $effetc = VerifyTokens($token);
  271. if(!empty($effetc) && $effetc['code']!=0){
  272. return error_show($effetc['code'],$effetc['message']);
  273. }
  274. $id = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :"";
  275. if($id==""){
  276. return error_show(1004,"参数sid 不能为空");
  277. }
  278. $type= isset($post['type'])&& $post['type']!="" ? intval($post['type']) :1;
  279. $payifo = Db::name("invoice_img")->where([["payid","=",$id],["is_del","=",0]])->select();
  280. if(empty($payifo->toArray())){
  281. return error_show(1004,"发票信息未找到");
  282. }
  283. $list=[];
  284. $n=0;
  285. $inBoole =false;
  286. foreach ($payifo as $key=>$value){
  287. if($value['status']==2){
  288. return error_show(1004,"存在不能识别的发票,请先删除!");
  289. }
  290. if($value['status']==4){
  291. return error_show(1004,"存在审核退回的发票,请先修改!");
  292. }
  293. if($value['status']==3){
  294. $list[]=$value['id'];
  295. }
  296. $inv_info = Db::name("invoice_info")->where([['invid',"=",$value['id']]])->find();
  297. if($value['status']==0 ){
  298. $n++;
  299. if(isset($inv_info['status']) ||$inv_info['status']==0){
  300. $inBoole = true;
  301. } ;
  302. }
  303. }
  304. if($n==count($payifo)){
  305. $check= $this->lastCheck($id);
  306. if($check["code"]){
  307. if($type==1){
  308. Db::name("pay_stages")->where("id","=",$id)->save(["status"=>5,"updatetime"=>date("Y-m-d H:i:s")]);
  309. return app_show(0,"提交成功");
  310. }else{
  311. Db::name("pay_stages")->where("id","=",$id)->save(["status"=>6,"inv_fee"=>$check['invtotal'],
  312. "updatetime"=>date("Y-m-d H:i:s")]);
  313. return app_show(0,"提交成功");
  314. }
  315. }else{
  316. return app_show(1003,"{$check['remark']}",$check);
  317. }
  318. }
  319. if(!empty($list)){
  320. Db::name("invoice_img")->where([["id","in",$list],["is_del","=",0],['status',"=",3]])->save
  321. (['status'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  322. }
  323. return app_show(0,"提交成功");
  324. }
  325. /**
  326. * 保存更新的资源
  327. *
  328. * @param \think\Request $request
  329. * @param int $id
  330. * @return \think\Response
  331. */
  332. public function update()
  333. {
  334. $post =$this->request->post();
  335. $token = isset($post['token']) ? trim($post['token']) : "";
  336. if($token==""){
  337. return error_show(101,'token不能为空');
  338. }
  339. $effetc = VerifyTokens($token);
  340. if(!empty($effetc) && $effetc['code']!=0){
  341. return error_show($effetc['code'],$effetc['message']);
  342. }
  343. $id = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :"";
  344. if($id==""){
  345. return error_show(1004,"参数id 不能为空");
  346. }
  347. $payifo = Db::name("invoice")->where("payid","=",$id)->select()->toArray();
  348. if(empty($payifo)){
  349. return error_show(1004,"发票信息未找到");
  350. }
  351. $n=0;
  352. foreach ($payifo as $key=>$value){
  353. if($value['status']==0){
  354. $n++;
  355. }
  356. }
  357. $invtime = isset($post['invtime'])&&$post['invtime']!='' ? $post['invtime']:date("Y-m-d H:i:s");
  358. Db::startTrans();
  359. try{
  360. $payno = Db::name("pay_stages")->where([['id',"=",$id],["status","=",6]])->find();
  361. if($n<count($payifo)){
  362. $msg ="审核未通过";
  363. $updat= Db::name("pay_stages")->where([['id',"=",$id],["status","=",6]])->save(['status'=>9,"updatetime"=>date("Y-m-d
  364. H:i:s")]);
  365. if($updat){
  366. Db::commit();
  367. return app_show(0,"审核未通过");
  368. }else{
  369. Db::rollback();
  370. return error_show(1004,"审核失败");
  371. }
  372. }else{
  373. $updat= Db::name("pay_stages")->where([['id',"=",$id],["status","=",6]])->save(['status'=>7,
  374. "invtime"=>$invtime,"updatetime"=>date("Y-m-d H:i:s")]);
  375. if($updat){
  376. $pay=[];
  377. $num = Db::name("pay_stages")->whereOr([['status',"<>",7],['pay_status',"<>",4]])->where
  378. ([['payNo',"=", $payno['payNo']],["is_del","=",0]])->count();
  379. if($num==0){
  380. $pay['status']=2;
  381. $pay['updatetime']=date("Y-m-d H:i:s");
  382. $pay_up = Db::name("pay")->where('payNo',"=", $payno['payNo'])->save($pay);
  383. if($pay_up){
  384. Db::commit();
  385. return app_show(0,"审核通过");
  386. }else{
  387. Db::rollback();
  388. return error_show(1004,"审核失败");
  389. }
  390. }
  391. Db::commit();
  392. return app_show(0,"审核通过");
  393. }
  394. Db::rollback();
  395. return error_show(1004,"审核失败");
  396. }
  397. }catch (\Exception $e){
  398. Db::rollback();
  399. return error_show(1004,$e->getMessage());
  400. }
  401. }
  402. /**
  403. * @return \think\response\Json|void
  404. * @throws \think\db\exception\DataNotFoundException
  405. * @throws \think\db\exception\DbException
  406. * @throws \think\db\exception\ModelNotFoundException
  407. * @throws \think\exception\DbException
  408. */
  409. public function InvoiceStatus()
  410. {
  411. $post =$this->request->post();
  412. $token = isset($post['token']) ? trim($post['token']) : "";
  413. if($token==""){
  414. return error_show(101,'token不能为空');
  415. }
  416. $effetc = VerifyTokens($token);
  417. if(!empty($effetc) && $effetc['code']!=0){
  418. return error_show($effetc['code'],$effetc['message']);
  419. }
  420. $id = isset($post['invid'])&& $post['invid']!="" ? intval($post['invid']) :"";
  421. if($id==""){
  422. return error_show(1004,"参数invid 不能为空");
  423. }
  424. $payifo = Db::name("invoice_img")->where("id","=",$id)->find();
  425. if(empty($payifo)){
  426. return error_show(1004,"发票信息未找到");
  427. }
  428. $status=isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  429. $remark=isset($post['remark'])&& $post['remark']!="" ? trim($post['remark']) :"";
  430. if($status==""){
  431. return error_show(1004,"参数status 不能为空");
  432. }
  433. if(!in_array($status,[0,1,2,3,4])){
  434. return error_show(1004,"参数status 无效参数");
  435. }
  436. Db::startTrans();
  437. try {
  438. $payifo['status']=$status;
  439. $payifo['remark']=$remark;
  440. $payifo['updatetime']=date("Y-m-d H:i:s");
  441. $update=Db::name("invoice_img")->save($payifo);
  442. if($update){
  443. // if(in_array($status,[2,4])){
  444. // $pay=["status"=>9,"updatetime"=>date("Y-m-d H:i:s")];
  445. // $ins= Db::name("pay_stages")->where("id","=",$payifo["payid"])->save($pay);
  446. // if($ins){
  447. // Db::commit();
  448. // return app_show(0,"修改成功");
  449. // }else{
  450. // Db::rollback();
  451. // return error_show(1003,"修改失败");
  452. // }
  453. // }
  454. Db::commit();
  455. return app_show(0,"修改成功");
  456. }
  457. Db::rollback();
  458. return error_show(1003,"修改失败");
  459. }catch (\Exception $e){
  460. Db::rollback();
  461. return error_show(1005,$e->getMessage());
  462. }
  463. }
  464. private function checkField($invocie,$payid){
  465. $paystage = Db::name("pay_stages")->where("id","=",$payid)->find();
  466. $remak="";
  467. if($paystage['companyNo']!=""){
  468. $company = Db::name("company_info")->where("companyNo","=",$paystage['companyNo'])->find();
  469. if(!empty($company)){
  470. if(isset($invocie['buyer_name'])&&$company['company_name']!=$invocie['buyer_name']){
  471. $remak.="\r\n 发票购买方企业名称不匹配;";
  472. }
  473. if(isset($invocie['buyer_id'])&&$company['company_license']!=$invocie['buyer_id']){
  474. $remak.="\r\n 发票购买方企业纳税识别号不匹配;";
  475. }
  476. if(isset($invocie['buyer_address'])&&stripos($company['company_address'].$company['mobile'],trim($invocie['buyer_address']))===false){
  477. $remak.="\r\n 发票购买方企业地址不匹配;";
  478. }
  479. if(isset($invocie['buyer_bank'])&&stripos($company['bank_name'].$company['bankNo'],trim($invocie['buyer_bank']))===false){
  480. $remak.="\r\n 发票购买方企业银行账户不匹配;";
  481. }
  482. }
  483. }
  484. if($remak!=""){
  485. return ["code"=>false,"msg"=>$remak];
  486. }else{
  487. return ["code"=>true,"msg"=>$remak];
  488. }
  489. }
  490. private function lastCheck($id){
  491. $list = Db::name("invoice")->where("payid","=",$id)->select();
  492. $isbool = True;
  493. $remark="";
  494. $rate=0;
  495. $total = 0;//发票总额;
  496. $invid=[];
  497. $paystage = Db::name("pay_stages")->where("id","=",$id)->find();
  498. if(!empty($list)){
  499. foreach ($list as $key=>$value){
  500. $row=$key+1;
  501. $item= json_decode($value['item_list'],true);
  502. if($value['subtotal_amount']===''){
  503. $isbool=false;
  504. $remark.="第{$row}张发票总额不能为空;";
  505. $invid[]=$value['id'];
  506. break;
  507. }
  508. if($value['subtotal_tax']===''){
  509. $isbool=false;
  510. $remark.="第{$row}张发票税额不能为空;";
  511. $invid[]=$value['id'];
  512. break;
  513. }
  514. if($value['total']===''){
  515. $isbool=false;
  516. $remark.="第{$row}张发票税后总额不能为空;";
  517. $invid[]=$value['id'];
  518. break;
  519. }
  520. $value['subtotal_amount']= str_replace("¥",'',$value['subtotal_amount']);
  521. $value['subtotal_tax']=str_replace("¥",'',$value['subtotal_tax']);
  522. $value['total']= str_replace("¥",'',$value['total']);
  523. $total +=$value['total'];
  524. $temp_total = round($value['subtotal_amount']+$value['subtotal_tax'],2);
  525. if($temp_total!=$value["total"]){
  526. $isbool=false;
  527. $remark.="第{$row}张发票金额总计不匹配;";
  528. $invid[]=$value['id'];
  529. break;
  530. }
  531. if(!empty($item)){
  532. $totla_amount =0;
  533. $totla_tax =0;
  534. foreach ($item as $k=>$val){
  535. if($val['tax_rate']===''){
  536. $isbool=false;
  537. $remark.="第{$row}张发票明细税率不能为空;";
  538. $invid[]=$value['id'];
  539. break;
  540. }
  541. if($val['tax']===''){
  542. $isbool=false;
  543. $remark.="第{$row}张发票明细税额不能为空;";
  544. $invid[]=$value['id'];
  545. break;
  546. }
  547. if($val['amount']===''){
  548. $isbool=false;
  549. $remark.="第{$row}张发票明细金额不能为空;";
  550. $invid[]=$value['id'];
  551. break;
  552. }
  553. $rate_tax=substr($val['tax_rate'],0,-1);
  554. $totla_amount+=floatval($val['amount']);
  555. $totla_tax+=floatval($val['tax']);
  556. if($rate==0){
  557. $rate=$rate_tax;
  558. }else{
  559. if($rate_tax!=$rate){
  560. $isbool=false;
  561. $remark.="第{$row}张发票税率不匹配;";
  562. $invid[]=$value['id'];
  563. break;
  564. }
  565. }
  566. }
  567. $totla_amount = round($totla_amount,2);
  568. $totla_tax = round($totla_tax,2);
  569. if($totla_amount!=$value['subtotal_amount']){
  570. $isbool=false;
  571. $remark.="第{$row}张发票明细总计金额不匹配;";
  572. $invid[]=$value['id'];
  573. break;
  574. }
  575. if($totla_tax!=$value['subtotal_tax']){
  576. $isbool=false;
  577. $remark.="第{$row}张发票总税额不匹配;";
  578. $invid[]=$value['id'];
  579. break;
  580. }
  581. }
  582. }
  583. $pay = Db::name("pay")->where("payNo","=",$paystage['payNo'])->find();
  584. $payrate= json_decode($pay['pay_rate'],true);
  585. $paytotal = sprintf("%.2f",$pay ['winv_fee']);
  586. $total = round($total,2);
  587. // //var_dump($paytotal,$total,(count($payrate)==$paystage['pay_stages']&& $paytotal!=$total));
  588. // if($paytotal<$total||(count($payrate)==$paystage['pay_stages']&& $paytotal!=$total)){
  589. // $isbool=false;
  590. // $remark.="发票总计金额不匹配;";
  591. // $invid[]=$value['id'];
  592. // }
  593. }
  594. return ["code"=>$isbool,"remark"=>$remark,"invid"=>array_unique($invid),"invtotal"=>$total];
  595. }
  596. }