OrderInv.php 63 KB

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