Title.php 11 KB

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