Title.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ChangeLog;
  4. use app\BaseController;
  5. use think\App;
  6. use think\facade\Db;
  7. //客户的营业执照相关信息
  8. class Title extends Base
  9. {
  10. public $post = "";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post= $this->request->post();
  15. }
  16. public function create(){
  17. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']):"";
  18. if($companyNo==""){
  19. return error_show(1002,"参数companyNo不能为空");
  20. }
  21. $companyinfo =$temp = Db::connect('mysql_sys')
  22. ->name('customer_title')
  23. ->field('id')
  24. ->where(['is_del' => 0, 'companyNo'=>$companyNo])
  25. ->findOrEmpty();
  26. if (!empty($companyinfo)) {
  27. return error_show(1002, "统一社会信用代码名称已存在");
  28. }
  29. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  30. if($invoice_title==""){
  31. return error_show(1002,"参数invoice_title不能为空");
  32. }
  33. // $invoice_people = isset($this->post['invoice_people']) && $this->post['invoice_people'] !== ""? trim($this->post['invoice_people']):"";
  34. // if($invoice_people==""){
  35. // return error_show(1002,"参数invoice_people不能为空");
  36. // }
  37. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !==""? trim($this->post['invoice_code']):"";
  38. if($invoice_code==""){
  39. return error_show(1002,"参数invoice_code不能为空");
  40. }
  41. $invoice_bank = isset($this->post['invoice_bank']) && $this->post['invoice_bank'] !==""? trim($this->post['invoice_bank']):"";
  42. if($invoice_bank==""){
  43. return error_show(1002,"参数invoice_bank不能为空");
  44. }
  45. $invoice_bankNo = isset($this->post['invoice_bankNo']) && $this->post['invoice_bankNo'] !==""? trim($this->post['invoice_bankNo']):"";
  46. if($invoice_bankNo==""){
  47. return error_show(1002,"参数invoice_bankNo不能为空");
  48. }
  49. $invoice_addr = isset($this->post['invoice_addr']) && $this->post['invoice_addr'] !==""? trim($this->post['invoice_addr']):"";
  50. if($invoice_addr==""){
  51. return error_show(1002,"参数invoice_addr不能为空");
  52. }
  53. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !==""? trim($this->post['invoice_mobile']):"";
  54. if($invoice_mobile==""){
  55. return error_show(1002,"参数invoice_mobile不能为空");
  56. }
  57. $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"1";
  58. $data =[
  59. "companyNo"=>$companyNo,
  60. "invoice_title"=>$invoice_title,
  61. // "invoice_people"=>$invoice_people,
  62. "invoice_code"=>$invoice_code,
  63. "invoice_bank"=>$invoice_bank,
  64. "invoice_bankNo"=>$invoice_bankNo,
  65. "invoice_addr"=>$invoice_addr,
  66. "invoice_mobile"=>$invoice_mobile,
  67. "status"=>$status,
  68. "is_del"=>0,
  69. "addtime"=>date("Y-m-d H:i:s"),
  70. "updatetime"=>date("Y-m-d H:i:s")
  71. ];
  72. $info = Db::connect('mysql_sys')
  73. ->name('customer_title')
  74. ->insert($data);
  75. if($info){
  76. return error_show(0,"新建成功");
  77. }else{
  78. return error_show(1002,"新建失败");
  79. }
  80. }
  81. public function list(){
  82. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  83. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  84. $where =[["a.is_del","=",0]];
  85. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  86. if($invoice_title!=""){
  87. $where[]=['a.invoice_title',"like","%$invoice_title%"];
  88. }
  89. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !=="" ? trim($this->post['invoice_code']):"";
  90. if($invoice_code!=""){
  91. $where[]=['a.invoice_code',"like","%$invoice_code%"];
  92. }
  93. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !=="" ? trim($this->post['invoice_mobile']):"";
  94. if($invoice_mobile !=""){
  95. $where[] =['a.invoice_code',"like","%$invoice_mobile%"];
  96. }
  97. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  98. if($status!==""){
  99. $where[]=['a.status',"=",$status];
  100. }
  101. $companyName = isset($this->post['companyName']) && $this->post['companyName'] !=="" ? trim($this->post['companyName']):"";
  102. if($companyName!=""){
  103. $where[]=['b.companyName',"like","%$companyName%"];
  104. }
  105. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  106. if($creater!=""){
  107. $where[]=['b.creater',"like","%$creater%"];
  108. }
  109. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  110. if($start!==""){
  111. $where[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  112. }
  113. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  114. if($end!==""){
  115. $where[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  116. }
  117. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  118. if ($company_name !== "") $where[] = ["u.uid", 'in', get_company_item_user_by_name($company_name)];
  119. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  120. if ($companyNo !== "") $where[] = ["a.companyNo", 'like', '%' . $companyNo . '%'];
  121. $count = Db::connect('mysql_sys')
  122. ->name('customer_title')
  123. ->alias("a")
  124. ->leftJoin("customer_info b","b.companyNo=a.companyNo")
  125. ->leftJoin("account_item c", "c.account_id=b.createrid")
  126. ->leftJoin("company_item d", "d.id=c.itemid")
  127. ->where($where)
  128. ->count();
  129. $total = ceil($count / $size);
  130. $page = $page >= $total ? $total : $page;
  131. $list = Db::connect('mysql_sys')
  132. ->name('customer_title')
  133. ->alias("a")
  134. ->field("a.*,b.companyName,b.creater,b.createrid,d.name company_name")
  135. ->leftJoin("customer_info b","b.companyNo=a.companyNo")
  136. ->leftJoin("account_item c", "c.account_id=b.createrid")
  137. ->leftJoin("company_item d", "d.id=c.itemid")
  138. ->where($where)
  139. ->page($page,$size)
  140. ->select()
  141. ->toArray();
  142. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  143. }
  144. public function edit(){
  145. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  146. if($id ==""){
  147. return error_show(1002,"参数id不能为空");
  148. }
  149. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  150. if($token==""){
  151. return error_show(101,'token不能为空');
  152. }
  153. $info= Db::connect('mysql_sys')
  154. ->name('customer_title')
  155. ->where(['id'=>$id,'is_del'=>0])
  156. ->find();
  157. if($info==""){
  158. return error_show(1002,"未找到数据");
  159. }
  160. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !==""? trim($this->post['companyNo']):"";
  161. // if($companyNo==""){
  162. // return error_show(1002,"参数companyNo不能为空");
  163. // }
  164. $invoice_title = isset($this->post['invoice_title']) && $this->post['invoice_title'] !=="" ? trim($this->post['invoice_title']):"";
  165. if($invoice_title==""){
  166. return error_show(1002,"参数invoice_title不能为空");
  167. }
  168. // $invoice_people = isset($this->post['invoice_people']) && $this->post['invoice_people'] !== ""? trim($this->post['invoice_people']):"";
  169. // if($invoice_people==""){
  170. // return error_show(1002,"参数invoice_people不能为空");
  171. // }
  172. $invoice_code = isset($this->post['invoice_code']) && $this->post['invoice_code'] !==""? trim($this->post['invoice_code']):"";
  173. if($invoice_code==""){
  174. return error_show(1002,"参数invoice_code不能为空");
  175. }
  176. $invoice_bank = isset($this->post['invoice_bank']) && $this->post['invoice_bank'] !==""? trim($this->post['invoice_bank']):"";
  177. if($invoice_bank==""){
  178. return error_show(1002,"参数invoice_bank不能为空");
  179. }
  180. $invoice_bankNo = isset($this->post['invoice_bankNo']) && $this->post['invoice_bankNo'] !==""? trim($this->post['invoice_bankNo']):"";
  181. if($invoice_bankNo==""){
  182. return error_show(1002,"参数invoice_bankNo不能为空");
  183. }
  184. $invoice_addr = isset($this->post['invoice_addr']) && $this->post['invoice_addr'] !==""? trim($this->post['invoice_addr']):"";
  185. if($invoice_addr==""){
  186. return error_show(1002,"参数invoice_addr不能为空");
  187. }
  188. $invoice_mobile = isset($this->post['invoice_mobile']) && $this->post['invoice_mobile'] !==""? trim($this->post['invoice_mobile']):"";
  189. if($invoice_mobile==""){
  190. return error_show(1002,"参数invoice_mobile不能为空");
  191. }
  192. $status = isset($this->post['status']) && $this->post['status'] !==""? trim($this->post['status']):"1";
  193. $data =[
  194. "id"=>$id,
  195. "invoice_title"=>$invoice_title,
  196. // "invoice_people"=>$invoice_people,
  197. "invoice_code"=>$invoice_code,
  198. "invoice_bank"=>$invoice_bank,
  199. "invoice_bankNo"=>$invoice_bankNo,
  200. "invoice_addr"=>$invoice_addr,
  201. "invoice_mobile"=>$invoice_mobile,
  202. "status"=>$status,
  203. "is_del"=>0,
  204. "updatetime"=>date("Y-m-d H:i:s")
  205. ];
  206. $temp = Db::connect('mysql_sys')
  207. ->name('customer_title')
  208. ->save($data);
  209. $titn = array_diff($data,$info);
  210. $json = json_encode($titn,JSON_UNESCAPED_UNICODE);
  211. $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
  212. if($temp){
  213. ChangeLog::logAdd(2,$info['companyNo'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  214. return error_show(0,"更新成功");
  215. }else{
  216. return error_show(1002,"更新失败");
  217. }
  218. }
  219. public function info(){
  220. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  221. if($id ==""){
  222. return error_show(1002,"参数id不能为空");
  223. }
  224. $info = Db::connect('mysql_sys')
  225. ->name('customer_title')
  226. ->alias('a')
  227. ->field('a.*,b.companyName')
  228. ->leftJoin('customer_info b','b.companyNo=a.companyNo AND b.is_del=0')
  229. ->where(['a.id'=>$id,'a.is_del'=>0])
  230. ->findOrEmpty();
  231. // $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  232. // if($info==""){
  233. // return error_show(1002,"未找到数据");
  234. // }
  235. // $temp = Db::name("customer_info")->where(['companyNo'=>$info['companyNo'],'is_del'=>0])->find();
  236. // $info['companyName']=$temp['companyName'];
  237. return app_show(0,"获取成功",$info);
  238. }
  239. public function del(){
  240. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  241. if($id ==""){
  242. return error_show(1002,"参数id不能为空");
  243. }
  244. $end = Db::connect('mysql_sys')
  245. ->name('customer_title')
  246. ->where(['id'=>$id,'is_del'=>0])
  247. ->update(['is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  248. if($end){
  249. return error_show(0,"删除成功");
  250. }else{
  251. return error_show(1002,"删除失败");
  252. }
  253. }
  254. public function status(){
  255. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
  256. if($id==""){
  257. return error_show(1002,"参数id不能为空");
  258. }
  259. // $info= Db::name('customer_title')->where(['id'=>$id,'is_del'=>0])->find();
  260. // if($info==""){
  261. // return error_show(1002,"未找到数据");
  262. // }
  263. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  264. if($status===""){
  265. return error_show(1002,"参数status不能为空");
  266. }
  267. if(!in_array($status,[0,1])){
  268. return error_show(1002,"参数status无效");
  269. }
  270. // $info['status']=$status;
  271. // $info['updatetime']=date("Y-m-d H:i:s");
  272. $msg = $status==1?"启用":"禁用";
  273. // $temp = Db::name("customer_title")->save($info);
  274. $temp = Db::connect('mysql_sys')
  275. ->name('customer_title')
  276. ->where(['id'=>$id,'is_del'=>0])
  277. ->where('status','<>',$status)
  278. ->update(['status'=>$status,'updatetime'=>date("Y-m-d H:i:s")]);
  279. return $temp ? error_show(0,"{$msg}成功"):error_show(1002,"{$msg}失败");
  280. }
  281. }