Title.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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'] !=="" ? intval($this->post['status'])
  86. :"";
  87. if($status!==""){
  88. $where[]=['a.status',"=",$status];
  89. }
  90. $companyName = isset($this->post['companyName']) && $this->post['companyName'] !=="" ? trim($this->post['companyName']):"";
  91. if($companyName!=""){
  92. $where[]=['b.companyName',"like","%$companyName%"];
  93. }
  94. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  95. if($creater!=""){
  96. $where[]=['b.creater',"like","%$creater%"];
  97. }
  98. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  99. if($start!==""){
  100. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  101. }
  102. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  103. if($end!==""){
  104. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  105. }
  106. $count = Db::name('customer_title')->alias("a")
  107. ->join("business b","b.companyNo=a.companyNo","left")->where($where)->count();
  108. $total = ceil($count / $size);
  109. $page = $page >= $total ? $total : $page;
  110. $list = Db::name('customer_title')->alias("a")
  111. ->join("customer_info b","b.companyNo=a.companyNo","left")
  112. ->where($where)->page($page,$size)->order("a.addtime desc")->field("a.*,b.companyName,b.creater")->select();
  113. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  114. }
  115. public function edit(){
  116. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  117. if($id ==""){
  118. return error_show(1002,"参数id不能为空");
  119. }
  120. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  121. if($info==""){
  122. return error_show(1002,"未找到数据");
  123. }
  124. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']):"";
  125. // if($companyNo==""){
  126. // return error_show(1002,"参数companyNo不能为空");
  127. // }
  128. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  129. if($invoice_title==""){
  130. return error_show(1002,"参数invoice_title不能为空");
  131. }
  132. // $invoice_people = isset($this->post['invoice_people']) && $this->post['invoice_people'] !== ""? trim($this->post['invoice_people']):"";
  133. // if($invoice_people==""){
  134. // return error_show(1002,"参数invoice_people不能为空");
  135. // }
  136. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !==""? trim($this->post['invoice_code']):"";
  137. if($invoice_code==""){
  138. return error_show(1002,"参数invoice_code不能为空");
  139. }
  140. $invoice_bank = isset($this->post['invoice_bank']) && $this->post['invoice_bank'] !==""? trim($this->post['invoice_bank']):"";
  141. if($invoice_bank==""){
  142. return error_show(1002,"参数invoice_bank不能为空");
  143. }
  144. $invoice_bankNo = isset($this->post['invoice_bankNo']) && $this->post['invoice_bankNo'] !==""? trim($this->post['invoice_bankNo']):"";
  145. if($invoice_bankNo==""){
  146. return error_show(1002,"参数invoice_bankNo不能为空");
  147. }
  148. $invoice_addr = isset($this->post['invoice_addr']) && $this->post['invoice_addr'] !==""? trim($this->post['invoice_addr']):"";
  149. if($invoice_addr==""){
  150. return error_show(1002,"参数invoice_addr不能为空");
  151. }
  152. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !==""? trim($this->post['invoice_mobile']):"";
  153. if($invoice_mobile==""){
  154. return error_show(1002,"参数invoice_mobile不能为空");
  155. }
  156. $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"1";
  157. $data =[
  158. "id"=>$id,
  159. "invoice_title"=>$invoice_title,
  160. // "invoice_people"=>$invoice_people,
  161. "invoice_code"=>$invoice_code,
  162. "invoice_bank"=>$invoice_bank,
  163. "invoice_bankNo"=>$invoice_bankNo,
  164. "invoice_addr"=>$invoice_addr,
  165. "invoice_mobile"=>$invoice_mobile,
  166. "status"=>$status,
  167. "is_del"=>0,
  168. "updatetime"=>date("Y-m-d H:i:s")
  169. ];
  170. $temp = Db::name('customer_title')->save($data);
  171. if($temp){
  172. return error_show(0,"更新成功");
  173. }else{
  174. return error_show(1002,"更新失败");
  175. }
  176. }
  177. public function info(){
  178. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  179. if($id ==""){
  180. return error_show(1002,"参数id不能为空");
  181. }
  182. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  183. if($info==""){
  184. return error_show(1002,"未找到数据");
  185. }
  186. $temp = Db::name("customer_info")->where(['companyNo'=>$info['companyNo'],'is_del'=>0])->find();
  187. $info['companyName']=$temp['companyName'];
  188. return app_show(0,"获取成功",$info);
  189. }
  190. public function del(){
  191. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  192. if($id ==""){
  193. return error_show(1002,"参数id不能为空");
  194. }
  195. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  196. if($info==""){
  197. return error_show(1002,"未找到数据");
  198. }
  199. $end = Db::name('customer_title')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  200. if($end){
  201. return error_show(0,"删除成功");
  202. }else{
  203. return error_show(1002,"删除失败");
  204. }
  205. }
  206. public function status(){
  207. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  208. if($id==""){
  209. return error_show(1002,"参数id不能为空");
  210. }
  211. $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  212. if($info==""){
  213. return error_show(1002,"未找到数据");
  214. }
  215. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  216. if($status===""){
  217. return error_show(1002,"参数status不能为空");
  218. }
  219. if(!in_array($status,[0,1])){
  220. return error_show(1002,"参数status无效");
  221. }
  222. $info['status']=$status;
  223. $info['updatetime']=date("Y-m-d H:i:s");
  224. $msg = $status==1?"启用":"禁用";
  225. $temp = Db::name("customer_title")->save($info);
  226. return $temp ? error_show(0,"{$msg}成功"):error_show(1002,"{$msg}失败");
  227. }
  228. }