InvCat.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class InvCat extends BaseController{
  7. public function __construct(App $app) {parent::__construct($app);}
  8. //商品关联开票类目
  9. public function AddGood(){
  10. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  11. if($spuCode==''){
  12. return error_show(1004,"参数 spuCode 不能为空");
  13. }
  14. $goodinfo =Db::name("good")->where(["spuCode"=>$spuCode])->findOrEmpty();
  15. if(empty($goodinfo)) return error_show(1004,"商品数据未找到");
  16. $inv_good_name = isset($this->post['inv_good_name'])&&$this->post['inv_good_name']!=''?trim($this->post['inv_good_name']):"";
  17. if($inv_good_name==''){
  18. return error_show(1004,"参数 inv_good_name 不能为空");
  19. }
  20. $tax = isset($this->post['tax'])&&$this->post['tax']!=''?trim($this->post['tax']):"";
  21. if($tax=="") return error_show(1004,"参数 tax 不能为空");
  22. $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
  23. if($cat_code==''){
  24. return error_show(1004,"参数 cat_code 不能为空");
  25. }
  26. $catinfo=Db::name("inv_cat")->where(["cat_code"=>$cat_code])->findOrEmpty();
  27. if(empty($catinfo)) return error_show(1004,"未找到对应的开票类目");
  28. $taxArr=$catinfo['tax']!=''? explode("、",$catinfo['tax']):[];
  29. if(!in_array($tax,$taxArr))return error_show(1004,"未找到对应的开票类目税率");
  30. $data=[
  31. "inv_cat_name"=>$catinfo['short_name'],
  32. "inv_cat_code"=>$catinfo['merge_code'],
  33. "inv_tax"=>$tax,
  34. "inv_good_name"=>$inv_good_name,
  35. "updatetime"=>date("Y-m-d H:i:s")
  36. ];
  37. $up =Db::name("good")->where($goodinfo)->update($data);
  38. return $up? app_show(0,"添加成功"):error_show(1004,"添加失败");
  39. }
  40. //商品列表
  41. public function GoodList(){
  42. $page =isset($this->post['page'])&& $this->post['page']!="" ? intval($this->post['page']) :1;
  43. $size =isset($this->post['size'])&& $this->post['size']!="" ? intval($this->post['size']) :15;
  44. $condition =[];
  45. $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
  46. if($status!==''){
  47. $condition[]=["status","=",$status];
  48. }
  49. $isZx =isset($this->post['isZx'])&&$this->post['isZx']!==''?intval($this->post['isZx']):"";
  50. if($isZx!==''){
  51. $condition[]=["isZx","=",$isZx];
  52. }
  53. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  54. if($spuCode!="") $condition[]=["spuCode","like","%$spuCode%"];
  55. $good_name=isset($this->post['good_name'])&&$this->post['good_name']!=''?trim($this->post['good_name']):"";
  56. if($good_name!="") $condition[]=["good_name","like","%$good_name%"];
  57. $companyNo=isset($this->post['companyNo'])&&$this->post['companyNo']!=''?trim($this->post['companyNo']):"";
  58. if($companyNo!="") $condition[]=["companyNo","like","%$companyNo%"];
  59. $supplierNo=isset($this->post['supplierNo'])&&$this->post['supplierNo']!=''?trim($this->post['supplierNo']):"";
  60. if($supplierNo!="") $condition[]=["supplierNo","like","%$supplierNo%"];
  61. $creater=isset($this->post['creater'])&&$this->post['creater']!=''?trim($this->post['creater']):"";
  62. if($creater!="") $condition[]=["creater","like","%$creater%"];
  63. $count=Db::name("good")->where($condition)->count();
  64. $total=ceil($count/$size);
  65. $page = $page>=$total? intval($total):$page;
  66. $list =Db::name("good")->where($condition)->order("addtime desc")->page($page,$size)->select()->toArray();
  67. foreach ($list as &$value){
  68. $company =Db::name("company_info")->where(["companyNo"=>$value['companyNo']])->find();
  69. $value['companyName']=$company['company_name']??"";
  70. $supplier =Db::name("supplier_info")->where(["code"=>$value["supplierNo"]])->find();
  71. $value["supplierName"]=$supplier["name"]??"";
  72. }
  73. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  74. }
  75. //商品详情
  76. public function goodinfo(){
  77. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  78. if($spuCode=="") return error_show(1004,"参数 spuCode 不能为空");
  79. $goodinfo =Db::name("good")->where(["spuCode"=>$spuCode])->findOrEmpty();
  80. if(empty($goodinfo))return error_show(1004,"商品数据未找到");
  81. $company =Db::name("company_info")->where(["companyNo"=>$goodinfo['companyNo']])->find();
  82. $goodinfo['companyName']=$company['company_name']??"";
  83. $supplier =Db::name("supplier_info")->where(["code"=>$goodinfo["supplierNo"]])->find();
  84. $goodinfo["supplierName"]=$supplier["name"]??"";
  85. return app_show(0,"获取成功",$goodinfo);
  86. }
  87. //发票类目列表
  88. public function catlist(){
  89. $page =isset($this->post['page'])&& $this->post['page']!="" ? intval($this->post['page']) :1;
  90. $size =isset($this->post['size'])&& $this->post['size']!="" ? intval($this->post['size']) :15;
  91. $condition =[];
  92. $cat_name = isset($this->post['cat_name'])&&$this->post['cat_name']!=''?trim($this->post['cat_name']):"";
  93. if($cat_name!=''){
  94. $condition[]=["cat_name|short_name","like","%$cat_name%"];
  95. }
  96. $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
  97. if($cat_code!=''){
  98. $condition[]=["cat_code|merge_code","like","%$cat_code%"];
  99. }
  100. $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
  101. if($status!==''){
  102. $condition[]=["status","=",$status];
  103. }
  104. $count =Db::name("inv_cat")->where($condition)->count();
  105. $total=ceil($count/$size);
  106. $page = $page>=$total? intval($total):$page;
  107. $list =Db::name("inv_cat")->where($condition)->order("addtime desc")->page($page,$size)->select()->toArray();
  108. foreach ($list as &$value){
  109. $value['tax'] = $value['tax']==''?[]:explode("、",$value['tax']);
  110. }
  111. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  112. }
  113. //类目查询
  114. public function query(){
  115. $condition =[];
  116. $cat_name = isset($this->post['cat_name'])&&$this->post['cat_name']!=''?trim($this->post['cat_name']):"";
  117. if($cat_name!=''){
  118. $condition[]=["cat_name|short_name","like","%$cat_name%"];
  119. }
  120. $cat_code = isset($this->post['cat_code'])&&$this->post['cat_code']!=''?trim($this->post['cat_code']):"";
  121. if($cat_code!=''){
  122. $condition[]=["cat_code|merge_code","like","%$cat_code%"];
  123. }
  124. $list =Db::name("inv_cat")->where($condition)->order("addtime desc")->limit(30)->select()->toArray();
  125. foreach ($list as &$value){
  126. $value['tax'] = $value['tax']==''?[]:explode("、",$value['tax']);
  127. }
  128. return app_show(0,"获取成功",$list);
  129. }
  130. }