Title.php 13 KB

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