Payment.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\BaseController;
  5. use app\admin\model\ReportCode;use app\command\datacopy;use think\facade\Db;
  6. class Payment extends BaseController
  7. {
  8. /**
  9. *付款详细列表
  10. * @return \think\Response
  11. */
  12. public function paymentList()
  13. {
  14. $post = $this->post;
  15. $condition = "a.is_del=0 ";
  16. $check = checkRole($this->roleid,49);
  17. if($check){
  18. $condition .=" and `a`.`apply_id` = {$this->uid}";
  19. }
  20. $startTime= isset($post['startTime'])&&$post['startTime']!="" ? trim($post['startTime']) :"";
  21. $endTime= isset($post['endTime'])&&$post['endTime']!="" ? trim($post['endTime']) :"";
  22. $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  23. $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
  24. $apply= isset($post['apply_name'])&&$post['apply_name']!="" ? trim($post['apply_name']) :"";
  25. $paystatus= isset($post['status'])&&$post['status']!="" ? $post['status'] :"";
  26. // $inv_status= isset($post['inv_status'])&&$post['inv_status']!="" ? $post['inv_status'] :"";
  27. if($startTime!=""){
  28. $condition.=" and `b`.`addtime` >= '{$startTime}'";
  29. }
  30. if($endTime!=""){
  31. $condition.=" and `b`.`addtime` <= '{$endTime}'";
  32. }
  33. if($supplierNo!=""){
  34. $condition.=" and `a`.`supplierNo` like '%{$supplierNo}%'";
  35. }
  36. if($payNo!=""){
  37. $condition.=" and `a`.`payNo` like '%{$payNo}%'";
  38. }
  39. if($apply!=""){
  40. $condition .=" and b.apply_name like '%{$apply}%'";
  41. }
  42. if($paystatus!=""){
  43. $condition .=" and `b`.`status` = {$paystatus}";
  44. }
  45. // if($inv_status!=""){
  46. // $condition .=" and `a`.`inv_status` = {$inv_status}";
  47. // }
  48. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1;
  49. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  50. $count = Db::name("pay")->alias('a')
  51. ->join("cfp_pay_payment b","`a`.`payNo` = `b`.`payNo` AND b.is_del = 0 ",'left')
  52. ->where($condition)->count();
  53. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  54. $page = $page>=$total?intval($total):$page;
  55. $list = Db::name("pay")->alias('a')
  56. ->join("cfp_pay_payment b","`a`.`payNo` = `b`.`payNo` AND ( `b`.`is_del` = 0 ) ",'left')
  57. ->where($condition)->page(intval($page),$size)->order("b.addtime desc")
  58. ->field(" `b`.`id` AS `id`,
  59. `a`.`payNo` AS `payNo`,
  60. `a`.`supplierNo`,
  61. `a`.`apay_fee` ,
  62. `a`.`total_fee` AS `total_fee`,
  63. `b`.`apply_name`,
  64. `b`.`apply_id`,
  65. `a`.`winv_fee` ,
  66. `a`.`ainv_fee` ,
  67. `a`.`wpay_fee` ,
  68. `a`.`pay_status` ,
  69. `a`.`inv_status` ,
  70. `b`.`pay_fee` AS `dpay_fee`,
  71. `b`.`return_img`,
  72. `b`.`return_time`,
  73. `b`.`status` AS `dstatus`,
  74. `a`.`status`,
  75. `a`.`remark` AS `remark`,
  76. `b`.`addtime` ,
  77. `a`.`companyNo` ,
  78. `a`.`companyName` ,
  79. `b`.`dzNo` AS `dzNo`
  80. ")->select();
  81. $data=[];
  82. foreach ($list as $key=>$value){
  83. $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count();
  84. $data[]=$value;
  85. }
  86. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  87. }
  88. /**
  89. *对账单列表
  90. * @return \think\Response
  91. */
  92. public function payList()
  93. {
  94. $post = $this->post;
  95. $condition = [["is_del","=",0]];
  96. $check = checkRole($this->roleid,49);
  97. if($check){
  98. $condition[]=["apply_id","=",$this->uid];
  99. }
  100. $startTime= isset($post['startTime'])&&$post['startTime']!="" ? trim($post['startTime']) :"";
  101. $endTime= isset($post['endTime'])&&$post['endTime']!="" ? trim($post['endTime']) :"";
  102. $supplierNo= isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  103. $payNo= isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
  104. $paystatus= isset($post['pay_status'])&&$post['pay_status']!="" ? $post['pay_status'] :"";
  105. $inv_status= isset($post['inv_status'])&&$post['inv_status']!="" ? $post['inv_status'] :"";
  106. if($startTime!=""){
  107. $condition[]=["addtime",">=",$startTime];
  108. }
  109. if($endTime!=""){
  110. $condition[]=["addtime","<=",$endTime];
  111. }
  112. if($supplierNo!=""){
  113. $condition[]=["supplierNo","like","%$supplierNo%"];
  114. }
  115. if($payNo!=""){
  116. $condition[]=["payNo","like","%$payNo%"];
  117. }
  118. if($paystatus!=""){
  119. $condition[]=["pay_status","=",$paystatus];
  120. }
  121. if($inv_status!=""){
  122. $condition[]=["inv_status","=",$inv_status];
  123. }
  124. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :1;
  125. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  126. $count = Db::name("pay")->where($condition)->count();
  127. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  128. $page = $page>=$total?intval($total):$page;
  129. $list = Db::name("pay")->where($condition)->page(intval($page),$size)->order("addtime desc")->select();
  130. $data=[];
  131. foreach ($list as $key=>$value){
  132. $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count();
  133. $data[]=$value;
  134. }
  135. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  136. }
  137. /**
  138. * 新建对账付款数据
  139. * @return \think\Response
  140. */
  141. public function PayAdd()
  142. {
  143. $post = $this->post;
  144. $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :"";
  145. if($cids==""){
  146. return error_show(1003,"参数cids不能为空");
  147. }
  148. $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids),"status"=>0])->select()->toArray();
  149. if(empty($cgdall)){
  150. return error_show(1003,"采购单数据不能为空");
  151. }
  152. $supplierNo= array_column($cgdall,"supplierNo");
  153. $supplierName= array_column($cgdall,"supplierName");
  154. if(count(array_unique($supplierNo))>1){
  155. return error_show(1003,"采购单数据供应商不一致");
  156. }
  157. $companyNo= array_column($cgdall,"companyNo");
  158. $companyName= array_column($cgdall,"companyName");
  159. if(count(array_unique($companyNo))>1){
  160. return error_show(1003,"采购单数据业务公司不一致");
  161. }
  162. $payNo = makeNo("PAY");
  163. Db::startTrans();
  164. try {
  165. $data=[];
  166. $paydata=[
  167. "payNo"=>$payNo,
  168. "apply_id"=>$this->uid,
  169. "apply_name"=>$this->uname,
  170. "total_fee"=>0,
  171. "supplierNo"=>$supplierNo[0],
  172. "supplierName"=>$supplierName[0],
  173. "companyNo"=>$companyNo[0],
  174. "companyName"=>$companyName[0],
  175. "wpay_fee"=>0,
  176. "apay_fee"=>0,
  177. "ainv_fee"=>0,
  178. "winv_fee"=>0,
  179. "remark"=>"",
  180. "status"=>0,
  181. "addtime"=>date("Y-m-d H:i:s"),
  182. "updatetime"=>date("Y-m-d H:i:s"),
  183. ];
  184. foreach ($cgdall as $key=>$value){
  185. $temp=[];
  186. $temp['cgdNo']=$value['sequenceNo'];
  187. $temp['total_fee']=$value['totalPrice'];
  188. $temp['apay_fee']=round($value['apay_fee'],2);
  189. $temp['wpay_fee']=round($value['wpay_fee'],2);
  190. $temp['winv_fee']=round($value['winv_fee'],2);
  191. $temp['ainv_fee']=round($value['ainv_fee'],2);
  192. $temp['payNo']=$payNo;
  193. $temp['addtime']=date("Y-m-d H:i:s");
  194. $temp['updatetime']=date("Y-m-d H:i:s");
  195. $data[]=$temp;
  196. $paydata['total_fee']+= $temp['total_fee'];
  197. $paydata['apay_fee']+= $temp['apay_fee'];
  198. $paydata['wpay_fee']+= $temp['wpay_fee'];
  199. $paydata['ainv_fee']+= $temp['ainv_fee'];
  200. $paydata['winv_fee']+= $temp['winv_fee'];
  201. $report=ReportCode::where(["cgdNo"=>$value['sequenceNo']])->find();
  202. $report->setField("payNo",$payNo);
  203. }
  204. $paydata['total_fee']= round($paydata['total_fee'],2);
  205. $paydata['apay_fee']= round($paydata['apay_fee'],2);
  206. $paydata['wpay_fee']= round($paydata['wpay_fee'],2);
  207. $paydata['ainv_fee']= round($paydata['ainv_fee'],2);
  208. $paydata['winv_fee']= round($paydata['winv_fee'],2);
  209. $info = Db::name("pay_info")->insertAll($data);
  210. if($info!=0){
  211. $payDA=Db::name("pay")->insert($paydata);
  212. if($payDA){
  213. $cgddup= Db::name("cgd_info")->where("id","in",$cids)->save(['status'=>1,"updatetime"=>date("Y-m-d
  214. H:i:s")]);
  215. if($cgddup){
  216. Db::commit();
  217. return app_show(0,"添加成功",["payNo"=>$payNo]);
  218. }
  219. }
  220. }
  221. Db::rollback();
  222. return error_show(1003,"添加失败");
  223. }catch(\Exception $e){
  224. Db::rollback();
  225. return error_show(1003,$e->getMessage());
  226. }
  227. }
  228. /**对账单未审核前可需改编辑
  229. * @return \think\response\Json|void
  230. * @throws \think\db\exception\DataNotFoundException
  231. * @throws \think\db\exception\DbException
  232. * @throws \think\db\exception\ModelNotFoundException
  233. * @throws \think\exception\DbException
  234. */
  235. public function PaySave()
  236. {
  237. $post = $this->post;
  238. $cids = isset($post['cids'])&&$post['cids']!="" ? trim($post['cids']) :"";
  239. if($cids==""){
  240. return error_show(1003,"参数cids不能为空");
  241. }
  242. $payNo = isset($post['payNo'])&&$post['payNo']!="" ? trim($post['payNo']) :"";
  243. if($payNo==""){
  244. return error_show(1003,"参数 payNo 不能为空");
  245. }
  246. $payinfo = Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
  247. if($payinfo==false){
  248. return error_show(1003,"未找到对账单数据");
  249. }
  250. if($payinfo['status']!=1){
  251. return error_show(1003,"对账单已提交审核");
  252. }
  253. $cgdall =Db::name("cgd_info")->where(["id"=>explode(",",$cids)])->select()->toArray();
  254. if(empty($cgdall)){
  255. return error_show(1003,"采购单数据不能为空");
  256. }
  257. $supplierNo= array_column($cgdall,"supplierNo");
  258. $supplierName= array_column($cgdall,"supplierName");
  259. if(count(array_unique($supplierNo))>1){
  260. return error_show(1003,"采购单数据供应商不一致");
  261. }
  262. $companyNo= array_column($cgdall,"companyNo");
  263. $companyName= array_column($cgdall,"companyName");
  264. if(count(array_unique($companyNo))>1){
  265. return error_show(1003,"采购单数据业务公司不一致");
  266. }
  267. $cgdArr=array_column($cgdall,"sequenceNo");
  268. $cgdNo = Db::name("pay_info")->where([["payNo","=",$payNo],["is_del","=",0]])->column("cgdNo");
  269. $add=[];
  270. $remove=[];
  271. if(!empty($cgdNo)){
  272. $remove = array_diff($cgdNo,$cgdArr);
  273. $add = array_diff($cgdArr,$cgdNo);
  274. }
  275. Db::startTrans();
  276. try {
  277. $data=[];
  278. $paydata=[
  279. "supplierNo"=>$supplierNo[0],
  280. "supplierName"=>$supplierName[0],
  281. "companyNo"=>$companyNo[0],
  282. "companyName"=>$companyName[0],
  283. "wpay_fee"=>0,
  284. "apay_fee"=>0,
  285. "ainv_fee"=>0,
  286. "winv_fee"=>0,
  287. "total_fee"=>0,
  288. "updatetime"=>date("Y-m-d H:i:s")
  289. ];
  290. foreach ($cgdall as $key=>$value){
  291. if(!empty($add)&& in_array($value['sequenceNo'],$add)){
  292. $temp=[];
  293. $temp['cgdNo']=$value['sequenceNo'];
  294. $temp['total_fee']=$value['totalPrice'];
  295. $temp['apay_fee']=round($value['apay_fee'],2);
  296. $temp['wpay_fee']=round($value['wpay_fee'],2);
  297. $temp['winv_fee']=round($value['winv_fee'],2);
  298. $temp['ainv_fee']=round($value['ainv_fee'],2);
  299. $temp['payNo']=$payNo;
  300. $temp['addtime']=date("Y-m-d H:i:s");
  301. $temp['updatetime']=date("Y-m-d H:i:s");
  302. $data[]=$temp;
  303. $report=ReportCode::where(["cgdNo"=>$value['sequenceNo']])->find();
  304. $report->setField("payNo",$payNo);
  305. }
  306. $paydata['total_fee']+= $value['totalPrice'];
  307. $paydata['apay_fee']+= $value['apay_fee'];
  308. $paydata['wpay_fee']+= $value['wpay_fee'];
  309. $paydata['ainv_fee']+= $value['ainv_fee'];
  310. $paydata['winv_fee']+= $value['winv_fee'];
  311. }
  312. $paydata['total_fee']= round($paydata['total_fee'],2);
  313. $paydata['apay_fee']= round($paydata['apay_fee'],2);
  314. $paydata['wpay_fee']= round($paydata['wpay_fee'],2);
  315. $paydata['ainv_fee']= round($paydata['ainv_fee'],2);
  316. $paydata['winv_fee']= round($paydata['winv_fee'],2);
  317. $payDA=Db::name("pay")->where($payinfo)->update($paydata);
  318. if($payDA){
  319. if(!empty($remove)){
  320. foreach ($remove as $value){
  321. $report=ReportCode::where(["cgdNo"=>$value])->find();
  322. $report->rmField("payNo",$payNo);
  323. }
  324. $payrm = Db::name("pay_info")->where(["cgdNo"=>$remove,"is_del"=>0])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  325. if($payrm==false){
  326. Db::rollback();
  327. return error_show(1004,"修改失败");
  328. }
  329. $cgdrm= Db::name("cgd_info")->where([["sequenceNo","in",$remove],["status","=",1]])->save(['status'=>0, "updatetime"=>date("Y-m-d H:i:s")]);
  330. if($cgdrm==false){
  331. Db::rollback();
  332. return error_show(1005,"修改失败");
  333. }
  334. }
  335. if(!empty($add)){
  336. $cgddup= Db::name("cgd_info")->where([["sequenceNo","in",$add],["status","=",0]])->save(['status'=>1, "updatetime"=>date("Y-m-d H:i:s")]);
  337. if($cgddup==false){
  338. Db::rollback();
  339. return error_show(1006,"修改失败");
  340. }
  341. }
  342. if(!empty($data)){
  343. $info = Db::name("pay_info")->insertAll($data);
  344. if($info==false){
  345. Db::rollback();
  346. return error_show(1003,"修改失败");
  347. }
  348. }
  349. Db::commit();
  350. return app_show(0,"修改成功",["payNo"=>$payNo]);
  351. }
  352. Db::rollback();
  353. return error_show(1007,"添加失败");
  354. }catch(\Exception $e){
  355. Db::rollback();
  356. return error_show(1003,$e->getMessage());
  357. }
  358. }
  359. /**
  360. * 对账付款状态审核 status 0 待提交 1 待采购审核 2 待财务审核 3 审核成功 4 采购驳回 5 财务驳回
  361. * @param \think\Request $request
  362. * @return \think\Response
  363. */
  364. public function PayStatus()
  365. {
  366. $post = $this->post;
  367. $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):"";
  368. if($payNo==""){
  369. return error_show(1004,"参数payNo不能为空");
  370. }
  371. $status= isset($post['status']) && $post['status']!=="" ? trim($post['status']):"";
  372. if($status===""){
  373. return error_show(1004,"参数status不能为空");
  374. }
  375. $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find();
  376. if($data==false){
  377. return error_show(1004,"未能找到对应数据");
  378. }
  379. $remark = isset($post['remark']) && $post['remark']!=""? trim($post['remark']):"";
  380. $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
  381. if(empty($cgdNo)){
  382. return error_show(1004,"未能找到对应采购单数据");
  383. }
  384. Db::startTrans();
  385. try{
  386. $update=[
  387. "status"=>$status,
  388. "remark"=>$remark,
  389. "updatetime"=>date("Y-m-d H:i:s")
  390. ];
  391. $result = Db::name("pay")->where("payNo","=",$payNo)->update($update);
  392. if($result){
  393. if($status==4 || $status==5){
  394. $cgdup =Db::name("cgd_info")->where(["sequenceNo"=>$cgdNo,"status"=>1])->update(['status'=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  395. if($cgdup==false){
  396. Db::rollback();
  397. return error_show(1004,"对账驳回失败");
  398. }
  399. foreach ($cgdNo as $value){
  400. $report=ReportCode::where(["cgdNo"=>$value])->find();
  401. $report->rmField("payNo",$payNo);
  402. }
  403. }
  404. Db::commit();
  405. return app_show(0,"状态更新成功");
  406. }
  407. Db::rollback();
  408. return error_show(1004,"状态更新失败");
  409. }catch (\Exception $e){
  410. Db::rollback();
  411. return error_show(1004,$e->getMessage());
  412. }
  413. }
  414. /**删除未审核完成的对账单
  415. * @return \think\response\Json|void
  416. * @throws \think\db\exception\DataNotFoundException
  417. * @throws \think\db\exception\DbException
  418. * @throws \think\db\exception\ModelNotFoundException
  419. */
  420. public function payDel(){
  421. $post = $this->post;
  422. $payNo = isset($post['payNo']) && $post['payNo']!="" ? trim($post['payNo']):"";
  423. if($payNo==""){
  424. return error_show(1004,"参数payNo不能为空");
  425. }
  426. $data = Db::name("pay")->where([["payNo","=",$payNo],["is_del","=",0]])->find();
  427. if($data==false){
  428. return error_show(1004,"未能找到对应数据");
  429. }
  430. if($data['status']==4){
  431. return error_show(1004,"对账单已审核通过");
  432. }
  433. $cgdNo = Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
  434. if(empty($cgdNo)){
  435. return error_show(1004,"未能找到对应采购单数据");
  436. }
  437. Db::startTrans();
  438. try{
  439. $payDel = ["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  440. $pay =Db::name("pay")->where($data)->update($payDel);
  441. if($pay){
  442. $infoup =Db::name("pay_info")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->update($payDel);
  443. if($infoup==false){
  444. Db::rollback();
  445. return error_show(1004,"对账删除失败");
  446. }
  447. $cgdup =Db::name("cgd_info")->where(["sequenceNo"=>$cgdNo,"status"=>1])->update(['status'=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  448. if($cgdup==false){
  449. Db::rollback();
  450. return error_show(1004,"对账删除失败");
  451. }
  452. foreach ($cgdNo as $value){
  453. $report=ReportCode::where(["cgdNo"=>$value])->find();
  454. $report->rmField("payNo",$payNo);
  455. }
  456. Db::commit();
  457. return error_show(0,"对账删除成功");
  458. }
  459. Db::rollback();
  460. return error_show(1004,"对账删除失败");
  461. }catch (\Exception $e){}
  462. }
  463. /**
  464. *
  465. * @param int $id
  466. * @return \think\Response
  467. */
  468. public function stageAdd()
  469. {
  470. $post = $this->post;
  471. $payNo = isset($post['payNo'])&& $post['payNo']!="" ? trim($post['payNo']) :"";
  472. if($payNo==""){
  473. return error_show(1004,"参数payNo 不能为空");
  474. }
  475. $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
  476. if($payinfo==false){
  477. return error_show(1004,"未找到对账信息");
  478. }
  479. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
  480. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  481. if($payinfo['status']!=3){
  482. return error_show(1004,"对账未审核完成");
  483. }
  484. $pay_fee = isset($post['pay_fee'])&& $post['pay_fee']!="" ? floatval($post['pay_fee']) :"";
  485. if($pay_fee==""){
  486. return error_show(1004,"参数 pay_fee 不能为空或零");
  487. }
  488. if($payinfo['wpay_fee']< $pay_fee){
  489. return error_show(1004,"对账单未付金额不足");
  490. }
  491. $dzno=makeNo("DZ");
  492. Db::startTrans();
  493. try {
  494. $ment =[
  495. "payNo"=>$payNo,
  496. "dzNo"=>$dzno,
  497. "apply_id"=>$this->uid,
  498. "apply_name"=>$this->uname,
  499. "pay_fee"=>$pay_fee,
  500. "return_img"=>'',
  501. "status"=>0,
  502. "addtime"=>date("Y-m-d H:i:s"),
  503. "updatetime"=>date("Y-m-d H:i:s")
  504. ];
  505. $payment =Db::name("pay_payment")->insert($ment);
  506. if($payment){
  507. $update=[
  508. "pay_fee"=> round($payinfo['pay_fee']+$pay_fee,2),
  509. "wpay_fee"=> round($payinfo['wpay_fee']-$pay_fee,2),
  510. "updatetime"=>date("Y-m-d H:i:s")
  511. ];
  512. $payup = Db::name("pay")->where($payinfo)->update($update);
  513. if($payup){
  514. foreach ($cgdNo as $value){
  515. $report=ReportCode::where(["cgdNo"=>$value])->find();
  516. $report->setField("DzNo",$dzno);
  517. }
  518. Db::commit();
  519. return app_show(0,"付款申请添加成功",["dzNo"=>$dzno]);
  520. }
  521. }
  522. Db::rollback();
  523. return error_show(1004,"付款申请添加失败");
  524. }catch (\Exception $e){
  525. Db::rollback();
  526. return error_show(1005,$e->getMessage());
  527. }
  528. }
  529. /**
  530. * 付款申请审核状态
  531. * 付款审核状态 0待发起 1待业务审核 2 待财务审核 3待付款回执 4 付款回执 5 业务驳回 6 财务驳回
  532. * @param int $id
  533. * @return \think\Response
  534. */
  535. public function stageStatus()
  536. {
  537. $post = $this->post;
  538. $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :"";
  539. if($dzNo==""){
  540. return error_show(1004,"参数 dzNo 不能为空");
  541. }
  542. $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  543. if($status==""){
  544. return error_show(1004,"参数status 不能为空");
  545. }
  546. if(!in_array($status,[0,1,2,3,4,5,6])){
  547. return error_show(1004,"参数status 无效值");
  548. }
  549. $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find();
  550. if($payment==false){
  551. return error_show(1005,"未找到付款申请信息");
  552. }
  553. $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
  554. if($payinfo==false){
  555. return error_show(1005,"未找到对账信息");
  556. }
  557. if($payinfo['status']!=3){
  558. return error_show(1005,"对账信息未完成审核");
  559. }
  560. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
  561. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  562. $remark = isset($post['remark'])? trim($post['remark']) :"";
  563. $image = isset($post['return_image'])? trim($post['return_image']) :"";
  564. $return_time = isset($post['return_time'])? trim($post['return_time']) :"";
  565. if($status==4){
  566. if($image=="")return error_show(1005,"付款回单图片不能为空");
  567. if($return_time=="")return error_show(1005,"付款回单时间不能为空");
  568. if($payinfo['pay_fee']< $payment['pay_fee'])return error_show(1005,"对账付款申请金额有误,请确认对账申请金额");
  569. }
  570. Db::startTrans();
  571. try{
  572. $mentupdate =["status"=>$status,"remark"=>$remark,"return_img"=>$image,"updatetime"=>date("Y-m-d H:i:s")];
  573. if($status==4) $mentupdate['return_time'] = $return_time;
  574. $payup=Db::name("pay_payment")->where($payment)->update($mentupdate);
  575. if($payup){
  576. if (in_array($status,[4,5,6])){
  577. if($status==4){ //审核通过 扣减对账付款中的金额 添加到已付金额
  578. $payupdate =[
  579. "apay_fee"=>$payinfo['apay_fee']+$payment['pay_fee'],
  580. "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'],
  581. "pay_status" => ($payinfo['pay_fee']-$payment['pay_fee'])==0 && $payinfo['wpay_fee']==0 ?3:2,
  582. "updatetime" => date("Y-m-d H:i:s")
  583. ];
  584. }
  585. if($status==5||$status==6){//审核驳回 扣减对账付款中的金额 返回到待付金额中
  586. $payupdate =[
  587. "wpay_fee"=>$payinfo['wpay_fee']+$payment['pay_fee'],
  588. "pay_fee"=>$payinfo['pay_fee']-$payment['pay_fee'],
  589. "pay_status" => $payinfo['apay_fee']==0 ?1:2,
  590. "updatetime" => date("Y-m-d H:i:s")
  591. ];
  592. foreach ($cgdNo as $value){
  593. $report=ReportCode::where(["cgdNo"=>$value])->find();
  594. $report->rmField("DzNo",$dzNo);
  595. }
  596. }
  597. $pay = Db::name("pay")->where($payinfo)->update($payupdate);
  598. if($pay==false){
  599. Db::rollback();
  600. return error_show(1003,"对账状态修改失败");
  601. }
  602. }
  603. Db::commit();
  604. return app_show(0,"状态修改成功");
  605. }else{
  606. Db::rollback();
  607. return error_show(1003,"状态修改失败");
  608. }
  609. }catch (\Exception $e){
  610. Db::rollback();
  611. return error_show(1008,$e->getMessage());
  612. }
  613. }
  614. /**对账申请删除
  615. * @return \think\response\Json|void
  616. * @throws \think\db\exception\DataNotFoundException
  617. * @throws \think\db\exception\DbException
  618. * @throws \think\db\exception\ModelNotFoundException
  619. */
  620. public function stageDel(){
  621. $post = $this->post;
  622. $dzNo = isset($post['dzNo'])&& $post['dzNo']!="" ? trim($post['dzNo']) :"";
  623. if($dzNo==""){
  624. return error_show(1004,"参数 dzNo 不能为空");
  625. }
  626. $payment= Db::name("pay_payment")->where([['dzNo',"=",$dzNo],['is_del',"=",0]])->find();
  627. if($payment==false){
  628. return error_show(1005,"未找到付款申请信息");
  629. }
  630. $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
  631. if($payinfo==false){
  632. return error_show(1005,"未找到付款信息");
  633. }
  634. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
  635. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  636. Db::startTrans();
  637. try{
  638. $paym = Db::name("pay_payment")->where($payment)->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  639. if($paym){
  640. if(in_array($payment['status'],[1,2,3,4])){
  641. if(in_array($payment['status'],[1,2,3])){
  642. $payinfo['wpay_fee']+=$payment['pay_fee'];
  643. $payinfo['pay_fee']-=$payment['pay_fee'];
  644. $payinfo['updatetime']=date("Y-m-d H:i:s");
  645. }
  646. if($payment['status']==4){
  647. $payinfo['wpay_fee']+=$payment['pay_fee'];
  648. $payinfo['apay_fee']-=$payment['pay_fee'];
  649. $payinfo['pay_status']=$payinfo['apay_fee']==0? 1 : 2 ;
  650. $payinfo['updatetime']=date("Y-m-d H:i:s");
  651. foreach ($cgdNo as $value){
  652. $report=ReportCode::where(["cgdNo"=>$value])->find();
  653. $report->rmField("DzNo",$dzNo);
  654. }
  655. }
  656. $pay = Db::name("pay")->save($payinfo);
  657. if($pay==false){
  658. Db::rollback();
  659. return error_show(1003,"对账状态修改失败");
  660. }
  661. }
  662. Db::commit();
  663. return app_show(0,"对账申请删除成功");
  664. }
  665. }catch (\Exception $e){
  666. Db::rollback();
  667. return error_show(1003,$e->getMessage());
  668. }
  669. }
  670. /**
  671. * 采购单列表
  672. * @param \think\Request $request
  673. * @param int $id
  674. * @return \think\Response
  675. */
  676. public function CgdList()
  677. {
  678. $post = $this->post;
  679. $condition = [];
  680. $check = checkRole($this->roleid,46);
  681. // if($check){
  682. // $condition []=["ownerid","=",$this->uid];
  683. // }
  684. $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo']!='' ? trim($post['sequenceNo']) :"";
  685. if($sequenceNo!=""){
  686. $condition []=["sequenceNo","like","%$sequenceNo%"];
  687. }
  688. $status = isset($post['status']) && $post['status']!=='' ? intval($post['status']) :"";
  689. if($status!==""){
  690. if($status!==''){
  691. if($status==3){
  692. $condition[]=["status","<>",2];
  693. }else{
  694. $condition[]=["status","=",$status];
  695. }
  696. }
  697. }
  698. $companyNo = isset($post['companyNo']) && $post['companyNo']!='' ? trim($post['companyNo']) :"";
  699. if($companyNo!=""){
  700. $condition []=["companyNo","like","%$companyNo%"];
  701. }
  702. $companyName = isset($post['companyName']) && $post['companyName']!='' ? trim($post['companyName']) :"";
  703. if($companyName!=""){
  704. $condition []=["companyName","like","%$companyName%"];
  705. }
  706. $bkCode = isset($post['bkCode']) && $post['bkCode']!='' ? trim($post['bkCode']) :"";
  707. if($bkCode!=""){
  708. $condition []=["bkCode","like","%$bkCode%"];
  709. }
  710. $goodNo = isset($post['goodNo']) && $post['goodNo']!='' ? trim($post['goodNo']) :"";
  711. if($goodNo!=""){
  712. $condition []=["goodNo","like","%$goodNo%"];
  713. }
  714. $goodName = isset($post['goodName']) && $post['goodName']!='' ? trim($post['goodName']) :"";
  715. if($goodName!=""){
  716. $condition []=["goodName","like","%$goodName%"];
  717. }
  718. $supplierName = isset($post['supplierName']) && $post['supplierName']!='' ? trim($post['supplierName']) :"";
  719. if($supplierName!=""){
  720. $condition []=["supplierName","like","%$supplierName%"];
  721. }
  722. $supplierNo = isset($post['supplierNo']) && $post['supplierNo']!='' ? trim($post['supplierNo']) :"";
  723. if($supplierNo!=""){
  724. $condition []=["supplierNo","like","%$supplierNo%"];
  725. }
  726. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  727. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  728. $count = Db::name("cgd_info")->where($condition)->count();
  729. $total = ceil($count/$size);
  730. $page = $page>=$total?intval($total):$page;
  731. $list = Db::name("cgd_info")->where($condition)->page($page,$size)->order('createdTime desc')->select();
  732. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  733. }
  734. //采购单信息
  735. public function cgdinfo(){
  736. $post=$this->post;
  737. $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo']!='' ? trim($post['sequenceNo']) :"";
  738. if($sequenceNo==''){
  739. return error_show(1004,"参数 sequenceNo 不能为空");
  740. }
  741. $cgdinfo = Db::name("cgd_info")->where(["sequenceNo"=>$sequenceNo])->findOrEmpty();
  742. if(empty($cgdinfo)){
  743. return error_show(1004,"采购单信息未找到");
  744. }
  745. $cgdinfo['catInfo'] = json_decode($cgdinfo['catInfo'],true);
  746. $payinfo =Db::name("pay_info")->alias("a")->leftJoin("pay b","a.payNo=b.payNo")
  747. ->where(["a.is_del"=>0,"b.is_del"=>0,"a.cgdNo"=>$sequenceNo])->field("b.inv_status,b.pay_status,b.status")
  748. ->find();
  749. $cgdinfo["cgd_pay_status"]=$payinfo['pay_status']??1;
  750. $cgdinfo["cgd_inv_status"]=$payinfo['inv_status']??1;
  751. $cgdinfo["cgd_status"]=$payinfo['status']??0;
  752. return app_show(0,"获取成功",$cgdinfo);
  753. }
  754. //todo
  755. public function PayInfo()
  756. {
  757. $post = $this->post;
  758. $payNo =isset($post['payNo'])&&$post['payNo']!='' ? trim($post['payNo']):"";
  759. if($payNo==""){
  760. return error_show(1004,"参数 payNo 不能为空");
  761. }
  762. $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
  763. if($payinfo==false){
  764. return error_show(1004,"对账单数据未找到");
  765. }
  766. $pay =Db::name("pay_info")->alias("a")->leftJoin("cgd_info b","a.cgdNo=b.sequenceNo")
  767. ->where(["a.is_del"=>0,"b.is_del"=>0,"a.payNo"=>$payNo])->field("b.*")
  768. ->select()->toArray();
  769. foreach ($pay as &$value){
  770. $value['catInfo'] = json_decode($value['catInfo'],true);
  771. }
  772. $payinfo['cgdlist'] = $pay;
  773. return app_show(0,"获取成功",$payinfo);
  774. }
  775. public function DzInfo()
  776. {
  777. $post = $this->post;
  778. $DzNo =isset($post['DzNo'])&&$post['DzNo']!='' ? trim($post['DzNo']):"";
  779. if($DzNo==""){
  780. return error_show(1004,"参数 DzNo 不能为空");
  781. }
  782. $payinfo =Db::name("pay_payment")->where(["dzNo"=>$DzNo,"is_del"=>0])->find();
  783. if($payinfo==false){
  784. return error_show(1004,"对账单付款申请数据未找到");
  785. }
  786. $pay =Db::name("pay")->where(["payNo"=>$payinfo['payNo'],"is_del"=>0])->find();
  787. if($pay==false){
  788. return error_show(1004,"对账单数据未找到");
  789. }
  790. $payinfo['pay_apply_id'] = $pay['apply_id']??'';
  791. $payinfo['pay_apply_name'] = $pay['apply_name']??'';
  792. $payinfo['supplierNo'] = $pay['supplierNo']??'';
  793. $payinfo['supplierName'] = $pay['supplierName']??'';
  794. $payinfo['companyNo'] = $pay['companyNo']??'';
  795. $payinfo['companyName'] = $pay['companyName']??'';
  796. $payinfo['total_fee'] = $pay['total_fee']??'';
  797. return app_show(0,"获取成功",$payinfo);
  798. }
  799. /**发票新建添加
  800. * @return \think\response\Json|void
  801. * @throws \think\db\exception\DataNotFoundException
  802. * @throws \think\db\exception\DbException
  803. * @throws \think\db\exception\ModelNotFoundException
  804. * @throws \think\exception\DbException
  805. */
  806. public function invAdd(){
  807. $post = $this->post;
  808. $payNo = isset($post['payNo'])&&$post['payNo']!='' ? $post['payNo']:"";
  809. if($payNo==""){
  810. return error_show(1004,"参数 payNo 不能为空");
  811. }
  812. $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
  813. if($payinfo==false){
  814. return error_show(1004,"对账单数据未找到");
  815. }
  816. if($payinfo['status']!=3){
  817. return error_show(1004,"对账单数据未完成审核");
  818. }
  819. $type = isset($post['invType']) && $post['invType']!="" ? intval($post['invType']):"";
  820. if($type==''){
  821. return error_show(1004,"参数 invType 不能为空");
  822. }
  823. $invNumber =isset($post['invNumber'])&& $post['invNumber']!='' ? trim($post['invNumber']):"";
  824. $invCode =isset($post['invCode'])&& $post['invCode']!='' ? trim($post['invCode']):"";
  825. $checkNumber =isset($post['checkNumber'])&& $post['checkNumber']!='' ? trim($post['checkNumber']):"";
  826. $openTime =isset($post['open_time'])&& $post['open_time']!='' ? trim($post['open_time']):"";
  827. if($type==1){
  828. if($invNumber=="") return error_show(1004,"参数 invNumber 不能为空");
  829. if($invCode=="") return error_show(1004,"参数 invCode 不能为空");
  830. // if($checkNumber=="") return error_show(1004,"参数 checkNumber 不能为空");
  831. if($openTime=="") return error_show(1004,"参数 open_time 不能为空");
  832. }
  833. $invimg = isset($post['inv_img'])&& $post['inv_img']!='' ? trim($post['inv_img']):"";
  834. $invName = isset($post['invName'])&& $post['invName']!='' ? trim($post['invName']):"";
  835. if($type==2){
  836. if($invimg=="")return error_show(1004,"参数 inv_img 不能为空");
  837. if($invName=="")return error_show(1004,"参数 invName 不能为空");
  838. }
  839. if ($type==3){
  840. }
  841. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
  842. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  843. Db::startTrans();
  844. try{
  845. $hpNo=makeNo("hp");
  846. $data=[
  847. "payNo"=>$payNo,
  848. "hpNo"=>$hpNo,
  849. "apply_id"=>$this->uid,
  850. "apply_name"=>$this->uname,
  851. "inv_fee"=> '',
  852. "invType"=> $type,
  853. "invoiceType"=>0,
  854. "inv_img"=>$invimg,
  855. "invName"=>$invName,
  856. "invoiceNumber"=>$invNumber,
  857. "invoiceCode"=>$invCode,
  858. "checkNumber"=>$checkNumber,
  859. "open_time"=>$openTime,
  860. "addtime"=>date("Y-m-d H:i:s"),
  861. "updatetime"=>date("Y-m-d H:i:s")
  862. ];
  863. $inadd =Db::name("pay_invoice")->insert($data);
  864. if ($inadd){
  865. foreach ($cgdNo as $value){
  866. $report=ReportCode::where(["cgdNo"=>$value])->find();
  867. $report->setField("hpNo",$hpNo);
  868. }
  869. Db::commit();
  870. return app_show(0,"回票新建成功",['hpNo'=>$hpNo]);
  871. }
  872. Db::rollback();
  873. return error_show(1004,"回票申请新建失败");
  874. }catch (\Exception $e){
  875. Db::rollback();
  876. return error_show(1004,$e->getMessage());
  877. }
  878. }
  879. /**
  880. * 发票审核状态
  881. * 0 上传发票,1待识别验证 2 待校验识别 3 待财务审核 6 待认证 7认证成功待确认完成 8回票完成 9识别失败 10 验证失败 11 财务驳回 12 认证失败
  882. * @return \think\response\Json|void
  883. * @throws \think\db\exception\DataNotFoundException
  884. * @throws \think\db\exception\DbException
  885. * @throws \think\db\exception\ModelNotFoundException
  886. * @throws \think\exception\DbException
  887. */
  888. public function invStatus(){
  889. $post = $this->post;
  890. $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? trim($post['hpNo']) :"";
  891. if($hpNo==""){
  892. return error_show(1004,"参数 hpNo 不能为空");
  893. }
  894. $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  895. if($status==""){
  896. return error_show(1004,"参数status 不能为空");
  897. }
  898. if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){
  899. return error_show(1004,"参数status 无效值");
  900. }
  901. $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find();
  902. if($payment==false){
  903. return error_show(1005,"未找到回票申请信息");
  904. }
  905. $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
  906. if($payinfo==false){
  907. return error_show(1005,"未找到对账信息");
  908. }
  909. if($payinfo['status']!=3){
  910. return error_show(1005,"对账信息未完成审核");
  911. }
  912. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
  913. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  914. if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
  915. $remark = $post['remark']??'';
  916. Db::startTrans();
  917. try {
  918. $invup =["status"=>$status,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
  919. $inv =Db::name("pay_invoice")->where($payment)->update($invup);
  920. if($inv){
  921. if($status==8){
  922. $payupdate =[
  923. "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'],
  924. "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
  925. "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2,
  926. "updatetime" => date("Y-m-d H:i:s")
  927. ];
  928. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  929. if($pay==false){
  930. Db::rollback();
  931. return error_show(1003,"回票申请状态更新成功");
  932. }
  933. }
  934. if($status==11){
  935. $payupdate =[
  936. "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'],
  937. "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
  938. "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2,
  939. "updatetime" => date("Y-m-d H:i:s")
  940. ];
  941. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  942. if($pay==false){
  943. Db::rollback();
  944. return error_show(1003,"回票申请状态更新成功");
  945. }
  946. foreach ($cgdNo as $value){
  947. $report=ReportCode::where(["cgdNo"=>$value])->find();
  948. $report->rmField("hpNo",$hpNo);
  949. }
  950. }
  951. Db::commit();
  952. return app_show(0,"回票申请更新成功");
  953. }
  954. Db::rollback();
  955. return error_show(1003,"回票申请状态更新成功");
  956. }catch (\Exception $e){
  957. Db::rollback();
  958. return error_show(1004,$e->getMessage());
  959. }
  960. }
  961. /**发票列表识别
  962. * @param int $id
  963. * @return \think\Response
  964. */
  965. public function InvList()
  966. {
  967. $post = $this->post;
  968. $condition = [["a.is_del","=",0 ],["b.is_del","=",0 ]];
  969. $invtype = isset($post['invType'])&&$post['invType']!='' ? intval($post['invType']):"";
  970. if ($invtype!=''){
  971. $condition[]=["a.invType","=",$invtype];
  972. }
  973. $hpNo = isset($post['hpNo'])&&$post['hpNo']!='' ? trim($post['hpNo']):"";
  974. if ($hpNo!=''){
  975. $condition[]=["a.hpNo","like","%$hpNo%"];
  976. }
  977. $invoiceType = isset($post['invoiceType'])&&$post['invoiceType']!='' ? intval($post['invoiceType']):"";
  978. if ($invoiceType!=''){
  979. $condition[]=["a.invoiceType","=",$invoiceType];
  980. }
  981. $status = isset($post['status'])&&$post['status']!="" ? intval($post['status']):"";
  982. if($status!=""){
  983. $condition[]=["a.status","=",$status];
  984. }
  985. $invNumber = isset($post['invNumber'])&&$post['invNumber']!="" ? trim($post['invNumber']):"";
  986. if($invNumber!=''){
  987. $condition[]=["invoiceNumber","=",$invNumber];
  988. }
  989. $invCode = isset($post['invCode'])&&$post['invCode']!="" ? trim($post['invCode']):"";
  990. if($invCode!=''){
  991. $condition[]=["invoiceCode","=",$invCode];
  992. }
  993. $start = isset($post['start']) && $post['start']!="" ? $post['start'] :"";
  994. if($start!=""){
  995. $condition[]=["a.addtime",">=",$start." 00:00:00"];
  996. }
  997. $end = isset($post['end']) && $post['end']!="" ? $post['end'] :"";
  998. if($end!=""){
  999. $condition[]=["a.addtime","<=",$end." 23:59:59"];
  1000. }
  1001. $open_start = isset($post['open_start']) && $post['open_start']!="" ? $post['open_start'] :"";
  1002. if($open_start!=""){
  1003. $condition[]=["a.open_time",">=",$open_start." 00:00:00"];
  1004. }
  1005. $open_end = isset($post['open_end']) && $post['open_end']!="" ? $post['open_end'] :"";
  1006. if($open_end!=""){
  1007. $condition[]=["a.open_time","<=",$open_end." 23:59:59"];
  1008. }
  1009. $apply_id = isset($post['apply_id']) && $post['apply_id']!="" ? $post['apply_id'] :"";
  1010. if($apply_id!=""){
  1011. $condition[]=["a.apply_id","=",$apply_id];
  1012. }
  1013. $apply_name = isset($post['apply_name']) && $post['apply_name']!="" ? trim($post['apply_name']):"";
  1014. if($apply_name!=""){
  1015. $condition[]=["a.apply_name","like","%$apply_name%"];
  1016. }
  1017. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']):1;
  1018. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']):10;
  1019. $count =Db::name("pay_invoice")->alias("a")->leftJoin("pay b","a.payNo=b.payNo")->where($condition)->count();
  1020. $total = ceil($count/$size);
  1021. $page = $page>$total? intval($total):$page;
  1022. $list = Db::name("pay_invoice")->alias("a")->leftJoin("pay b","a.payNo=b.payNo")->field("a.*")->where
  1023. ($condition)->page($page,$size)->select()->toArray();
  1024. foreach ($list as &$value){
  1025. $invoinfo =Db::name("invoice_info")->where(["hpNo"=>$value['hpNo'],"status"=>1])->find();
  1026. $value['buyer_name'] = $invoinfo['buyer_name']??"";
  1027. $value['buyer_id'] = $invoinfo['buyer_id']??"";
  1028. $value['buyer_address'] = $invoinfo['buyer_address']??"";
  1029. $value['buyer_bank'] = $invoinfo['buyer_bank']??"";
  1030. $value['seller_name'] = $invoinfo['seller_name']??"";
  1031. $value['seller_id'] = $invoinfo['seller_id']??"";
  1032. $value['seller_address'] = $invoinfo['seller_address']??"";
  1033. $value['seller_bank'] = $invoinfo['seller_bank']??"";
  1034. $value['subtotal_amount'] = $invoinfo['subtotal_amount']??"";
  1035. $value['subtotal_tax'] = $invoinfo['subtotal_tax']??"";
  1036. $value['total'] = $invoinfo['total']??"";
  1037. $value['receiver'] = $invoinfo['receiver']??"";
  1038. $value['issuer'] = $invoinfo['issuer']??"";
  1039. $value['reivewer'] = $invoinfo['reivewer']??"";
  1040. $value['remarks'] = $invoinfo['remarks']??"";
  1041. $value['item_list'] = isset($invoinfo['item_list']) &&$invoinfo['item_list']!='' ?json_decode($invoinfo['item_list'],true):"";
  1042. }
  1043. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  1044. }
  1045. /**发票删除
  1046. * @return \think\response\Json|void
  1047. * @throws \think\db\exception\DataNotFoundException
  1048. * @throws \think\db\exception\DbException
  1049. * @throws \think\db\exception\ModelNotFoundException
  1050. */
  1051. public function invDel(){
  1052. $post = $this->post;
  1053. $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :"";
  1054. if ($hpNo==""){
  1055. return error_show(1004,"参数 hpNo 不能为空");
  1056. }
  1057. $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find();
  1058. if($payinv==false){
  1059. return error_show(1004,"对账单回票申请未找到数据");
  1060. }
  1061. $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find();
  1062. if($payinfo==false){
  1063. return error_show(1005,"未找到对账信息");
  1064. }
  1065. if($payinfo['status']!=3){
  1066. return error_show(1005,"对账信息未完成审核");
  1067. }
  1068. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payinv['payNo'],"is_del"=>0])->column("cgdNo");
  1069. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  1070. Db::startTrans();
  1071. try{
  1072. $update=["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  1073. $invup =Db::name("pay_invoice")->where($payinv)->update($update);
  1074. if($invup){
  1075. if($payinv['status']==8){
  1076. if($payinfo['ainv_fee']< $payinv['inv_fee']){
  1077. Db::rollback();
  1078. return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
  1079. }
  1080. $payupdate =[
  1081. "ainv_fee"=>$payinfo['ainv_fee']-$payinv['inv_fee'],
  1082. "winv_fee"=>$payinfo['winv_fee']+$payinv['inv_fee'],
  1083. "inv_status" => ($payinfo['ainv_fee']-$payinv['inv_fee'])==0?1:2,
  1084. "updatetime" => date("Y-m-d H:i:s")
  1085. ];
  1086. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  1087. if($pay==false){
  1088. Db::rollback();
  1089. return error_show(1003,"删除失败");
  1090. }
  1091. foreach ($cgdNo as $value){
  1092. $report=ReportCode::where(["cgdNo"=>$value])->find();
  1093. $report->rmField("hpNo",$hpNo);
  1094. }
  1095. }
  1096. Db::commit();
  1097. return app_show(0,"删除成功");
  1098. }
  1099. }catch (\Exception $e){
  1100. Db::rollback();
  1101. return error_show(1003,$e->getMessage());
  1102. }
  1103. }
  1104. public function HpInfo(){
  1105. $post = $this->post;
  1106. $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :"";
  1107. if ($hpNo==""){
  1108. return error_show(1004,"参数 hpNo 不能为空");
  1109. }
  1110. $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find();
  1111. if($payinv==false){
  1112. return error_show(1004,"对账单回票申请未找到数据");
  1113. }
  1114. $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find();
  1115. if($payinfo==false){
  1116. return error_show(1005,"未找到对账信息");
  1117. }
  1118. $payinv['pay_apply_id'] = $payinfo['apply_id']??'';
  1119. $payinv['pay_apply_name'] = $payinfo['apply_name']??'';
  1120. $payinv['supplierNo'] = $payinfo['supplierNo']??'';
  1121. $payinv['supplierName'] = $payinfo['supplierName']??'';
  1122. $payinv['companyNo'] = $payinfo['companyNo']??'';
  1123. $payinv['companyName'] = $payinfo['companyName']??'';
  1124. $payinv['total_fee'] = $payinfo['total_fee']??'';
  1125. $invinfo =Db::name("invoice_info")->where(["hpNo"=>$hpNo])->findOrEmpty();
  1126. if(!empty($invinfo)){
  1127. $invinfo['item_list'] =json_decode($invinfo['item_list'],true);
  1128. }
  1129. $payinv["info"]=$invinfo;
  1130. return app_show(0,'获取成功',$payinv);
  1131. }
  1132. public function UnPay(){
  1133. $post = $this->post;
  1134. $codeNo = isset($post['id'])&&$post['id']!=="" ? trim($post['id']) :'';
  1135. if($codeNo===""){
  1136. return error_show(1004,'参数 id 不能为空');
  1137. }
  1138. $update = Db::name('cgd_info')->where("id","in",$codeNo)->update(['status'=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  1139. if($update){
  1140. return app_show(0,'更新成功');
  1141. }else{
  1142. return error_show(1004,'更新失败');
  1143. }
  1144. }
  1145. }