OrderInv.php 63 KB

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