Title.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Title extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post= $this->request->post();
  13. }
  14. public function create(){
  15. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']):"";
  16. if($companyNo==""){
  17. return error_show(1002,"参数companyNo不能为空");
  18. }
  19. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  20. if($invoice_title==""){
  21. return error_show(1002,"参数invoice_title不能为空");
  22. }
  23. // $invoice_people = isset($this->post['invoice_people']) && $this->post['invoice_people'] !== ""? trim($this->post['invoice_people']):"";
  24. // if($invoice_people==""){
  25. // return error_show(1002,"参数invoice_people不能为空");
  26. // }
  27. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !==""? trim($this->post['invoice_code']):"";
  28. if($invoice_code==""){
  29. return error_show(1002,"参数invoice_code不能为空");
  30. }
  31. $invoice_bank = isset($this->post['invoice_bank']) && $this->post['invoice_bank'] !==""? trim($this->post['invoice_bank']):"";
  32. if($invoice_bank==""){
  33. return error_show(1002,"参数invoice_bank不能为空");
  34. }
  35. $invoice_bankNo = isset($this->post['invoice_bankNo']) && $this->post['invoice_bankNo'] !==""? trim($this->post['invoice_bankNo']):"";
  36. if($invoice_bankNo==""){
  37. return error_show(1002,"参数invoice_bankNo不能为空");
  38. }
  39. $invoice_addr = isset($this->post['invoice_addr']) && $this->post['invoice_addr'] !==""? trim($this->post['invoice_addr']):"";
  40. if($invoice_addr==""){
  41. return error_show(1002,"参数invoice_addr不能为空");
  42. }
  43. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !==""? trim($this->post['invoice_mobile']):"";
  44. if($invoice_mobile==""){
  45. return error_show(1002,"参数invoice_mobile不能为空");
  46. }
  47. $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"1";
  48. $data =[
  49. "companyNo"=>$companyNo,
  50. "invoice_title"=>$invoice_title,
  51. // "invoice_people"=>$invoice_people,
  52. "invoice_code"=>$invoice_code,
  53. "invoice_bank"=>$invoice_bank,
  54. "invoice_bankNo"=>$invoice_bankNo,
  55. "invoice_addr"=>$invoice_addr,
  56. "invoice_mobile"=>$invoice_mobile,
  57. "status"=>$status,
  58. "is_del"=>0,
  59. "addtime"=>date("Y-m-d H:i:s"),
  60. "updatetime"=>date("Y-m-d H:i:s")
  61. ];
  62. $info = Db::name('customer_title')->insert($data);
  63. if($info){
  64. return error_show(0,"新建成功");
  65. }else{
  66. return error_show(1002,"新建失败");
  67. }
  68. }
  69. public function list(){
  70. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  71. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  72. $where =[["a.is_del","=",0]];
  73. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  74. if($invoice_title!=""){
  75. $where[]=['a.invoice_title',"like","%$invoice_title%"];
  76. }
  77. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !=="" ? trim($this->post['invoice_code']):"";
  78. if($invoice_code!=""){
  79. $where[]=['a.invoice_code',"like","%$invoice_code%"];
  80. }
  81. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !=="" ? trim($this->post['invoice_mobile']):"";
  82. if($invoice_mobile !=""){
  83. $where[] =['a.invoice_code',"like","%$invoice_mobile%"];
  84. }
  85. $status = isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  86. if($status !=""){
  87. $where[] =['a.status',"=",$status];
  88. }
  89. $companyName = isset($this->post['companyName']) && $this->post['companyName'] !=="" ? trim($this->post['companyName']):"";
  90. if($companyName!=""){
  91. $where[]=['b.companyName',"like","%$companyName%"];
  92. }
  93. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  94. if($creater!=""){
  95. $where[]=['b.creater',"like","%$creater%"];
  96. }
  97. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  98. if($start!==""){
  99. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  100. }
  101. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  102. if($end!==""){
  103. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  104. }
  105. $count = Db::name('customer_title')->alias("a")
  106. ->join("business b","b.companyNo=a.companyNo","left")->where($where)->count();
  107. $total = ceil($count / $size);
  108. $page = $page >= $total ? $total : $page;
  109. $list = Db::name('customer_title')->alias("a")
  110. ->join("customer_info b","b.companyNo=a.companyNo","left")
  111. ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.companyName,b.creater")->select();
  112. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  113. }
  114. public function edit(){
  115. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  116. if($id ==""){
  117. return error_show(1002,"参数id不能为空");
  118. }
  119. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  120. if($info==""){
  121. return error_show(1002,"未找到数据");
  122. }
  123. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']):"";
  124. // if($companyNo==""){
  125. // return error_show(1002,"参数companyNo不能为空");
  126. // }
  127. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  128. if($invoice_title==""){
  129. return error_show(1002,"参数invoice_title不能为空");
  130. }
  131. // $invoice_people = isset($this->post['invoice_people']) && $this->post['invoice_people'] !== ""? trim($this->post['invoice_people']):"";
  132. // if($invoice_people==""){
  133. // return error_show(1002,"参数invoice_people不能为空");
  134. // }
  135. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !==""? trim($this->post['invoice_code']):"";
  136. if($invoice_code==""){
  137. return error_show(1002,"参数invoice_code不能为空");
  138. }
  139. $invoice_bank = isset($this->post['invoice_bank']) && $this->post['invoice_bank'] !==""? trim($this->post['invoice_bank']):"";
  140. if($invoice_bank==""){
  141. return error_show(1002,"参数invoice_bank不能为空");
  142. }
  143. $invoice_bankNo = isset($this->post['invoice_bankNo']) && $this->post['invoice_bankNo'] !==""? trim($this->post['invoice_bankNo']):"";
  144. if($invoice_bankNo==""){
  145. return error_show(1002,"参数invoice_bankNo不能为空");
  146. }
  147. $invoice_addr = isset($this->post['invoice_addr']) && $this->post['invoice_addr'] !==""? trim($this->post['invoice_addr']):"";
  148. if($invoice_addr==""){
  149. return error_show(1002,"参数invoice_addr不能为空");
  150. }
  151. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !==""? trim($this->post['invoice_mobile']):"";
  152. if($invoice_mobile==""){
  153. return error_show(1002,"参数invoice_mobile不能为空");
  154. }
  155. $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"1";
  156. $data =[
  157. "id"=>$id,
  158. "invoice_title"=>$invoice_title,
  159. // "invoice_people"=>$invoice_people,
  160. "invoice_code"=>$invoice_code,
  161. "invoice_bank"=>$invoice_bank,
  162. "invoice_bankNo"=>$invoice_bankNo,
  163. "invoice_addr"=>$invoice_addr,
  164. "invoice_mobile"=>$invoice_mobile,
  165. "status"=>$status,
  166. "is_del"=>0,
  167. "updatetime"=>date("Y-m-d H:i:s")
  168. ];
  169. $temp = Db::name('customer_title')->save($data);
  170. if($temp){
  171. return error_show(0,"更新成功");
  172. }else{
  173. return error_show(1002,"更新失败");
  174. }
  175. }
  176. public function info(){
  177. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  178. if($id ==""){
  179. return error_show(1002,"参数id不能为空");
  180. }
  181. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  182. if($info==""){
  183. return error_show(1002,"未找到数据");
  184. }
  185. $temp = Db::name("customer_info")->where(['companyNo'=>$info['companyNo'],'is_del'=>0])->find();
  186. $info['companyName']=$temp['companyName'];
  187. return app_show(0,"获取成功",$info);
  188. }
  189. public function del(){
  190. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  191. if($id ==""){
  192. return error_show(1002,"参数id不能为空");
  193. }
  194. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  195. if($info==""){
  196. return error_show(1002,"未找到数据");
  197. }
  198. $end = Db::name('customer_title')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  199. if($end){
  200. return error_show(0,"删除成功");
  201. }else{
  202. return error_show(1002,"删除失败");
  203. }
  204. }
  205. public function status(){
  206. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  207. if($id==""){
  208. return error_show(1002,"参数id不能为空");
  209. }
  210. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  211. if($info==""){
  212. return error_show(1002,"未找到数据");
  213. }
  214. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  215. if($status===""){
  216. return error_show(1002,"参数status不能为空");
  217. }
  218. if(!in_array($status,[0,1])){
  219. return error_show(1002,"参数status无效");
  220. }
  221. $info['status']=$status;
  222. $info['updatetime']=date("Y-m-d H:i:s");
  223. $msg = $status==1?"启用":"禁用";
  224. $temp = Db::name("customer_title")->save($info);
  225. return $temp ? error_show(0,"{$msg}成功"):error_show(1002,"{$msg}失败");
  226. }
  227. }