Payment.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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"=>1,
  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. $condition []=["status","=",$status];
  691. }
  692. $companyNo = isset($post['companyNo']) && $post['companyNo']!='' ? trim($post['companyNo']) :"";
  693. if($companyNo!=""){
  694. $condition []=["companyNo","like","%$companyNo%"];
  695. }
  696. $companyName = isset($post['companyName']) && $post['companyName']!='' ? trim($post['companyName']) :"";
  697. if($companyName!=""){
  698. $condition []=["companyName","like","%$companyName%"];
  699. }
  700. $bkCode = isset($post['bkCode']) && $post['bkCode']!='' ? trim($post['bkCode']) :"";
  701. if($bkCode!=""){
  702. $condition []=["bkCode","like","%$bkCode%"];
  703. }
  704. $goodNo = isset($post['goodNo']) && $post['goodNo']!='' ? trim($post['goodNo']) :"";
  705. if($goodNo!=""){
  706. $condition []=["goodNo","like","%$goodNo%"];
  707. }
  708. $goodName = isset($post['goodName']) && $post['goodName']!='' ? trim($post['goodName']) :"";
  709. if($goodName!=""){
  710. $condition []=["goodName","like","%$goodName%"];
  711. }
  712. $supplierName = isset($post['supplierName']) && $post['supplierName']!='' ? trim($post['supplierName']) :"";
  713. if($supplierName!=""){
  714. $condition []=["supplierName","like","%$supplierName%"];
  715. }
  716. $supplierNo = isset($post['supplierNo']) && $post['supplierNo']!='' ? trim($post['supplierNo']) :"";
  717. if($supplierNo!=""){
  718. $condition []=["supplierNo","like","%$supplierNo%"];
  719. }
  720. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']) :0;
  721. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']) :10;
  722. $count = Db::name("cgd_info")->where($condition)->count();
  723. $total = ceil($count/$size);
  724. $page = $page>=$total?intval($total):$page;
  725. $list = Db::name("cgd_info")->where($condition)->page($page,$size)->order('createdTime desc')->select();
  726. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  727. }
  728. //todo
  729. public function PayInfo()
  730. {
  731. $post = $this->post;
  732. $token = isset($post['token']) ? trim($post['token']) : "";
  733. if($token==""){
  734. return error_show(101,'token不能为空');
  735. }
  736. $effetc = VerifyTokens($token);
  737. if(!empty($effetc) && $effetc['code']!=0){
  738. return error_show($effetc['code'],$effetc['message']);
  739. }
  740. $sid = isset($post['sid'])&& $post['sid']!="" ? intval($post['sid']) :"";
  741. if($sid==""){
  742. return error_show(1004,"参数sid 不能为空");
  743. }
  744. $payinfo = Db::name("pay_ment")->where("sid","=",$sid)->field("id,payNo,contector,supplierNo,name,pay_method,pay_rate,dpay_fee,inv_rate,rate,dpay_rate,pay_stages,return_img,remark,pay_status,dstatus,pay_remark")->find();
  745. if(empty($payinfo)){
  746. return error_show(1004,"付款申请信息未找到");
  747. }
  748. $payinfo['return_img'] = isset($payinfo['return_img']) && $payinfo['return_img']!="" ? explode(",",$payinfo['return_img']):"";
  749. $paylist = Db::name("pay_info")->where([["payNo","=",$payinfo['payNo']],["status","=",1]])->column("sequenceNo");
  750. $payinfo['list']=[];
  751. if($paylist){
  752. $list = Db::name("cgd_info")->alias('a')->join('cfp_supplier_info b','a.ShortText1617861287265=b.code','left')
  753. ->join("cfp_cgd_inv c",'c.cgdNo=a.sequenceNo','left')
  754. ->where([["a.sequenceNo","in",$paylist],["a.status","=",1]])->field("a.id,
  755. `a`.`sequenceNo` AS `sequenceNo`,
  756. `a`.`ownerName` AS `ownerName`,
  757. `a`.`department` AS `department`,
  758. b.code as supplierNo,
  759. `a`.`ShortText1618315935182` AS `cgdNO`,
  760. `b`.`name` AS `name`,
  761. `b`.`contector` AS `contector`,
  762. `b`.`mobile` AS `mobile`,
  763. `a`.`ShortText1617861001482` AS `goodNo`,
  764. `a`.`ShortText1617861966146` AS `goodName`,
  765. `a`.`ShortText1617865626160` AS `goodType`,
  766. `a`.`ShortText1617865633070` AS `goodBank`,
  767. `a`.`ShortText1617865675342` AS `goodModel`,
  768. `a`.`ShortText1617865678025` AS `goodMaterial`,
  769. `a`.`ShortText1617865680605` AS `goodColor`,
  770. `a`.`text1618268357055` AS `goodDesc`,
  771. `a`.`ShortText1617865685744` AS `goodUnit`,
  772. `a`.`ShortText1618240134229` AS `goodCat`,
  773. ifnull( `a`.`Number1618240480148`, '0' ) AS `weight`,
  774. ifnull( `a`.`Number1618240458074`, '0' ) AS `price`,
  775. `a`.`ShortText1617866158120` AS `isDiff`,
  776. `a`.`number1618240356104` AS `workDay`,
  777. `a`.`ShortText1617865688485` AS `taxPoint`,
  778. `a`.`Number1617865804813` AS `nakedPrice`,
  779. `a`.`Number1617865807879` AS `markPrice`,
  780. `a`.`Number1617865810822` AS `packPrice`,
  781. `a`.`Number1617865813284` AS `certPrice`,
  782. `a`.`Number1617865816181` AS `openPrice`,
  783. `a`.`number1618240204358` AS `craftPrice`,
  784. `a`.`number1618240287778` AS `postPrice`,
  785. `a`.`Number1617865818517` AS `totalPrice`,
  786. `a`.`Number1618240685904` AS `purchasePrice`,
  787. `a`.`Number1618240600907` AS `orderNum`,
  788. `a`.`Number1618330470625` AS `pay_fee`,
  789. `a`.`Number1618330472961` AS `wait_fee`,
  790. `a`.`Number1618330541286` AS `inv_open_fee`,
  791. `a`.`Number1618330543270` AS `inv_wait_fee`,
  792. `a`.`ShortText1619463188366` AS `payinfo`,
  793. `a`.`ShortText1619463208482` AS `invinfo`,
  794. a.th_status as th_info,
  795. a.ShortText1618859321070 as send_info,
  796. `a`.`Number1619632826654` AS `diff_fee`,
  797. `a`.`Number1619632830397` AS `diff_info`,
  798. createdTime,
  799. a.Date1618315953443 as DownTime,
  800. IF
  801. (( `a`.`sequenceStatus` = 'COMPLETED' ), 2, 1 ) AS `order_status`,
  802. ifnull( `c`.`companyNo`, '' ) AS `inv_company`,
  803. ifnull( `c`.`status`, '0' ) AS `inv_status`,
  804. ifnull( `c`.`id`, '0' ) AS `invid`")
  805. ->select();
  806. $data=[];
  807. foreach ($list as $key=>$value){
  808. $value['pay_price'] =sprintf( "%.2f",$value['totalPrice']*$value['orderNum']);
  809. if($value['inv_company']!=""){
  810. $invcom = Db::name("company_info")->where([['companyNo',"=",$value['inv_company']],['status',"=",1]])
  811. ->find();
  812. $value['inv_company_name'] =isset($invcom['company_name']) ? $invcom['company_name']:"";
  813. }else{
  814. $value['inv_company_name'] ="";
  815. }
  816. $data[]=$value;
  817. }
  818. $payinfo['list']=$data;
  819. }
  820. return app_show(0,"获取成功",$payinfo);
  821. }
  822. /**发票新建添加
  823. * @return \think\response\Json|void
  824. * @throws \think\db\exception\DataNotFoundException
  825. * @throws \think\db\exception\DbException
  826. * @throws \think\db\exception\ModelNotFoundException
  827. * @throws \think\exception\DbException
  828. */
  829. public function invAdd(){
  830. $post = $this->post;
  831. $payNo = isset($post['payNo'])&&$post['payNo']!='' ? $post['payNo']:"";
  832. if($payNo==""){
  833. return error_show(1004,"参数 payNo 不能为空");
  834. }
  835. $payinfo =Db::name("pay")->where(["payNo"=>$payNo,"is_del"=>0])->find();
  836. if($payinfo==false){
  837. return error_show(1004,"对账单数据未找到");
  838. }
  839. if($payinfo['status']!=3){
  840. return error_show(1004,"对账单数据未完成审核");
  841. }
  842. $type = isset($post['invType']) && $post['invType']!="" ? intval($post['invType']):"";
  843. if($type==''){
  844. return error_show(1004,"参数 invType 不能为空");
  845. }
  846. $invNumber =isset($post['invNumber'])&& $post['invNumber']!='' ? trim($post['invNumber']):"";
  847. $invCode =isset($post['invCode'])&& $post['invCode']!='' ? trim($post['invCode']):"";
  848. $checkNumber =isset($post['checkNumber'])&& $post['checkNumber']!='' ? trim($post['checkNumber']):"";
  849. $openTime =isset($post['open_time'])&& $post['open_time']!='' ? trim($post['open_time']):"";
  850. if($type==1){
  851. if($invNumber=="") return error_show(1004,"参数 invNumber 不能为空");
  852. if($invCode=="") return error_show(1004,"参数 invCode 不能为空");
  853. // if($checkNumber=="") return error_show(1004,"参数 checkNumber 不能为空");
  854. if($openTime=="") return error_show(1004,"参数 open_time 不能为空");
  855. }
  856. $invimg = isset($post['inv_img'])&& $post['inv_img']!='' ? trim($post['inv_img']):"";
  857. $invName = isset($post['invName'])&& $post['invName']!='' ? trim($post['invName']):"";
  858. if($type==2){
  859. if($invimg=="")return error_show(1004,"参数 inv_img 不能为空");
  860. if($invName=="")return error_show(1004,"参数 invName 不能为空");
  861. }
  862. if ($type==3){
  863. }
  864. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payNo,"is_del"=>0])->column("cgdNo");
  865. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  866. Db::startTrans();
  867. try{
  868. $hpNo=makeNo("hp");
  869. $data=[
  870. "payNo"=>$payNo,
  871. "hpNo"=>$hpNo,
  872. "apply_id"=>$this->uid,
  873. "apply_name"=>$this->uname,
  874. "inv_fee"=> '',
  875. "invType"=> $type,
  876. "invoiceType"=>0,
  877. "inv_img"=>$invimg,
  878. "invName"=>$invName,
  879. "invoiceNumber"=>$invNumber,
  880. "invoiceCode"=>$invCode,
  881. "checkNumber"=>$checkNumber,
  882. "open_time"=>$openTime,
  883. "addtime"=>date("Y-m-d H:i:s"),
  884. "updatetime"=>date("Y-m-d H:i:s")
  885. ];
  886. $inadd =Db::name("pay_invoice")->insert($data);
  887. if ($inadd){
  888. foreach ($cgdNo as $value){
  889. $report=ReportCode::where(["cgdNo"=>$value])->find();
  890. $report->setField("hpNo",$hpNo);
  891. }
  892. Db::commit();
  893. return app_show(0,"回票新建成功",['hpNo'=>$hpNo]);
  894. }
  895. Db::rollback();
  896. return error_show(1004,"回票申请新建失败");
  897. }catch (\Exception $e){
  898. Db::rollback();
  899. return error_show(1004,$e->getMessage());
  900. }
  901. }
  902. /**
  903. * 发票审核状态
  904. * 0 上传发票,1待识别验证 2 待校验识别 3 待财务审核 6 待认证 7认证成功待确认完成 8回票完成 9识别失败 10 验证失败 11 财务驳回 12 认证失败
  905. * @return \think\response\Json|void
  906. * @throws \think\db\exception\DataNotFoundException
  907. * @throws \think\db\exception\DbException
  908. * @throws \think\db\exception\ModelNotFoundException
  909. * @throws \think\exception\DbException
  910. */
  911. public function invStatus(){
  912. $post = $this->post;
  913. $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? $post['hpNo'] :"";
  914. if($hpNo==""){
  915. return error_show(1004,"参数 hpNo 不能为空");
  916. }
  917. $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
  918. if($status==""){
  919. return error_show(1004,"参数status 不能为空");
  920. }
  921. if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){
  922. return error_show(1004,"参数status 无效值");
  923. }
  924. $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find();
  925. if($payment==false){
  926. return error_show(1005,"未找到回票申请信息");
  927. }
  928. $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
  929. if($payinfo==false){
  930. return error_show(1005,"未找到对账信息");
  931. }
  932. if($payinfo['status']!=3){
  933. return error_show(1005,"对账信息未完成审核");
  934. }
  935. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
  936. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  937. if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
  938. Db::startTrans();
  939. try {
  940. $invup =["status"=>$status,"updatetime"=>date("Y-m-d H:i:s")];
  941. $inv =Db::name("pay_invoice")->where($payment)->update($invup);
  942. if($inv){
  943. if($status==8){
  944. $payupdate =[
  945. "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'],
  946. "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
  947. "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2,
  948. "updatetime" => date("Y-m-d H:i:s")
  949. ];
  950. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  951. if($pay==false){
  952. Db::rollback();
  953. return error_show(1003,"回票申请状态更新成功");
  954. }
  955. }
  956. if($status==11){
  957. $payupdate =[
  958. "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'],
  959. "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
  960. "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2,
  961. "updatetime" => date("Y-m-d H:i:s")
  962. ];
  963. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  964. if($pay==false){
  965. Db::rollback();
  966. return error_show(1003,"回票申请状态更新成功");
  967. }
  968. foreach ($cgdNo as $value){
  969. $report=ReportCode::where(["cgdNo"=>$value])->find();
  970. $report->rmField("hpNo",$hpNo);
  971. }
  972. }
  973. Db::commit();
  974. return app_show(0,"回票申请更新成功");
  975. }
  976. Db::rollback();
  977. return error_show(1003,"回票申请状态更新成功");
  978. }catch (\Exception $e){
  979. Db::rollback();
  980. return error_show(1004,$e->getMessage());
  981. }
  982. }
  983. /**发票列表识别
  984. * @param int $id
  985. * @return \think\Response
  986. */
  987. public function InvList()
  988. {
  989. $post = $this->post;
  990. $condition = [["is_del","=",0 ]];
  991. $invtype = isset($post['invType'])&&$post['invType']!='' ? intval($post['invType']):"";
  992. if ($invtype!=''){
  993. $condition[]=["invType","=",$invtype];
  994. }
  995. $hpNo = isset($post['hpNo'])&&$post['hpNo']!='' ? trim($post['hpNo']):"";
  996. if ($hpNo!=''){
  997. $condition[]=["hpNo","like","%$hpNo%"];
  998. }
  999. $invoiceType = isset($post['invoiceType'])&&$post['invoiceType']!='' ? intval($post['invoiceType']):"";
  1000. if ($invoiceType!=''){
  1001. $condition[]=["invoiceType","=",$invoiceType];
  1002. }
  1003. $status = isset($post['status'])&&$post['status']!="" ? intval($post['status']):"";
  1004. if($status!=""){
  1005. $condition[]=["status","=",$status];
  1006. }
  1007. $invNumber = isset($post['invNumber'])&&$post['invNumber']!="" ? trim($post['invNumber']):"";
  1008. if($invNumber!=''){
  1009. $condition[]=["invoiceNumber","=",$invNumber];
  1010. }
  1011. $invCode = isset($post['invCode'])&&$post['invCode']!="" ? trim($post['invCode']):"";
  1012. if($invCode!=''){
  1013. $condition[]=["invoiceCode","=",$invCode];
  1014. }
  1015. $start = isset($post['start']) && $post['start']!="" ? $post['start'] :"";
  1016. if($start!=""){
  1017. $condition[]=["addtime",">=",$start." 00:00:00"];
  1018. }
  1019. $end = isset($post['end']) && $post['end']!="" ? $post['end'] :"";
  1020. if($end!=""){
  1021. $condition[]=["addtime","<=",$end." 23:59:59"];
  1022. }
  1023. $open_start = isset($post['open_start']) && $post['open_start']!="" ? $post['open_start'] :"";
  1024. if($open_start!=""){
  1025. $condition[]=["open_time",">=",$open_start." 00:00:00"];
  1026. }
  1027. $open_end = isset($post['open_end']) && $post['open_end']!="" ? $post['open_end'] :"";
  1028. if($open_end!=""){
  1029. $condition[]=["open_time","<=",$open_end." 23:59:59"];
  1030. }
  1031. $apply_id = isset($post['apply_id']) && $post['apply_id']!="" ? $post['apply_id'] :"";
  1032. if($apply_id!=""){
  1033. $condition[]=["apply_id","=",$apply_id];
  1034. }
  1035. $apply_name = isset($post['apply_name']) && $post['apply_name']!="" ? trim($post['apply_name']):"";
  1036. if($apply_name!=""){
  1037. $condition[]=["apply_name","like","%$apply_name%"];
  1038. }
  1039. $page = isset($post['page'])&&$post['page']!="" ? intval($post['page']):1;
  1040. $size = isset($post['size'])&&$post['size']!="" ? intval($post['size']):10;
  1041. $count =Db::name("pay_invoice")->where($condition)->count();
  1042. $total = ceil($count/$size);
  1043. $page = $page>$total? intval($total):$page;
  1044. $list = Db::name("pay_invoice")->where($condition)->page($page,$size)->select();
  1045. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  1046. }
  1047. /**发票删除
  1048. * @return \think\response\Json|void
  1049. * @throws \think\db\exception\DataNotFoundException
  1050. * @throws \think\db\exception\DbException
  1051. * @throws \think\db\exception\ModelNotFoundException
  1052. */
  1053. public function invDel(){
  1054. $post = $this->post;
  1055. $hpNo = isset($post['hpNo'])&&$post['hpNo']!="" ? trim($post['hpNo']) :"";
  1056. if ($hpNo==""){
  1057. return error_show(1004,"参数 hpNo 不能为空");
  1058. }
  1059. $payinv =Db::name("pay_invoice")->where(["hpNo"=>$hpNo,"is_del"=>0])->find();
  1060. if($payinv==false){
  1061. return error_show(1004,"对账单回票申请未找到数据");
  1062. }
  1063. $payinfo= Db::name("pay")->where([['payNo',"=",$payinv['payNo']],['is_del',"=",0]])->find();
  1064. if($payinfo==false){
  1065. return error_show(1005,"未找到对账信息");
  1066. }
  1067. if($payinfo['status']!=3){
  1068. return error_show(1005,"对账信息未完成审核");
  1069. }
  1070. $cgdNo =Db::name("pay_info")->where(["payNo"=>$payinv['payNo'],"is_del"=>0])->column("cgdNo");
  1071. if(empty($cgdNo)) return error_show(1004,"未找到对账采购单信息");
  1072. Db::startTrans();
  1073. try{
  1074. $update=["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")];
  1075. $invup =Db::name("pay_invoice")->where($payinv)->update($update);
  1076. if($invup){
  1077. if($payinv['status']==8){
  1078. if($payinfo['ainv_fee']< $payinv['inv_fee']){
  1079. Db::rollback();
  1080. return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
  1081. }
  1082. $payupdate =[
  1083. "ainv_fee"=>$payinfo['ainv_fee']-$payinv['inv_fee'],
  1084. "winv_fee"=>$payinfo['winv_fee']+$payinv['inv_fee'],
  1085. "inv_status" => ($payinfo['ainv_fee']-$payinv['inv_fee'])==0?1:2,
  1086. "updatetime" => date("Y-m-d H:i:s")
  1087. ];
  1088. $pay =Db::name("pay")->where($payinfo)->update($payupdate);
  1089. if($pay==false){
  1090. Db::rollback();
  1091. return error_show(1003,"删除失败");
  1092. }
  1093. foreach ($cgdNo as $value){
  1094. $report=ReportCode::where(["cgdNo"=>$value])->find();
  1095. $report->rmField("hpNo",$hpNo);
  1096. }
  1097. }
  1098. Db::commit();
  1099. return app_show(0,"删除成功");
  1100. }
  1101. }catch (\Exception $e){
  1102. Db::rollback();
  1103. return error_show(1003,$e->getMessage());
  1104. }
  1105. }
  1106. public function UnPay(){
  1107. $post = $this->post;
  1108. $token = isset($post['token']) ? trim($post['token']) : "";
  1109. if($token==""){
  1110. return error_show(101,'token不能为空');
  1111. }
  1112. $effetc = VerifyTokens($token);
  1113. if(!empty($effetc) && $effetc['code']!=0){
  1114. return error_show($effetc['code'],$effetc['message']);
  1115. }
  1116. $codeNo = isset($post['id'])&&$post['id']!=="" ? trim($post['id']) :'';
  1117. if($codeNo===""){
  1118. return error_show(1004,'参数id 不能为空');
  1119. }
  1120. $update = Db::name('cgd_info')->where("id","in",$codeNo)->update(['status'=>2,"updatetime"=>date("Y-m-d
  1121. H:i:s")]);
  1122. // echo Db::name('cgd_info')->getLastSql();
  1123. if($update){
  1124. return app_show(0,'更新成功');
  1125. }else{
  1126. return error_show(1004,'更新失败');
  1127. }
  1128. }
  1129. }