Customer.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 Customer extends Base
  9. {
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. }
  14. /*列表*/
  15. public function list()
  16. {
  17. $param = $this->request->filter('trim')->post();
  18. $userCommon = \app\admin\common\User::getIns();
  19. $rs = $userCommon->handle('customer_org_list', $param);
  20. return json_show($rs['code'], $rs['message'], $rs['data']);
  21. // $page= isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']):"1";
  22. // $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) :"10";
  23. // $pid = isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
  24. // $where =[];
  25. // $where []= ['ci.is_del',"=",0];
  26. // $condition = [['co.is_del',"=",0]];
  27. // if($pid!==""){
  28. // $condition[]=["co.pid","=",$pid];
  29. // }
  30. // $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  31. // if($companyNo !==""){
  32. // $where[] = ['ci.companyNo',"like","%$companyNo%"];
  33. // }
  34. // $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  35. // if($creater !==""){
  36. // $where[] = ['ci.creater',"like","%$creater%"];
  37. // }
  38. // $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
  39. // if($name!=""){
  40. // $condition[]=["co.name","like","%{$this->post['name']}%"];
  41. // }
  42. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  43. // if ($start != "") {
  44. // $where[] = ["ci.addtime", '>=', $start];
  45. // }
  46. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  47. // if ($end != "") {
  48. // $where[] = ["ci.addtime", '<=', $end];
  49. // }
  50. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  51. // if($status!==""){
  52. // $where[] = ['ci.status',"=",$status];
  53. // }
  54. //// $count = Db::name('customer_org1')->where($condition)->count();
  55. //// $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  56. // $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  57. // if($creater !==""){
  58. // $condition[] = ['co.creater',"like","%$creater%"];
  59. // }
  60. // $name= isset($this->post['name'])&&$this->post['name']!=="" ? trim($this->post['name']):"";
  61. // if($name!=""){
  62. // $condition[]=["co.name","like","%{$this->post['name']}%"];
  63. // }
  64. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  65. // if ($start != "") {
  66. // $condition[] = ["co.addtime", '>=', $start];
  67. // }
  68. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  69. // if ($end != "") {
  70. // $condition[] = ["co.addtime", '<=', $end];
  71. // }
  72. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  73. // if($status!==""){
  74. // $condition[] = ['co.status',"=",$status];
  75. // }
  76. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  77. // if ($company_name !== "") {
  78. // $company_ids = get_company_item_user_by_name($company_name);
  79. // $where[] = ["u.uid", 'in', $company_ids];
  80. // $condition[] = ['u.uid',"in",$company_ids];
  81. // }
  82. //
  83. // $pidlist = Db::name("customer_org1")
  84. // ->alias('co')
  85. // ->leftJoin("depart_user u", "u.uid=co.createrid AND u.is_del=0")
  86. // ->where($condition)
  87. // ->order("co.addtime desc")->column("co.pid");
  88. // if(!empty($pidlist)){
  89. // $where[]=[["ci.itemid","in",$pidlist]];
  90. //
  91. // }else{
  92. // if($pid===""){
  93. // $where[]=['ci.itemid','=',0];
  94. // }else{
  95. // $where[]=['ci.itemid','=',$pid];
  96. // }
  97. // }
  98. // $list = Db::name('customer_org1')
  99. // ->alias('co')
  100. // ->where($condition)
  101. // ->order("co.addtime",'desc')
  102. // ->column("co.id,co.pid,co.name,co.level,co.depart_link,co.creater,co.createrid,co.addtime,co.status");
  103. //
  104. // $all_createrid = array_column($list,'createrid');
  105. // $all_item = get_company_name_by_uid($all_createrid);
  106. //
  107. // $var=[];
  108. // foreach ($list as $item) {
  109. // $iten=[];
  110. // $iten['name']=$item['name'];
  111. //// $iten['code']="";
  112. // $iten['id']=$item['id'];
  113. // $iten['creater']=$item['creater'];
  114. // $iten['status']=$item['status'];
  115. // $iten['addtime']=$item['addtime'];
  116. // $iten['kh']=0;//组织架构
  117. // $iten['company_name'] = $all_item[$item['createrid']]??'';
  118. //
  119. // $var[]=$iten;
  120. // }
  121. // $itm = Db::connect('mysql_sys')
  122. // ->name('customer_info')
  123. // ->alias('ci')
  124. //// ->leftJoin("depart_user u", "u.nickname=ci.creater AND u.is_del=0")
  125. // ->where($where)
  126. // ->order("ci.addtime desc")
  127. // ->select()
  128. // ->toArray();
  129. //
  130. // //同理,这个表里只存了创建人名称,没有id
  131. //
  132. // foreach ($itm as $vat){
  133. // $inm=[];
  134. // $inm['name']=$vat['companyName'];
  135. // $inm['id']=$vat['id'];
  136. // $inm['code']=$vat['companyNo'];
  137. //// $inm['companyName']=$vat['companyName'];
  138. //// $inm['invoice_bank']=$vat['invoice_bank'];
  139. //// $inm['invoice_bankNo']=$vat['invoice_bankNo'];
  140. //// $inm['invoice_code']=$vat['invoice_code'];
  141. //// $inm['invoice_people']=$vat['invoice_people'];
  142. //// $inm['invoice_mobile']=$vat['invoice_mobile'];
  143. //// $inm['invoice_addr']=$vat['invoice_addr'];
  144. //// $inm['parent']=$vat['parent'];
  145. //// $inm['branch']=$vat['branch'];
  146. //// $inm['middle']=$vat['middle'];
  147. //// $inm['country']=$vat['country'];
  148. // $inm['status']=$vat['status'];
  149. // $inm['creater']=$vat['creater'];
  150. // $inm['addtime']=$vat['addtime'];
  151. // $inm['kh']=1;//客户
  152. // $inm['company_name'] = '待处理';
  153. // $var[]=$inm;
  154. // }
  155. // return app_show(0,"获取成功",$var);
  156. }
  157. /*新建*/
  158. public function create()
  159. {
  160. $param = $this->request->filter('trim')->post();
  161. $param['uid'] = $this->uid;
  162. $param['uname'] = $this->uname;
  163. $userCommon = \app\admin\common\User::getIns();
  164. $rs = $userCommon->handle('customer_org_create', $param);
  165. return json_show($rs['code'], $rs['message'], $rs['data']);
  166. // $name = isset($this->post['name']) && $this->post['name'] !== "" ? trim($this->post['name']) : "";
  167. // if ($name == "") {
  168. // return error_show(1003, "公司名称不能为空");
  169. // }
  170. // $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? trim($this->post['weight']) : "0";
  171. // $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? trim($this->post['pid']) : "0";
  172. //// if ($pid === "") {
  173. //// return error_show(1002, "父级id不能为空");
  174. //// }
  175. // if($pid!=0){
  176. // $spid = Db::name('customer_org1')->where(['id'=>$pid, 'is_del'=>0])->find();
  177. // //var_dump( Db::name('customer_org1')->getLastSql());
  178. // if(empty($spid)){
  179. // return error_show(1004,"父级不能为空");
  180. // }
  181. // }
  182. // $rename = Db::name('customer_org1')->where(['is_del' => 0, 'name' => $name,'pid'=>$pid])->find();
  183. // if (!empty($rename)) {
  184. // return error_show(1002, "组织名称已存在");
  185. // }
  186. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  187. // if($token==''){
  188. // return error_show(105,"参数token不能为空");
  189. // }
  190. // $user =GetUserInfo($token);
  191. // if(empty($user)||$user['code']!=0){
  192. // return error_show(1002,"创建人数据不存在");
  193. // }
  194. // $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  195. // $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  196. // $level = isset($this->post['level']) && $this->post['level'] !== "" ? trim($this->post['level']) : "1";
  197. // Db::startTrans();
  198. // try {
  199. // $tada = [
  200. // "name" => $name,
  201. // "weight" => $weight,
  202. // "pid" => $pid,
  203. // "level" => $level,
  204. // "updatetime" => date("Y-m-d H:i:s"),
  205. // "addtime" => date("Y-m-d H:i:s"),
  206. // "depart_link" => "",
  207. // "is_del" => 0,
  208. // "pname"=>isset($spid['name']) ? $spid['name']:"",
  209. // "creater"=>$creater,
  210. // "createrid"=>$createrid
  211. // ];
  212. // $t = Db::name('customer_org1')->insert($tada, true);
  213. // //var_dump(Db::name('customer_org1')->getLastSql());
  214. // if ($t > 0) {
  215. // if(isset($spid)){
  216. // // var_dump($spid);
  217. // $depart_link = $spid['depart_link']."{$t}-";
  218. // }else{
  219. // $depart_link="{$t}-";
  220. // }
  221. // $level = explode('-', $depart_link);
  222. // // var_dump($level);
  223. // $level = array_filter($level);
  224. // $level = count($level);
  225. // $k = ['depart_link' => $depart_link, 'level' => $level];
  226. // $u = Db::name('customer_org1')->where(['id' => $t])->save($k);
  227. // // var_dump( Db::name('customer_org1')->getLastSql());
  228. // if ($u) {
  229. // Db::commit();
  230. // return error_show(0, "新建成功");
  231. // }
  232. // }
  233. // Db::rollback();
  234. // } catch (\Exception $e) {
  235. // Db::rollback();
  236. // return error_show(1003, $e->getMessage());
  237. // }
  238. }
  239. /*更新*/
  240. public function update()
  241. {
  242. $param = $this->request->filter('trim')->post();
  243. $param['uid'] = $this->uid;
  244. $param['uname'] = $this->uname;
  245. $userCommon = \app\admin\common\User::getIns();
  246. $rs = $userCommon->handle('customer_org_update', $param);
  247. return json_show($rs['code'], $rs['message'], $rs['data']);
  248. // $id = isset($this->post['id'])?intval($this->post['id']):"";
  249. // if($id===""){
  250. // return error_show(1004,"参数id不能为空");
  251. // }
  252. // $sid = Db::name('customer_org1')->where("id","=","$id")->find();
  253. // // var_dump(Db::name('customer_org1')->getLastSql());
  254. // if($sid==false){
  255. // return error_show(1004,"公司不存在");
  256. // }
  257. // if($sid['status']==1){
  258. // return error_show(1002,"状态是启用状态,无法编辑");
  259. // }
  260. // $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']):"";
  261. // if($pid===""){
  262. // return error_show(1004,"父级id不能为空");
  263. // }
  264. //
  265. // if($pid!=0){
  266. // $fpid = Db::name('customer_org1')->where(['id'=>"$pid",'is_del'=>0])->find();
  267. // if(empty($fpid)){
  268. // return error_show(1004,"父级不能为空");
  269. // }
  270. // }
  271. //
  272. // $weight = isset($this->post['weight']) && $this->post['weight'] !==""? intval($this->post['weight']):"0";
  273. //
  274. //// $level = isset($this->post['level']) && $this->post['level'] !==""? intval($this->post['level']):"";
  275. // $name = isset($this->post['name'])? trim($this->post['name']):"";
  276. // if($name==""){
  277. // return error_show(1004,"公司名称不能为空");
  278. // }
  279. // $repeat_name = Db::name('customer_org1')->where(["is_del"=>0,"name"=>$name,'pid'=>$pid])->where("id","<>","$id")->find();
  280. // // echo Db::name('customer_org1')->getLastSql();
  281. // if(!empty($repeat_name)){
  282. // return error_show(1004,"部门名称已存在");
  283. // }
  284. // if(isset($fpid)){
  285. // $depart_link=$fpid['depart_link']."{$id}-";
  286. // }else{
  287. // $depart_link= "{$id}-";
  288. // }
  289. // $level =explode('-',$depart_link);
  290. // $level = array_filter($level);
  291. // $level= count($level);
  292. // $vir=[
  293. // "id"=>$id,
  294. // "name"=>$name,"pid"=>$pid,
  295. // "weight"=>$weight,"depart_link"=>$depart_link,
  296. // "level"=>$level,"is_del"=>0,"addtime"=>date("Y-m-d H:i:s"),
  297. // "updatetime"=>date("Y-m-d H:i:s"),
  298. // ];
  299. // $org = Db::name('customer_org1')->save($vir);
  300. // if($org){
  301. // return error_show(0,"更新成功");
  302. // }else{
  303. // return error_show(1004,"更新失败");
  304. // }
  305. }
  306. /*查询*/
  307. public function info()
  308. {
  309. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  310. if ($id == "") {
  311. return error_show(1004, "公司客户不存在");
  312. }
  313. $userCommon = \app\admin\common\User::getIns();
  314. $rs = $userCommon->handle('customer_org_info', ['id' => $id]);
  315. return json_show($rs['code'], $rs['message'], $rs['data']);
  316. // $tod=Db::name('customer_org1')->where(['id'=>$id,'is_del'=>0])->find();
  317. // //var_dump(Db::name('customer_org1')->getLastSql());
  318. // return app_show(0,"获取成功",$tod);
  319. }
  320. /*删除*/
  321. public function delete()
  322. {
  323. $id = $this->request->post('id/d', 0, 'trim');
  324. if ($id === 0) return json_show(1004, 'id不能为空');
  325. $userCommon = \app\admin\common\User::getIns();
  326. $rs = $userCommon->handle('customer_org_delete', ['id' => $id]);
  327. return json_show($rs['code'], $rs['message'], $rs['data']);
  328. // $id=isset($this->post['id']) ?intval($this->post['id']):"";
  329. // $custy = Db::name('customer_org1')->where(["is_del"=>0,'id'=>$id])->find();
  330. // if($custy==false){
  331. // return error_show(1004,"公司不存在");
  332. // }
  333. // //$var= Db::name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->find();
  334. // $db= Db::name('customer_org1')->where(['pid'=>$custy['id'],'is_del'=>0])->count();
  335. // if($db>0){
  336. // return error_show(1004,"下一级还有组织,不允许删除");
  337. // }
  338. // $var= Db::connect('mysql_sys')
  339. // ->name('customer_info')->where(['itemid'=>$id,'is_del'=>0])->count();
  340. // if($var>0){
  341. // return error_show(1004,"下一级还有分公司,不允许删除");
  342. // }
  343. // $custy['is_del']=1;
  344. // $custy['updatetime']=date("Y-m-d H:i:s");
  345. // $compy = Db::name('customer_org1')->save($custy);
  346. // return $compy ? error_show(0,"删除成功"):error_show(1004,"删除失败");
  347. }
  348. public function status()
  349. {
  350. $param = $this->request->filter('trim')->post();
  351. $userCommon = \app\admin\common\User::getIns();
  352. $rs = $userCommon->handle('customer_org_status', $param);
  353. return json_show($rs['code'], $rs['message'], $rs['data']);
  354. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  355. // if($id==""){
  356. // return error_show(1002,"参数id不能为空");
  357. // }
  358. // $info = Db::name("customer_org1")->where([["id","=",$id]])->find();
  359. // if(!$info){
  360. // return error_show(1002,"未找到对应数据");
  361. // }
  362. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  363. // if($status===""){
  364. // return error_show(1002,"参数status不能为空");
  365. // }
  366. // if(!in_array($status,[0,1])){
  367. // return error_show(1002,"参数status无效");
  368. // }
  369. // $info['status']=$status;
  370. // $info['updatetime']=date("Y-m-d H:i:s");
  371. // $msg = $status==1?"启用":"禁用";
  372. // $update = Db::name("customer_org1")->save($info);
  373. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  374. }
  375. }