OrderInv.php 63 KB

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