OrderInv.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\admin\model\ReportCode;
  5. use think\App;
  6. use think\facade\Config;use think\facade\Db;
  7. use think\facade\Cache;
  8. class OrderInv extends BaseController{
  9. public function __construct(App $app) {
  10. parent::__construct($app);
  11. }
  12. /**
  13. * 新建销售单开票申请
  14. */
  15. public function create(){
  16. $companyType = isset($this->post['companyType'])&&$this->post['companyType']!=='' ? trim($this->post['companyType']):"";
  17. if ($companyType==''){
  18. return error_show(1004,"参数 companyType 不能为空");
  19. }
  20. $buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):"";
  21. if($buy_id==''){
  22. return error_show(1004,"参数 buy_id 不能为空");
  23. }
  24. $buyinfo =Db::name("customer_invoice")->where(['id'=>$buy_id,"is_del"=>0])->find();
  25. if($buyinfo==false){
  26. return error_show(1004,"购买方发票信息未找到");
  27. }
  28. $companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=='' ? trim($this->post['companyNo']):"";
  29. if($companyNo==''){
  30. return error_show(1004,"参数 companyNo 不能为空");
  31. }
  32. $company = Db::name("company_info")->where(["companyNo"=>$companyNo])->find();
  33. if($company==false){
  34. return error_show(1004,"销售方信息未找到");
  35. }
  36. // $khNo = isset($this->post['khNo'])&&$this->post['khNo']!=='' ? trim($this->post['khNo']):"";
  37. // if($khNo==''){
  38. // return error_show(1004,"参数 khNo 不能为空");
  39. // }
  40. // $customer = Db::name("customer_info")->where(["companyNo"=>$khNo])->find();
  41. // if($customer==false){
  42. // return error_show(1004,"客户信息未找到");
  43. // }
  44. $invtype = isset($this->post['invtype'])&&$this->post['invtype']!=='' ? intval($this->post['invtype']):"";
  45. if($invtype==''){
  46. return error_show(1004,"参数 invtype 不能为空");
  47. }
  48. $email = isset($this->post['email'])&&$this->post['email']!=='' ? trim($this->post['email']):"";
  49. $remark = isset($this->post['remark'])&&$this->post['remark']!=='' ? trim($this->post['remark']):"";
  50. $orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr']) ? $this->post['orderArr']:[];
  51. if(empty($orderArr)){
  52. return error_show(1004,"参数 orderArr 不能为空");
  53. }
  54. $temp =[];
  55. $good=[];
  56. $invNo=makeNo("INV");
  57. $invfee=array_sum(array_column($orderArr,'inv_fee'));
  58. Db::startTrans();
  59. try{
  60. foreach ($orderArr as $value){
  61. if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){
  62. Db::rollback();
  63. return error_show(1004,"参数 sequenceNo 不能为空");
  64. }
  65. $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find();
  66. if($qrd['status']==2){
  67. Db::rollback();
  68. return error_show(1004,"确认单{$value['sequenceNo']}不参与对账");
  69. }
  70. if(!isset($value['inv_fee']) || $value['inv_fee']===''){
  71. Db::rollback();
  72. return error_show(1004,"参数 inv_fee 不能为空");
  73. }
  74. if($qrd['winv_fee']<$value['inv_fee']){
  75. Db::rollback();
  76. return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
  77. }
  78. $good_info = Db::name("good")->where(["spuCode"=>$qrd["goodNo"],"status"=>1])->findOrEmpty();
  79. if(empty($good_info)){
  80. Db::rollback();
  81. return error_show(1004,"确认单{$value['sequenceNo']}商品未确认开票类目");
  82. }
  83. $ascc=[
  84. "assocNo"=>makeNo("AS"),
  85. "apply_id"=>$this->uid,
  86. "apply_name"=>$this->uname,
  87. "type"=>1,
  88. "orderCode"=>$value['sequenceNo'],
  89. "customerNo"=>$qrd['customerNo'],
  90. "viceCode"=>$invNo,
  91. "order_total"=>$qrd['totalPrice'],
  92. "vice_total"=>$invfee,
  93. "cancel_fee"=>$value['inv_fee'],
  94. "status"=>1,
  95. "addtime"=>date("Y-m-d H:i:s"),
  96. "updatetime"=>date("Y-m-d H:i:s")
  97. ];
  98. $invoice_good=[
  99. "invNo"=>$invNo,
  100. "orderCode"=>$value['sequenceNo'],
  101. "goodNo"=>$qrd['goodNo'],
  102. "goodName"=>$good_info['inv_good_name'],
  103. "catName"=>$good_info['inv_cat_name'],
  104. "catNo"=>$good_info['inv_cat_code'],
  105. "goodPrice"=>round($value['inv_fee']/$value['num'],8),
  106. "unitName"=>$qrd['goodUnit'],
  107. "goodNum"=>$value['num'],
  108. "specInfo"=>'',
  109. "totalPrice"=>$value['inv_fee'],
  110. "tax"=>$good_info['inv_tax'],
  111. "is_discount"=>$good_info['is_discount'],
  112. "addTax"=>$good_info['addTax'],
  113. "inv_tag"=>$good_info['inv_tag'],
  114. "taxPrice"=>round($value['inv_fee']*$good_info['inv_tax'],2),
  115. "addtime"=>date("Y-m-d H:i:s"),
  116. "updatetime"=>date("Y-m-d H:i:s")
  117. ];
  118. $update = [
  119. "inv_fee"=>$qrd['inv_fee']+$value['inv_fee'],
  120. "winv_fee"=>$qrd['winv_fee']-$value['inv_fee'],
  121. "inv_status"=>2,
  122. "status"=>1,
  123. "updatetime"=>date("Y-m-d H:i:s")
  124. ];
  125. $up = Db::name("qrd_info")->where($qrd)->update($update);
  126. if($up==false){
  127. Db::rollback();
  128. return error_show(1005,"确认单{$value['sequenceNo']} 更新失败");
  129. }
  130. $temp[]=$ascc;
  131. $good[]=$invoice_good;
  132. $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find();
  133. if($report)$report->setField("invNo",$invNo);
  134. }
  135. $associn = Db::name("assoc")->insertAll($temp);
  136. if($associn==0){
  137. Db::rollback();
  138. return error_show(1005,"确认单申请开票失败");
  139. }
  140. $goodin = Db::name("invoice_good")->insertAll($good);
  141. if($goodin==0){
  142. Db::rollback();
  143. return error_show(1005,"确认单申请开票失败");
  144. }
  145. $inv=[
  146. "invNo"=>$invNo,
  147. "inv_value"=>$invfee,
  148. "inv_out"=> $companyNo,
  149. "apply_id"=>$this->uid,
  150. "apply_name"=>$this->uname,
  151. "inv_type"=>$invtype,//发票类型 专用 普通 电子专用 电子普通
  152. "open_type"=>0, //开票类型 金税开票 金税线下 纯线下
  153. "is_ticket"=>$company['out_ticket'], //是否支持金税开票
  154. "company_type"=> $buyinfo['company_type'], //类型01 企业,02 机关事业单位,03 个人, 04 其他
  155. "remark"=>$remark, //申请备注
  156. "exam_remark"=>'', //审核备注
  157. "ainv_fee"=>0,//已核销金额
  158. "winv_fee"=>$invfee,//未核销金额
  159. "status"=>0,// 待财务开票/待金税开票 待财务审核 待填写物流 开票完成 开票失败/开票驳回 财务驳回
  160. "is_del"=>0,
  161. "email"=>$email,
  162. "addtime"=>date("Y-m-d H:i:s"),
  163. "updatetime"=>date("Y-m-d H:i:s")
  164. ];
  165. $invin = Db::name("invoice_pool")->insert($inv);
  166. if($invin){
  167. $invinfo=[
  168. "buyer_title"=>$buyinfo['invoice_title'],
  169. "buyer_code"=>$buyinfo['invoice_code'],
  170. "buyer_addr"=>$buyinfo['invoice_addr'],
  171. "buyer_mobile"=>$buyinfo['invoice_mobile'],
  172. "buyer_bank"=>$buyinfo['invoice_bank'],
  173. "buyer_bankNo"=>$buyinfo['invoice_bankNo'],
  174. "seller_title"=>$company['company_name'],
  175. "seller_code"=>$company['company_license'],
  176. "seller_addr"=>$company['company_address'],
  177. "seller_mobile"=>$company['mobile'],
  178. "seller_bank"=>$company['bank_name'],
  179. "seller_bankNo"=>$company['bankNo'],
  180. "invNo"=>$invNo,
  181. "voider"=>$company['voider'],
  182. "payee"=>$company['payee'],
  183. "drawer"=>$company['drawer'],
  184. "reviewer"=>$company['reviewer'],
  185. "ownerPlace"=>$company['ownerPlace'],
  186. "addtime"=>date("Y-m-d H:i:s")
  187. ];
  188. $poolinfo =Db::name("invoice_pool_info")->insert($invinfo);
  189. if($poolinfo){
  190. Db::commit();
  191. return app_show(0,"确认单发票申请成功",["invNo"=>$invNo]);
  192. }
  193. }
  194. Db::rollback();
  195. return error_show(1004,"确认单发票申请失败");
  196. }catch (\Exception $e){
  197. Db::rollback();
  198. return error_show(1004,$e->getMessage());
  199. }
  200. }
  201. // 0 待财务开票/待金税开票 1待财务审核 2待填写物流 3开票完成 4开票失败/开票驳回 5财务驳回 6退票 7金税开票中
  202. public function status(){
  203. $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
  204. if($invNo==""){
  205. return error_show(1004,"参数 invNo 不能为空");
  206. }
  207. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
  208. if($invinfo==false){
  209. return error_show(1004,"发票申请数据未找到");
  210. }
  211. $status= isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
  212. if($status===''){
  213. return error_show(1004,"参数 status 不能为空");
  214. }
  215. //open_type 1 金税开票 2 金税线下开票 3 线下开票
  216. $open_type = isset($this->post['open_type'])&&$this->post['open_type']!==''?intval($this->post['open_type']):"";
  217. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  218. // $invArr=isset($this->post['invArr'])&&!empty($this->post['invArr'])?$this->post['invArr']:[];
  219. $invCode =isset($this->post['invCode'])&&$this->post['invCode']!=''?trim($this->post['invCode']):"";
  220. $invNum =isset($this->post['invNum'])&&$this->post['invNum']!=''?trim($this->post['invNum']):"";
  221. $open_date =isset($this->post['open_date'])&&$this->post['open_date']!=''?trim($this->post['open_date']):"";
  222. $total_fee =isset($this->post['total_fee'])&&$this->post['total_fee']!=''?floor($this->post['total_fee']):"";
  223. $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floor($this->post['subtotal_fee']):"";
  224. if($status==1){
  225. if($open_type==='')return error_show(1004,"参数 open_type 不能为空");
  226. if($open_type!=1){
  227. if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
  228. if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
  229. if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
  230. if($total_fee==='') return error_show(1004,"参数 tatal_fee 不能为空");
  231. if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
  232. if($total_fee!=$invinfo['inv_value'])return error_show(1004,"发票金额不足");
  233. }else{
  234. $status=7;
  235. }
  236. }
  237. $update=[
  238. "status"=>$status,
  239. "exam_remark"=>$remark,
  240. "updatetime" => date("Y-m-d H:i:s")
  241. ];
  242. $status==1 ? $update['open_type']=$open_type :"";
  243. Db::startTrans();
  244. try{
  245. $invup =Db::name("invoice_pool")->where($invinfo)->update($update);
  246. if($invup){
  247. if($status==1&& $open_type!=1){
  248. $invpool=[
  249. "invNo"=>$invinfo['invNo'],
  250. "inv_type"=>$open_type,
  251. "inv_code"=>$invCode,
  252. "inv_number"=>$invNum,
  253. "inv_total"=>$total_fee,
  254. "inv_subtotal"=>$subtotal_fee,
  255. "open_date"=>$open_date,
  256. "item"=>'',
  257. "status"=>0,
  258. "addtime"=>date("Y-m-d H:i:s"),
  259. "updatetime"=>date("Y-m-d H:i:s")
  260. ];
  261. $in = Db::name("invoice_ticket")->insert($invpool);
  262. if($in==false){
  263. Db::rollback();
  264. return error_show(1004,"发票信息添加失败");
  265. }
  266. }
  267. if($status==7 && $open_type==1){
  268. $invpoolinfo =Db::name("invoice_pool_info")->where(["invNo"=>$invNo])->findOrEmpty();
  269. if(empty($invpoolinfo)){
  270. Db::rollback();
  271. return error_show(1004,"开票信息未找到");
  272. }
  273. $goodinfo =Db::name("invoice_good")
  274. ->where(["invNo"=>$invNo,"is_del"=>0])
  275. ->field("0 as FPHXZ,
  276. catNo as SPBM,
  277. id as ZXBM,
  278. is_discount as YHZCBS,
  279. if(inv_tag==0,'',inv_tag) as LSLBS,
  280. addTax as ZZSTSGL,
  281. goodName as XMMC,
  282. unitName as DW,
  283. goodNum as SPSL,
  284. goodPrice as DJ,
  285. totalPrice as JE,
  286. 1 HSBZ,
  287. tax as SL,
  288. taxPrice as SE")
  289. ->select()->toJson();
  290. if(empty($goodinfo)){
  291. Db::rollback();
  292. return error_show(1004,"开票商品信息未找到");
  293. }
  294. $data=[
  295. "invNo"=>$invNo,
  296. "KPLX"=>"0",
  297. "XHFSBH"=>$invpoolinfo['seller_code'],
  298. "XHFMC"=>$invpoolinfo['seller_title'],
  299. "XHFDZ"=>$invpoolinfo['seller_addr'],
  300. "XHFDH"=>$invpoolinfo['seller_mobile'],
  301. "XHFYH"=>$invpoolinfo['seller_bank'],
  302. "XHFZH"=>$invpoolinfo['seller_bankNo'],
  303. "GMFBM"=>"",
  304. "GMFSBH"=>$invpoolinfo['buyer_code'],
  305. "GMFMC"=>$invpoolinfo['buyer_title'],
  306. "GMFDZ"=>$invpoolinfo['buyer_addr'],
  307. "GMFDH"=>$invpoolinfo['buyer_mobile'],
  308. "GMFYH"=>$invpoolinfo['buyer_bank'],
  309. "GMFZH"=>$invpoolinfo['buyer_bankNo'],
  310. "GMFLX"=>$invinfo['company_type'],
  311. "GMFSJH"=>"",
  312. "GMFDZYX"=>$invinfo['email'],
  313. "KPR"=>$invpoolinfo['drawer'],
  314. "SKR"=>$invpoolinfo['payee'],
  315. "FHR"=>$invpoolinfo['reviewer'],
  316. "QDBZ"=>"0",
  317. "JSHJ"=>$invinfo['inv_value'],
  318. "HJJE"=>"0",
  319. "HJSE"=>"0",
  320. "BZ"=>"",
  321. "DDMXXX"=>$goodinfo,
  322. "FPLXDM"=>invoiceType($invinfo['inv_type']),
  323. "DDQQPCH"=>"",
  324. "DDQQLSH"=>randomkeys(26).date("YmdHis"),
  325. "status"=>"0",
  326. "result"=>"",
  327. "addtime"=>date("Y-m-d H:i:s"),
  328. "updatetime"=>date("Y-m-d H:i:s")
  329. ];
  330. $invoice=Db::name("invoice_interface")->insert($data);
  331. if($invoice==false){
  332. Db::rollback();
  333. return error_show(1003,"开票信息生成失败");
  334. }
  335. Cache::push("invoiceList",$data["DDQQLSH"]);
  336. }
  337. if($status==4 ||$status==5 ){
  338. $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->column("id,orderCode,cancel_fee");
  339. if(!empty($qrdArr)){
  340. foreach ($qrdArr as $value){
  341. $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
  342. if($qrdinfo==false){
  343. Db::rollback();
  344. return error_show(1003,"确认单信息未找到");
  345. }
  346. if($qrdinfo['inv_fee']<$value['cancel_fee']){
  347. Db::rollback();
  348. return error_show(1003,"确认单信息开票金额不足");
  349. }
  350. $update =[
  351. "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
  352. "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
  353. "inv_status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 1 : 2,
  354. "status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ?0 : 1,
  355. "updatetime"=>date("Y-m-d H:i:s"),
  356. ];
  357. $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
  358. if($qrdup==false){
  359. Db::rollback();
  360. return error_show(1003,"确认单信息更新失败");
  361. }
  362. $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
  363. $assocup =Db::name("assoc")->where($value)->update($assoc);
  364. if($assocup==false){
  365. Db::rollback();
  366. return error_show(1003,"确认单关联信息更新失败");
  367. }
  368. $report=ReportCode::where(["qrdNo"=>$value['sequenceNo']])->find();
  369. if($report)$report->rmField("invNo",$invinfo['invNo']);
  370. }
  371. }
  372. }
  373. Db::commit();
  374. return app_show(0,"审核成功");
  375. }
  376. Db::rollback();
  377. return error_show(1004,"审核失败");
  378. }catch (\Exception $e){
  379. Db::rollback();
  380. return error_show(1004,$e->getMessage());
  381. }
  382. }
  383. /**
  384. * 发票设置物流
  385. */
  386. public function SetPost(){
  387. // @param invNo postCompany postCode postFee;
  388. $invNo =isset($this->post['invNo'])&&$this->post['invNo']!="" ? trim($this->post['invNo']):"";
  389. if($invNo==''){
  390. return error_show(1004,"参数invNo不能为空");
  391. }
  392. $invinfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
  393. if($invinfo==false){
  394. return error_show(1004,"发票申请信息未找到");
  395. }
  396. $post_company =isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
  397. if($post_company==''){
  398. return error_show(1004,"参数 post_company 不能为空");
  399. }
  400. $post_code =isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  401. if($post_code==''){
  402. return error_show(1004,"参数 post_code 不能为空");
  403. }
  404. $post_fee =isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? floor($this->post['post_fee']):"0";
  405. Db::startTrans();
  406. try{
  407. $data=[
  408. "post_company"=>$post_company,
  409. "post_code"=>$post_code,
  410. "post_fee"=>$post_fee,
  411. "status"=>3,
  412. "updatetime"=>date("Y-m-d H:i:s")
  413. ];
  414. $up =Db::name("invoice_pool")->where($invinfo)->update($data);
  415. if($up){
  416. $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0])->column("id,orderCode,cancel_fee");
  417. if(!empty($qrdArr)){
  418. foreach ($qrdArr as $value){
  419. $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
  420. if($qrdinfo==false){
  421. Db::rollback();
  422. return error_show(1003,"确认单信息未找到");
  423. }
  424. if($qrdinfo['inv_fee']<$value['cancel_fee']){
  425. Db::rollback();
  426. return error_show(1003,"确认单信息开票金额不足");
  427. }
  428. $update =[
  429. "ainv_fee"=>$qrdinfo['ainv_fee']+$value['cancel_fee'],
  430. "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
  431. "invtime"=>date("Y-m-d H:i:s"),
  432. "inv_status"=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2,
  433. "updatetime"=>date("Y-m-d H:i:s"),
  434. ];
  435. $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
  436. if($qrdup==false){
  437. Db::rollback();
  438. return error_show(1003,"确认单信息更新失败");
  439. }
  440. $assoc=["status"=>2,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")];
  441. $assocup =Db::name("assoc")->where($value)->update($assoc);
  442. if($assocup==false){
  443. Db::rollback();
  444. return error_show(1003,"确认单关联信息更新失败");
  445. }
  446. }
  447. }
  448. Db::commit();
  449. return app_show(0,"更新成功");
  450. }
  451. Db::rollback();
  452. return error_show(1003,"发票申请信息更新失败");
  453. }catch (\Exception $e){
  454. Db::rollback();
  455. return error_show(1004,$e->getMessage());
  456. }
  457. }
  458. /**
  459. * 发票废弃使用
  460. */
  461. public function Discard(){
  462. $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
  463. if($invNo=='') return error_show(1004,"参数invNo不能为空");
  464. $invinfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
  465. if($invinfo==false) return error_show(1004,"未找到对应发票申请数据");
  466. if(!in_array($invinfo['status'],[1,2,3,5]))return error_show(1004,"发票状态无法废弃");
  467. $company =Db::name("company_info")->where(["companyNo"=>$invinfo['inv_out']])->find();
  468. if($company==false)return error_show(1004,"开票业务公司未找到");
  469. $invoice =Db::name("invoice_ticket")->where(["invNo"=>$invNo])->find();
  470. if($invoice==false)return error_show(1004,"发票详细信息未找到");
  471. Db::startTrans();
  472. try{
  473. $invoice=Config::get("invoice");
  474. $tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
  475. $result=$tax->DeprecateInvoices($company['company_license'],invoiceType($invinfo['inv_type']),$invoice['inv_code'],$invoice['inv_number'],1);
  476. if(isset($result['ZTDM']) && $result['ZTDM']=='050000'){
  477. $up =Db::name("invoice_pool")->where($invinfo)->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
  478. if($up){
  479. if($invinfo['status']!=5){
  480. $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"is_del"=>0,"status"=>[1,2]])->column("id,orderCode,cancel_fee");
  481. if(!empty($qrdArr)){
  482. foreach ($qrdArr as $value){
  483. $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
  484. if($qrdinfo==false){
  485. Db::rollback();
  486. return error_show(1003,"确认单信息未找到");
  487. }
  488. if ($invinfo['status']==3){
  489. if($qrdinfo['ainv_fee']<$value['cancel_fee']){
  490. Db::rollback();
  491. return error_show(1003,"确认单信息开票金额不足");
  492. }
  493. $update =[
  494. "ainv_fee"=>$qrdinfo['ainv_fee']-$value['cancel_fee'],
  495. "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
  496. "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee'] ==0 ? 1: 2,
  497. "updatetime"=>date("Y-m-d H:i:s"),
  498. ];
  499. }else{
  500. if($qrdinfo['inv_fee']<$value['cancel_fee']){
  501. Db::rollback();
  502. return error_show(1003,"确认单信息开票金额不足");
  503. }
  504. $update =[
  505. "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
  506. "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
  507. "inv_status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee']) ==0 ?1 : 2,
  508. "updatetime"=>date("Y-m-d H:i:s"),
  509. ];
  510. }
  511. $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
  512. if($qrdup==false){
  513. Db::rollback();
  514. return error_show(1003,"确认单信息更新失败");
  515. }
  516. $assoc=["status"=>3,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")];
  517. $assocup =Db::name("assoc")->where($value)->update($assoc);
  518. if($assocup==false){
  519. Db::rollback();
  520. return error_show(1003,"确认单关联信息更新失败");
  521. }
  522. }
  523. }
  524. }
  525. Db::commit();
  526. return app_show(0,"发票废弃成功");
  527. }
  528. }
  529. Db::rollback();
  530. return error_show(1004,"发票废弃失败");
  531. }catch (\Exception $e){
  532. Db::rollback();
  533. return error_show(1004,$e->getMessage());
  534. }
  535. }
  536. /**@param invNo return_reason remark 退票申请
  537. * @return \think\response\Json|void
  538. */
  539. public function ReturnAdd(){
  540. $invNo = isset($this->post['invNo']) && $this->post['invNo']!=''? trim($this->post['invNo']) :'';
  541. if($invNo==""){
  542. return error_show(1004,"参数 invNo 不能为空");
  543. }
  544. $return_reason = isset($this->post['return_reason']) && $this->post['return_reason']!=''? trim($this->post['return_reason']) :'';
  545. $remark = isset($this->post['remark']) && $this->post['remark']!=''? trim($this->post['remark']) :'';
  546. if($return_reason==""){
  547. return error_show(1004,"参数 return_reason 不能为空");
  548. }
  549. if($remark==""){
  550. return error_show(1004,"参数 remark 不能为空");
  551. }
  552. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
  553. if($invinfo==false){
  554. return error_show(1004,"发票申请数据未找到");
  555. }
  556. if($invinfo['status']!=3){
  557. return error_show(1004,"发票申请未完成");
  558. }
  559. $qrd =Db::name("assoc")->where(["viceCode"=>$invNo,"status"=>2,"is_del"=>0])->column("orderCode");
  560. if(empty($qrd)){
  561. return error_show(1004,"未找到开票的销售单信息");
  562. }
  563. $returnCode = makeNo("RIN");
  564. $data=[
  565. "returnCode"=>$returnCode,
  566. "invNo"=>$invNo,
  567. "return_reason"=>$return_reason,
  568. "remark"=>$remark,
  569. "status"=>0,
  570. "apply_id"=>$this->uid,
  571. "apply_name"=>$this->uname,
  572. "addtime"=>date("Y-m-d H:i:s"),
  573. "updatetime"=>date("Y-m-d H:i:s")
  574. ];
  575. $inter = Db::name("invoice_return")->insert($data);
  576. if($inter){
  577. foreach ($qrd as $value){
  578. $report=ReportCode::where(["qrdNo"=>$value])->find();
  579. if($report)$report->setField("returnInv",$returnCode);
  580. }
  581. return app_show(0,"退票申请新建成功",["returnCode"=>$returnCode]);
  582. }else{
  583. return error_show(1005,"退票申请新建失败");
  584. }
  585. }
  586. // 0 待审核 1 待退票 2 退票成功 3 驳回4 退票失败
  587. public function ReturnStatus(){
  588. $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  589. if($returnCode==""){
  590. return error_show(1005,"参数 returnCode 不能为空");
  591. }
  592. $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):"";
  593. if ($status==""){
  594. return error_show(1005,"参数 status 不能为空");
  595. }
  596. $return_type = isset($this->post['return_type'])&&$this->post['return_type']!="" ? intval($this->post['return_type']):"";
  597. if ($return_type==""){
  598. return error_show(1005,"参数 return_type 不能为空");
  599. }
  600. $remark =isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
  601. if($remark==""){
  602. return error_show(1005,"参数 remark 不能为空");
  603. }
  604. $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
  605. if($return==false){
  606. return error_show(1005,"退票申请信息未找到");
  607. }
  608. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find();
  609. if($invinfo==false){
  610. return error_show(1004,"发票申请数据未找到");
  611. }
  612. if($invinfo['status']!=3){
  613. return error_show(1004,"发票申请未完成");
  614. }
  615. $qrd =Db::name("assoc")->where(["viceCode"=>$return['invNo'],"status"=>2,"is_del"=>0])->column("orderCode");
  616. if(empty($qrd)){
  617. return error_show(1004,"未找到开票的销售单信息");
  618. }
  619. Db::startTrans();
  620. try{
  621. $update=["status"=>$status,"return_type"=>$return_type,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
  622. $up =Db::name("invoice_return")->where($return)->update($update);
  623. if($up){
  624. if($status==2){
  625. $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0,"status"=>[1,2]])->column("id,orderCode,cancel_fee");
  626. if(!empty($qrdArr)){
  627. foreach ($qrdArr as $value){
  628. $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
  629. if($qrdinfo==false){
  630. Db::rollback();
  631. return error_show(1003,"确认单信息未找到");
  632. }
  633. if($qrdinfo['inv_fee']<$value['cancel_fee']){
  634. Db::rollback();
  635. return error_show(1003,"确认单信息开票金额不足");
  636. }
  637. $update =[
  638. "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
  639. "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
  640. "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 ? 1 : 2,
  641. "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1,
  642. "updatetime"=>date("Y-m-d H:i:s"),
  643. ];
  644. $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
  645. if($qrdup==false){
  646. Db::rollback();
  647. return error_show(1003,"确认单信息更新失败");
  648. }
  649. $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
  650. $assocup =Db::name("assoc")->where($value)->update($assoc);
  651. if($assocup==false){
  652. Db::rollback();
  653. return error_show(1003,"确认单关联信息更新失败");
  654. }
  655. }
  656. }
  657. }
  658. if($status==3 || $status==4){
  659. foreach ($qrd as $value){
  660. $report=ReportCode::where(["qrdNo"=>$value])->find();
  661. if($report)$report->rmField("returnInv",$returnCode);
  662. }
  663. }
  664. Db::commit();
  665. return app_show(0,"退票申请信息更新成功");
  666. }
  667. Db::rollback();
  668. return error_show(1005,"退票申请信息更新失败");
  669. }catch (\Exception $e){
  670. Db::rollback();
  671. return error_show(1005,$e->getMessage());
  672. }
  673. }
  674. //红冲票
  675. public function returnRed(){
  676. $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  677. if($returnCode==""){
  678. return error_show(1005,"参数 returnCode 不能为空");
  679. }
  680. $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
  681. if($return==false){
  682. return error_show(1005,"退票申请信息未找到");
  683. }
  684. $redinv =isset($this->post['redinv'])&&$this->post['redinv']!="" ? trim($this->post['redinv']):"";
  685. if($redinv==""){
  686. return error_show(1005,"参数 redinv 不能为空");
  687. }
  688. $red =Db::name("invoice_red")->where(["invRed"=>$redinv,"is_del"=>0])->findOrEmpty();
  689. if(empty($red)) return error_show(1005,"红冲发票信息未找到");
  690. if($red['status']!=4) return error_show(1005,"红冲发票开票未完成");
  691. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find();
  692. if($invinfo==false){
  693. return error_show(1005,"发票申请信息未找到");
  694. }
  695. Db::startTrans();
  696. try{
  697. $update=["status"=>2,"red_inv"=>$redinv,"updatetime"=>date("Y-m-d H:i:s")];
  698. $up =Db::name("invoice_return")->where($return)->update($update);
  699. if($up){
  700. $invup = ["status"=>6,"updatetime"=>date("Y-m-d H:i:s")];
  701. $inv=Db::name("invoice_pool")->where($invinfo)->update($invup);
  702. if($inv){
  703. $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"is_del"=>0])->column("id,orderCode,cancel_fee");
  704. if(!empty($qrdArr)){
  705. foreach ($qrdArr as $value){
  706. $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
  707. if($qrdinfo==false){
  708. Db::rollback();
  709. return error_show(1003,"确认单信息未找到");
  710. }
  711. if($qrdinfo['inv_fee']<$value['cancel_fee']){
  712. Db::rollback();
  713. return error_show(1003,"确认单信息开票金额不足");
  714. }
  715. $update =[
  716. "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
  717. "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
  718. "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 ? 1 : 2,
  719. "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1,
  720. "updatetime"=>date("Y-m-d H:i:s"),
  721. ];
  722. $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
  723. if($qrdup==false){
  724. Db::rollback();
  725. return error_show(1003,"确认单信息更新失败");
  726. }
  727. $assoc=["status"=>3,"updatetime"=>date("Y-m-d H:i:s")];
  728. $assocup =Db::name("assoc")->where($value)->update($assoc);
  729. if($assocup==false){
  730. Db::rollback();
  731. return error_show(1003,"确认单关联信息更新失败");
  732. }
  733. }
  734. }
  735. Db::commit();
  736. return app_show(0,"退票申请信息更新成功");
  737. }
  738. }
  739. Db::rollback();
  740. return error_show(1005,"退票申请信息更新失败");
  741. }catch (\Exception $e){
  742. Db::rollback();
  743. return error_show(1005,$e->getMessage());
  744. }
  745. }
  746. //退票详情
  747. public function returnInfo(){
  748. $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  749. if($returnCode==""){
  750. return error_show(1005,"参数 returnCode 不能为空");
  751. }
  752. $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
  753. if($return==false){
  754. return error_show(1005,"退票申请信息未找到");
  755. }
  756. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find();
  757. $return['inv_out']= $invinfo['inv_out']??"";
  758. $return['inv_value']= $invinfo['inv_value']??"";
  759. $return['inv_apply_id']= $invinfo['apply_id']??"";
  760. $return['inv_apply_name']= $invinfo['apply_name']??"";
  761. $return['inv_type']= $invinfo['inv_type']??"";
  762. $return['open_type']= $invinfo['open_type']??"";
  763. $return['is_ticket']= $invinfo['is_ticket']??"";
  764. $return['email']= $invinfo['email']??"";
  765. $return['post_code']= $invinfo['post_code']??"";
  766. $return['post_company']= $invinfo['post_company']??"";
  767. $poolinfo = Db::name("invoice_pool_info")->where(["invNo"=>$return['invNo']])->find();
  768. $return['buyer_title'] = $poolinfo['buyer_title']??'';
  769. $return['buyer_code'] = $poolinfo['buyer_code']??'';
  770. $return['buyer_addr'] = $poolinfo['buyer_addr']??'';
  771. $return['buyer_mobile'] = $poolinfo['buyer_mobile']??'';
  772. $return['buyer_bank'] = $poolinfo['buyer_bank']??'';
  773. $return['buyer_bankNo'] = $poolinfo['buyer_bankNo']??'';
  774. $return['seller_title'] = $poolinfo['seller_title']??'';
  775. $return['seller_addr'] = $poolinfo['seller_addr']??'';
  776. $return['seller_code'] = $poolinfo['seller_code']??'';
  777. $return['seller_mobile'] = $poolinfo['seller_mobile']??'';
  778. $return['seller_bank'] = $poolinfo['seller_bank']??'';
  779. $return['seller_bankNo'] = $poolinfo['seller_bankNo']??'';
  780. $return['voider'] = $poolinfo['voider']??'';
  781. $return['payee'] = $poolinfo['payee']??'';
  782. $return['drawer'] = $poolinfo['drawer']??'';
  783. $return['reviewer'] = $poolinfo['reviewer']??'';
  784. $return['ownerPlace'] = $poolinfo['ownerPlace']??'';
  785. $orderList =Db::name("invoice_good")->where(["invNo"=>$return['invNo'],"is_del"=>0])->select()->toArray();
  786. $return['goodList']=$orderList;
  787. return app_show(0,"获取成功",$return);
  788. }
  789. /**
  790. *发票池列表
  791. */
  792. public function list(){
  793. $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
  794. $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
  795. $condition=[["a.is_del","=",0]];
  796. $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
  797. $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
  798. if($start!=""){
  799. $condition[]=["a.addtime",">=",$start." 00:00:00"];
  800. }
  801. if($end!=""){
  802. $condition[]=["a.addtime","<=",$end." 23:59:59"];
  803. }
  804. $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  805. if($status!==""){
  806. $condition[]=["a.status","=",$status];
  807. }
  808. $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
  809. if($inv_type!==""){
  810. $condition[]=["a.inv_type","=",$inv_type];
  811. }
  812. $inv_out= isset($this->post['inv_out'])&&$this->post['inv_out']!=="" ? trim($this->post['inv_out']):"";
  813. if($inv_out!==""){
  814. $condition[]=["a.inv_out","=",$inv_out];
  815. }
  816. // $inv_in = isset($this->post['inv_in'])&&$this->post['inv_in']!=="" ? trim($this->post['inv_in']):"";
  817. // if($inv_in!==""){
  818. // $condition[]=["a.inv_in","=",$inv_in];
  819. // }
  820. $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
  821. if($invNo!==""){
  822. $condition[]=["a.invNo","like","%$invNo%"];
  823. }
  824. $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
  825. if($apply_id!==""){
  826. $condition[]=["a.apply_id","=",$apply_id];
  827. }
  828. $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
  829. if($apply_name!==""){
  830. $condition[]=["a.apply_name","like","%$apply_name%"];
  831. }
  832. $count=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where
  833. ($condition)->count();
  834. $total =ceil($count/$size);
  835. $page= $page>$total ? intval($total):$page;
  836. $list=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where($condition)
  837. ->page($page,$size)->order("a.addtime desc")->select()->toArray();
  838. foreach ($list as &$item) {
  839. $company =Db::name("company_info")->where(["companyNo"=>$item['inv_out']])->find();
  840. // $kehu =Db::name("customer_info")->where(["companyNo"=>$item['inv_in']])->find();
  841. $item['companyName'] = $company['company_name']??"";
  842. // $item['customerName'] = $kehu['companyName']??"";
  843. }
  844. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  845. }
  846. //获取发票详情
  847. public function info(){
  848. $invNo = isset($this->post['invNo'])&& $this->post['invNo']!='' ? trim($this->post['invNo']):"";
  849. if($invNo==''){
  850. return error_show(1004,"参数 invNo 不能为空");
  851. }
  852. $poolinfo =Db::name("invoice_pool")->where([["invNo","=",$invNo],["is_del","=",0]])->findOrEmpty();
  853. if(empty($poolinfo)){
  854. return error_show(1004,"为找到开票信息");
  855. }
  856. $company =Db::name("company_info")->where(["companyNo"=>$poolinfo['inv_out']])->find();
  857. $poolinfo['companyName'] = $company['company_name']??"";
  858. $pool = Db::name("invoice_pool_info")->where(["invNo"=>$invNo])->find();
  859. $poolinfo['buyer_title'] = $pool['buyer_title']??'';
  860. $poolinfo['buyer_code'] = $pool['buyer_code']??'';
  861. $poolinfo['buyer_addr'] = $pool['buyer_addr']??'';
  862. $poolinfo['buyer_mobile'] = $pool['buyer_mobile']??'';
  863. $poolinfo['buyer_bank'] = $pool['buyer_bank']??'';
  864. $poolinfo['buyer_bankNo'] = $pool['buyer_bankNo']??'';
  865. $poolinfo['seller_title'] = $pool['seller_title']??'';
  866. $poolinfo['seller_addr'] = $pool['seller_addr']??'';
  867. $poolinfo['seller_code'] = $pool['seller_code']??'';
  868. $poolinfo['seller_mobile'] = $pool['seller_mobile']??'';
  869. $poolinfo['seller_bank'] = $pool['seller_bank']??'';
  870. $poolinfo['seller_bankNo'] = $pool['seller_bankNo']??'';
  871. $poolinfo['voider'] = $pool['voider']??'';
  872. $poolinfo['payee'] = $pool['payee']??'';
  873. $poolinfo['drawer'] = $pool['drawer']??'';
  874. $poolinfo['reviewer'] = $pool['reviewer']??'';
  875. $poolinfo['ownerPlace'] = $pool['ownerPlace']??'';
  876. $orderList =Db::name("invoice_good")->where(["invNo"=>$invNo,"is_del"=>0])->select()->toArray();
  877. $poolinfop['goodList']=$orderList;
  878. return app_show(0,"获取成功",$poolinfo);
  879. }
  880. //退票列表
  881. public function returnList(){
  882. $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
  883. $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
  884. $condition=[["b.is_del","=",0]];
  885. $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
  886. $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
  887. if($start!=""){
  888. $condition[]=["a.addtime",">=",$start." 00:00:00"];
  889. }
  890. if($end!=""){
  891. $condition[]=["a.addtime","<=",$end." 23:59:59"];
  892. }
  893. $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
  894. if($inv_type!==""){
  895. $condition[]=["b.inv_type","=",$inv_type];
  896. }
  897. $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
  898. if($apply_id!==""){
  899. $condition[]=["a.apply_id","=",$apply_id];
  900. }
  901. $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
  902. if($apply_name!==""){
  903. $condition[]=["a.apply_name","like","%$apply_name%"];
  904. }
  905. $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  906. if($status!==""){
  907. $condition[]=["a.status","=",$status];
  908. }
  909. $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
  910. if($invNo!==""){
  911. $condition[]=["a.invNo","like","%$invNo%"];
  912. }
  913. $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!=="" ? trim($this->post['returnCode']):"";
  914. if($returnCode!==""){
  915. $condition[]=["a.returnCode","like","%$returnCode%"];
  916. }
  917. $count=Db::name("invoice_return")->alias("a")
  918. ->leftJoin("invoice_pool b","a.invNo=b.invNo")
  919. ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
  920. ->where($condition)->count();
  921. $total =ceil($count/$size);
  922. $page= $page>$total ? intval($total):$page;
  923. $list=Db::name("invoice_return")->alias("a")
  924. ->leftJoin("invoice_pool b","a.invNo=b.invNo")
  925. ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
  926. ->where($condition)->page($page,$size)->field("a.*,c.buyer_title,c.buyer_code,c.buyer_addr,c.buyer_mobile,c.buyer_bank,
  927. c.buyer_bankNo,c.seller_title,c.seller_code,c.seller_addr,c.seller_mobile,c.seller_bank,c.seller_bankNo,c.voider,c.payee,
  928. c.drawer,c.reviewer,c.ownerPlace,b.inv_value,b.inv_out,b.inv_type,b.open_type,is_ticket,b.email,
  929. b.winv_fee,b.ainv_fee,b.post_fee,b.post_company,b.post_code")->order("id desc")->select()->toArray();
  930. foreach ($list as &$value){
  931. $company =Db::name("company_info")->where(["companyNo"=>$value['inv_out']])->find();
  932. $value['companyName'] = $company['company_name']??"";
  933. }
  934. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  935. }
  936. //红冲申请
  937. public function applyRed(){
  938. $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
  939. if($invNo=='')return error_show(1004,"参数 invNo 不能为空");
  940. $invfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
  941. if($invfo==false) return error_show(1004,"发票数据未找到");
  942. if(!in_array($invfo['status'],[1,2,3,4,5]))return error_show(1004,"发票数据状态无法申请");
  943. $ticket =Db::name("invoice_ticket")->where(["invNo"=>$invNo])->findOrEmpty();
  944. if(empty($ticket)) return error_show(1004,"未找到开票信息");
  945. $company =Db::name("company_info")->where(["companyNo"=>$invfo['inv_out']])->findOrEmpty();
  946. if(empty($company)) return error_show(1004,"业务企业信息未找到");
  947. $invoice=Config::get("invoice");
  948. $Tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
  949. $redticketList=[];
  950. $redticketArry=[
  951. "SQBSCQQPCH"=>randomkeys(26).date("YmdHis"),
  952. "NSRSBH"=>$company['company_license'],
  953. "FPLXDM"=>invoiceType($invfo['inv_type']),
  954. ];
  955. $goodinfo =Db::name("invoice_good")
  956. ->where(["invNo"=>$invNo,"is_del"=>0])
  957. ->field("0 as FPHXZ,
  958. catNo as SPBM,
  959. id as ZXBM,
  960. is_discount as YHZCBS,
  961. if(inv_tag=0,'',inv_tag) as LSLBS,
  962. addTax as ZZSTSGL,
  963. goodName as XMMC,
  964. unitName as DW,
  965. -goodNum as SPSL,
  966. goodPrice as DJ,
  967. -totalPrice as JE,
  968. 1 HSBZ,
  969. tax as SL,
  970. -taxPrice as SE")
  971. ->select()->toArray();
  972. if(empty($goodinfo)){
  973. Db::rollback();
  974. return error_show(1004,"开票商品信息未找到");
  975. }
  976. $info=[
  977. "SQBSCQQLSH"=>randomkeys(29).date("YmdHis"),
  978. "YYSBZ"=> "0000000000", //营业税标志
  979. "XXBLX"=> "0",//信息表类型 0 正常;1 逾期(仅销方开具)
  980. "YFPDM"=>$ticket['inv_code'], //红字专票购方已抵扣可不填
  981. "YFPHM"=> $ticket['inv_number'],//红字专票购方已抵扣可不填
  982. "YFPKPRQ"=>$ticket['open_date'], //红字专票购方已抵扣可不填
  983. "TKSJ"=>date("YmdHis"), //填开时间
  984. "XHFSBH"=>$ticket['seller_id'],
  985. "XHFMC"=>$ticket['seller_title'],
  986. "GMFSBH"=>$ticket['buyer_id'],
  987. "GMFMC"=> $ticket['buyer_title'],
  988. "HJJE"=> "-".$ticket['inv_total'],//合计金额(不含 税)
  989. "HJSE"=>"-".$ticket['tax_fee'],//合计税额
  990. "SQSM"=>"", //申请说明
  991. "XXBTSBS"=>"0",//0: 正常;1:成品油发票,涉及销售数量 变更(销货退回、开票有误等原因);2: 成品油发票,仅涉及销售金额变更(销 售折让);3:机动车发票,仅涉及销售数
  992. //量变更(销货退回、开票有误等原因);4: 机动车发票,仅涉及销售金额变更(销 售折让)
  993. ];
  994. $invRed=makeNo("IRE");
  995. $data=[
  996. 'invNo'=>$invNo,
  997. "invRed"=>$invRed,
  998. "apply_id"=>$this->uid,
  999. "apply_name"=>$this->uname,
  1000. "status"=>0,
  1001. "remark"=>'',
  1002. "addtime"=>date("Y-m-d H:i:s"),
  1003. "updatetime"=>date("Y-m-d H:i:s"),
  1004. "SQBSCQQLSH"=>$info['SQBSCQQLSH'],
  1005. "YYSBZ"=> "0000000000", //营业税标志
  1006. "XXBLX"=> "0",//信息表类型 0 正常;1 逾期(仅销方开具)
  1007. "YFPDM"=>$ticket['inv_code'], //红字专票购方已抵扣可不填
  1008. "YFPHM"=> $ticket['inv_number'],//红字专票购方已抵扣可不填
  1009. "YFPKPRQ"=>$ticket['open_date'], //红字专票购方已抵扣可不填
  1010. "TKSJ"=>date("YmdHis"), //填开时间
  1011. "XHFSBH"=>$ticket['seller_id'],
  1012. "XHFMC"=>$ticket['seller_title'],
  1013. "GMFSBH"=>$ticket['buyer_id'],
  1014. "GMFMC"=> $ticket['buyer_title'],
  1015. "HJJE"=> "-".$ticket['inv_total'],//合计金额(不含 税)
  1016. "HJSE"=>"-".$ticket['tax_fee'],//合计税额
  1017. "SQSM"=>"", //申请说明
  1018. "XXBTSBS"=>"0",
  1019. "DDMXX"=>json_encode($goodinfo,JSON_UNESCAPED_UNICODE),
  1020. "SQBSCQQPCH"=>$redticketArry['SQBSCQQPCH'],
  1021. "FPLXDM"=>invoiceType($invfo['inv_type']),
  1022. ];
  1023. $redticketList[]=["HZSQDTXX"=>$info,"DDMXXX"=>$goodinfo];
  1024. $result=$Tax->AllocateRedInvoiceApplication($redticketArry,$redticketList);
  1025. $data['status']=5;
  1026. $data['remark']='红冲申请提交失败';
  1027. if(isset($result['ZTDM']) && $result['ZTDM']=='060000'){
  1028. $resultChild=$result['HZSQDSCJG'][0];
  1029. if($resultChild['ZTDM']=='060000'){
  1030. $data['status']=2;
  1031. $data['remark']='红冲申请审核通过';
  1032. }
  1033. if($resultChild['ZTDM']=='060001'){
  1034. $data['status']=1;
  1035. $data['remark']='红冲申请审核中';
  1036. }
  1037. }
  1038. $up =Db::name("invoice_red")->insert($data);
  1039. return $up ? app_show(0,"红冲发票申请新建成功",["invRed"=>$invRed]):error_show(1004,"红冲发票申请新建失败");
  1040. }
  1041. //批量申请红冲发票
  1042. public function batchApplyRed(){
  1043. $invArr = isset($this->post['invArr'])&&!empty($this->post['invArr'])?$this->post['invArr']:[];
  1044. if(empty($invArr))return error_show(1004,"参数 invArr 不能为空");
  1045. $invfo =Db::name("invoice_pool")->where(["invNo"=>$invArr,"is_del"=>0])->select()->toArray();
  1046. if(empty($invfo)) return error_show(1004,"发票数据未找到");
  1047. $insertAll=[];
  1048. $companyCode = array_unique(array_column($invfo,"inv_out"));
  1049. $inv_type = array_unique(array_column($invfo,"inv_type"));
  1050. if(count($companyCode)>1){
  1051. return error_show(1004,"业务企业公司不统一");
  1052. }
  1053. if(count($inv_type)>1){
  1054. return error_show(1004,"发票类型不统一");
  1055. }
  1056. $company =Db::name("company_info")->where(["companyNo"=>$companyCode])->findOrEmpty();
  1057. if(empty($company)) {
  1058. return error_show(1004,"业务企业信息未找到");
  1059. }
  1060. $ticketArr=Db::name("invoice_ticket")->where(["invNo"=>$invArr,"is_del"=>0])->column("*","invNo");
  1061. if(empty($ticketArr)){
  1062. return error_show(1004,"未找到开票信息");
  1063. }
  1064. $invoice=Config::get("invoice");
  1065. $Tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
  1066. Db::startTrans();
  1067. try{
  1068. $redticketArry=[
  1069. "SQBSCQQPCH"=>randomkeys(26).date("YmdHis"),
  1070. "NSRSBH"=>$company['company_license'],
  1071. "FPLXDM"=>invoiceType($inv_type[0]),
  1072. ];
  1073. $redticketList=[];
  1074. foreach ($invfo as $value){
  1075. if(!in_array($value['status'],[1,2,3,4,5])){
  1076. Db::rollback();
  1077. return error_show(1004,"发票数据状态无法申请");
  1078. }
  1079. $ticket =$ticketArr[$value['invNo']] ??[];
  1080. if(empty($ticket)){
  1081. Db::rollback();
  1082. return error_show(1004,"未找到开票信息");
  1083. }
  1084. $goodinfo =Db::name("invoice_good")
  1085. ->where(["invNo"=>$value['invNo'],"is_del"=>0])
  1086. ->field("0 as FPHXZ,
  1087. catNo as SPBM,
  1088. id as ZXBM,
  1089. is_discount as YHZCBS,
  1090. if(inv_tag=0,'',inv_tag) as LSLBS,
  1091. addTax as ZZSTSGL,
  1092. goodName as XMMC,
  1093. unitName as DW,
  1094. -goodNum as SPSL,
  1095. goodPrice as DJ,
  1096. -totalPrice as JE,
  1097. 1 HSBZ,
  1098. tax as SL,
  1099. -taxPrice as SE")
  1100. ->select()->toArray();
  1101. if(empty($goodinfo)){
  1102. Db::rollback();
  1103. return error_show(1004,"开票商品信息未找到");
  1104. }
  1105. $info=[
  1106. "SQBSCQQLSH"=>randomkeys(26).date("YmdHis"),
  1107. "YYSBZ"=> "0000000000", //营业税标志
  1108. "XXBLX"=> "0",//信息表类型 0 正常;1 逾期(仅销方开具)
  1109. "YFPDM"=>$ticket['inv_code'], //红字专票购方已抵扣可不填
  1110. "YFPHM"=> $ticket['inv_number'],//红字专票购方已抵扣可不填
  1111. "YFPKPRQ"=>$ticket['open_date'], //红字专票购方已抵扣可不填
  1112. "TKSJ"=>date("YmdHis"), //填开时间
  1113. "XHFSBH"=>$ticket['seller_id'],
  1114. "XHFMC"=>$ticket['seller_title'],
  1115. "GMFSBH"=>$ticket['buyer_id'],
  1116. "GMFMC"=> $ticket['buyer_title'],
  1117. "HJJE"=> "-".$ticket['inv_total'],//合计金额(不含 税)
  1118. "HJSE"=>"-".$ticket['tax_fee'],//合计税额
  1119. "SQSM"=>"1100000000", //申请说明
  1120. "XXBTSBS"=>"0",//0: 正常;1:成品油发票,涉及销售数量 变更(销货退回、开票有误等原因);2: 成品油发票,仅涉及销售金额变更(销 售折让);3:机动车发票,仅涉及销售数
  1121. //量变更(销货退回、开票有误等原因);4: 机动车发票,仅涉及销售金额变更(销 售折让)
  1122. ];
  1123. $data=[
  1124. 'invNo'=>$value['invNo'],
  1125. "invRed"=>makeNo("IRE"),
  1126. "apply_id"=>$this->uid,
  1127. "apply_name"=>$this->uname,
  1128. "status"=>5,
  1129. "remark"=>'红冲申请提交失败',
  1130. "addtime"=>date("Y-m-d H:i:s"),
  1131. "updatetime"=>date("Y-m-d H:i:s"),
  1132. "SQBSCQQLSH"=>$info['SQBSCQQLSH'],
  1133. "YYSBZ"=> "0000000000", //营业税标志
  1134. "XXBLX"=> "0",//信息表类型 0 正常;1 逾期(仅销方开具)
  1135. "YFPDM"=>$ticket['inv_code'], //红字专票购方已抵扣可不填
  1136. "YFPHM"=> $ticket['inv_number'],//红字专票购方已抵扣可不填
  1137. "YFPKPRQ"=>$ticket['open_date'], //红字专票购方已抵扣可不填
  1138. "TKSJ"=>date("YmdHis"), //填开时间
  1139. "XHFSBH"=>$ticket['seller_id'],
  1140. "XHFMC"=>$ticket['seller_title'],
  1141. "GMFSBH"=>$ticket['buyer_id'],
  1142. "GMFMC"=> $ticket['buyer_title'],
  1143. "HJJE"=> "-".$ticket['inv_total'],//合计金额(不含 税)
  1144. "HJSE"=>"-".$ticket['tax_fee'],//合计税额
  1145. "SQSM"=>"1100000000", //申请说明
  1146. "XXBTSBS"=>"0",
  1147. "DDMXXX"=>json_encode($goodinfo,JSON_UNESCAPED_UNICODE),
  1148. "SQBSCQQPCH"=>$redticketArry['SQBSCQQPCH'],
  1149. "FPLXDM"=>invoiceType($value['inv_type']),
  1150. ];
  1151. $redticketList[]=["HZSQDTXX"=>$info,"DDMXXX"=>$goodinfo];
  1152. $insertAll[$info['SQBSCQQLSH']]=$data;
  1153. }
  1154. $result=$Tax->AllocateRedInvoiceApplication($redticketArry,$redticketList);
  1155. if(isset($result['ZTDM']) && $result['ZTDM']=='060000'){
  1156. if(isset($result['HZSQDSCJG']) && count($result['HZSQDSCJG'])>0){
  1157. foreach ($result['HZSQDSCJG'] as $value){
  1158. if($value['ZTDM']=='060000'){
  1159. $insertAll[$value['SQBSCQQLSH']]['status']=2;
  1160. $insertAll[$value['SQBSCQQLSH']]['remark']="红冲申请审核通过";
  1161. // $data['status']=2;
  1162. // $data['remark']='红冲申请审核通过';
  1163. }
  1164. if($value['ZTDM']=='060001'){
  1165. $insertAll[$value['SQBSCQQLSH']]['status']=1;
  1166. $insertAll[$value['SQBSCQQLSH']]['remark']="红冲申请审核中";
  1167. }
  1168. }
  1169. }
  1170. }
  1171. $uns= Db::name("invoice_red")->insertAll($insertAll);
  1172. if($uns==count($insertAll)){
  1173. Db::commit();
  1174. return app_show(0,"红冲发票申请新建成功");
  1175. }
  1176. Db::rollback();
  1177. return error_show(1004,"红冲发票申请新建失败");
  1178. }catch (\Exception $e){
  1179. Db::rollback();
  1180. return error_show(1004,$e->getMessage());
  1181. }
  1182. }
  1183. //红票申请开票
  1184. public function redOpen(){
  1185. $invRed= isset($this->post['invRed'])&&$this->post['invRed']!=''? $this->post['invRed']:"";
  1186. if($invRed==''){
  1187. return error_show(1004,"参数 invRed 不能为空");
  1188. }
  1189. $redinfo =Db::name("invoice_red")->where(["invRed"=>$invRed,"is_del"=>0])->findOrEmpty();
  1190. if(empty($redinfo)){
  1191. return error_show(1004,"红冲发票申请不存在");
  1192. }
  1193. $redreason = isset($this->post['redreason'])&&$this->post['redreason']!=''? $this->post['redreason']:"";
  1194. if($redreason==''){
  1195. return error_show(1004,"参数 redreason 不能为空");
  1196. }
  1197. if($redinfo['status']!=2){
  1198. return error_show(1004,"红冲发票申请审核未通过");
  1199. }
  1200. $invinfo = Db::name("invoice_pool")->where(["invNo"=>$redinfo['invNo'],"is_del"=>0])->findOrEmpty();
  1201. if(empty($invinfo)) return error_show(1004,"红冲发票原票信息未找到");
  1202. $invpoolinfo = Db::name("invoice_ticket")->where(["invNo"=>$redinfo['invNo'],"status"=>1,"is_del"=>0])->findOrEmpty();
  1203. if(empty($invpoolinfo)) return error_show(1004,"红冲发票开票信息未找到");
  1204. Db::startTrans();
  1205. try{
  1206. $data=[
  1207. "invNo"=>$invRed,
  1208. "KPLX"=>"1",
  1209. "XHFSBH"=>$invpoolinfo['seller_code'],
  1210. "XHFMC"=>$invpoolinfo['seller_title'],
  1211. "XHFDZ"=>$invpoolinfo['seller_addr'],
  1212. "XHFDH"=>$invpoolinfo['seller_mobile'],
  1213. "XHFYH"=>$invpoolinfo['seller_bank'],
  1214. "XHFZH"=>$invpoolinfo['seller_bankNo'],
  1215. "GMFBM"=>"",
  1216. "GMFSBH"=>$invpoolinfo['buyer_code'],
  1217. "GMFMC"=>$invpoolinfo['buyer_title'],
  1218. "GMFDZ"=>$invpoolinfo['buyer_addr'],
  1219. "GMFDH"=>$invpoolinfo['buyer_mobile'],
  1220. "GMFYH"=>$invpoolinfo['buyer_bank'],
  1221. "GMFZH"=>$invpoolinfo['buyer_bankNo'],
  1222. "GMFLX"=>$invinfo['company_type'],
  1223. "GMFSJH"=>"",
  1224. "GMFDZYX"=>$invinfo['email'],
  1225. "KPR"=>$invpoolinfo['issuer'],
  1226. "SKR"=>$invpoolinfo['reciver'],
  1227. "FHR"=>$invpoolinfo['reviewer'],
  1228. "QDBZ"=>"0",
  1229. "YFPDM"=>$redinfo['YFPDM'],
  1230. "YFPHM"=>$redinfo['YFPHM'],
  1231. "YFPLX"=>$invpoolinfo['inv_type'] == '004' || $invpoolinfo['inv_type'] =='028'||$redreason=='' ?'':$invpoolinfo['inv_type'],
  1232. "YFPKPRQ"=>$invpoolinfo['inv_type'] == '004' || $invpoolinfo['inv_type'] == '028'||$redreason=='' ? '':date("Y-m-d",strtotime($redinfo['YFPKPRQ'])),
  1233. "CHYY"=>$invpoolinfo['inv_type'] == '004' || $invpoolinfo['inv_type'] == '028' ? '':$redreason,
  1234. "TSCHBZ"=>"",
  1235. "JSHJ"=>"-".$invpoolinfo['inv_total'],
  1236. "HJJE"=>$invpoolinfo['inv_subtotal'],
  1237. "HJSE"=>$invpoolinfo['tax_fee'],
  1238. "BZ"=>"",
  1239. "DDMXXX"=>$redinfo['DDMXXX'],
  1240. "FPLXDM"=>$redinfo['FPLXDM'],
  1241. "DDQQPCH"=>"",
  1242. "DDQQLSH"=>randomkeys(26).date("YmdHis"),
  1243. "status"=>"0",
  1244. "result"=>"",
  1245. "addtime"=>date("Y-m-d H:i:s"),
  1246. "updatetime"=>date("Y-m-d H:i:s")
  1247. ];
  1248. $invoice=Db::name("invoice_interface")->insert($data);
  1249. if($invoice==false){
  1250. Db::rollback();
  1251. return error_show(1003,"红冲开票信息生成失败");
  1252. }
  1253. $upred=Db::name("invoice_red")->where(["invRed"=>$invRed])->update(["status"=>3,"red_reason"=>$redreason,"updatetime"=>date("Y-m-d H:i:s")]);
  1254. if($upred==false){
  1255. Db::rollback();
  1256. return error_show(1003,"红冲发票信息更新失败");
  1257. }
  1258. Db::commit();
  1259. return app_show(0,"红冲发票信息开票提交成功");
  1260. }catch (\Exception $e){
  1261. Db::rollback();
  1262. return error_show(1003,$e->getMessage());
  1263. }
  1264. }
  1265. //红冲票申请列表
  1266. public function redList(){
  1267. $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
  1268. $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
  1269. $condition=[["is_del","=",0]];
  1270. $invRed=isset($this->post["invRed"])&&$this->post["invRed"]!=''?trim($this->post["invRed"]):"";
  1271. if($invRed!=''){
  1272. $condition[]=["invRed","like","%$invRed%"];
  1273. }
  1274. $apply_id=isset($this->post["apply_id"])&&$this->post["apply_id"]!=''?intval($this->post["apply_id"]):"";
  1275. if($apply_id!=''){
  1276. $condition[]=["apply_id","=",$apply_id];
  1277. }
  1278. $invNo=isset($this->post["invNo"])&&$this->post["invNo"]!=''?trim($this->post["invNo"]):"";
  1279. if($invNo!=''){
  1280. $condition[]=["invNo","like","%$invNo%"];
  1281. }
  1282. $apply_name=isset($this->post["apply_name"])&&$this->post["apply_name"]!=''?trim($this->post["apply_name"]):"";
  1283. if($apply_name!=''){
  1284. $condition[]=["apply_name","like","%$apply_name%"];
  1285. }
  1286. $start = isset($this->post["start"])&&$this->post["start"]!=''?trim($this->post["start"]):"";
  1287. $end = isset($this->post["end"])&&$this->post["end"]!=''?trim($this->post["end"]):"";
  1288. if($start!=''){
  1289. $condition[]=["addtime",">=",$start];
  1290. }
  1291. if($end!=''){
  1292. $condition[]=["addtime","<=",$end];
  1293. }
  1294. $total_low=isset($this->post["total_low"])&&$this->post["total_low"]!=''?floor($this->post["total_low"]):"";
  1295. $total_up=isset($this->post["total_up"])&&$this->post["total_up"]!=''?floor($this->post["total_up"]):"";
  1296. if($total_low!=''){
  1297. $condition[]=["ABS(HJJE)",">=",$total_low];
  1298. }
  1299. if($total_up!=''){
  1300. $condition[]=["ABS(HJJE)","<=",$total_up];
  1301. }
  1302. $count= Db::name("invoice_red")->where($condition)->count();
  1303. $total =ceil($count/$size);
  1304. $page=$total>=$page?$page :intval($total);
  1305. $list =Db::name("invoice_red")->where($condition)->json(["DDMXXX"])->page($page,$size)->order("addtime desc")->select()
  1306. ->toArray();
  1307. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  1308. }
  1309. }