Customar.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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 Customar 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. {
  18. $param = $this->request->filter('trim')->post();
  19. $param['uid']= $this->uid;
  20. $param['uname']= $this->uname;
  21. $userCommon = \app\admin\common\User::getIns();
  22. $rs = $userCommon->handle('cCreate',$param);
  23. return json_show($rs['code'],$rs['message'],$rs['data']);
  24. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  25. // if ($token == '') {
  26. // return error_show(1005, "参数token不能为空");
  27. // }
  28. // $companyNo = makeNo("KH");
  29. // $companyName = isset($this->post['companyName']) && $this->post['companyName'] !== "" ? $this->post['companyName'] : "";
  30. // if ($companyName == "") {
  31. // return error_show(1002, "参数companyName不能为空");
  32. // }
  33. // $parent = isset($this->post['parent']) && $this->post['parent'] !== "" ? intval($this->post['parent'] ) : "";
  34. // $rename = Db::name('customer_org1')->where(['is_del' =>0,'id'=>$parent])->find();
  35. // $item = Db::name('customer_info')->where(['itemid'=>$rename['id'],'companyName'=>$companyName,'is_del'=>0])->find();
  36. // if ($item!=false) {
  37. // return error_show(1002, "公司名称已存在");
  38. // }
  39. // if ($parent === "") {
  40. // return error_show(1002, "参数parent不能为空");
  41. // }
  42. //$itemid = isset($this->post['itemid']) && $this->post['itemid'] !== "" ? intval($this->post['itemid'] ) : "";
  43. // $customer_member = isset($this->post['customer_member']) && $this->post['customer_member'] !== "" ? $this->post['customer_member'] : "";
  44. // if ($customer_member == "") {
  45. // return error_show(1002, "参数customer_member不能为空");
  46. // }
  47. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  48. // if($status==""){
  49. // return error_show(1002,"参数status不能为空");
  50. // }
  51. // $user = GetUserInfo($token);
  52. // if (empty($user) || $user['code'] != 0) {
  53. // return error_show(102, "创建人数据不存在");
  54. // }
  55. // $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  56. // $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  57. // Db::startTrans();
  58. // try {
  59. // $data = [
  60. // "companyNo" => $companyNo,
  61. // "companyName" => $companyName,
  62. // "parent" => $parent,
  63. // "itemid" => $parent,
  64. // "area" => "",
  65. // "comdepart" => "",
  66. // "commobile" => "",
  67. // "comtel" => "",
  68. // "contactor" => "",
  69. // "depart" => "",
  70. // "mobile" => "",
  71. // "invoice_title" => "",
  72. // "invoice_people" => "",
  73. // "invoice_addr" => "",
  74. // "invoice_mobile" => "",
  75. // "invoice_code" => "",
  76. // "invoice_bank" => "",
  77. // "invoice_bankNo" => "",
  78. // "companyCode" => "",
  79. // "status" => 0,
  80. // "sales_name" => "",
  81. // "sales_depart" => "",
  82. // "branch" => "",
  83. // "middle" => "",
  84. // "country" => "",
  85. // "is_del" => 0,
  86. // "creater" => $creater,
  87. // "modifier" => "",
  88. // "addtime" => date("Y-m-d H:i:s"),
  89. // "updatetime" => date("Y-m-d H:i:s"),
  90. // ];
  91. // $datainfo = Db::name('customer_info')->insert($data);
  92. // if ($datainfo) {
  93. //
  94. //// $var = [];
  95. //// //var_dump($customer_member);
  96. // foreach ($customer_member as $value) {
  97. //// if($value['ownerid']!==""){
  98. //// $to = GetInfoById($token, ['id' => $value['ownerid']]);
  99. //// if (empty($to) || $to['code'] != 0) {
  100. //// return app_show(1002, "数据拥有者信息不存在");
  101. //// }
  102. //// }
  103. // $item = [];
  104. //// $info = $to['data'];
  105. //// $item['owner'] = isset($info['nickname']) ? $info['nickname'] : "";
  106. // // $item['ownerid'] = $info['id'];
  107. // $item['commobile'] = isset($value['commobile']) ? $value['commobile'] : "";;
  108. // $item['comtel'] = "";
  109. // $item['contactor'] = isset($value['contactor']) ? $value['contactor'] : "";
  110. // $item['position'] = isset($value['position']) ? $value['position'] : "";
  111. // $item['wxaccount'] = isset($value['wxaccount']) ? $value['wxaccount'] : "";
  112. // $item['qqaccount'] = isset($value['qqaccount']) ? $value['qqaccount'] : "";
  113. // $item['email'] = isset($value['email']) ? $value['email'] : "";
  114. // $item['comdepart'] = isset($value['comdepart']) ? $value['comdepart'] : "";
  115. // //$item['is_private'] = isset($value['is_private']) ? $value['is_private'] : "";
  116. // $item['status'] = $value['status'];
  117. // $item['createrid'] = $createrid;
  118. // $item['creater'] = $creater;
  119. // $item['companyNo'] = $companyNo;
  120. // $item['is_del'] = 0;
  121. // $item['addtime'] = date("Y-m-d H:i:s");
  122. // $item['updatetime'] = date("Y-m-d H:i:s");
  123. // $var[] = $item;
  124. // }
  125. // $vp = Db::name('customer_member')->insertAll($var);
  126. // if ($vp == "") {
  127. // Db::rollback();
  128. // return error_show(1002, "新建失败");
  129. // }
  130. //
  131. // Db::commit();
  132. // return error_show(0, "新建成功");
  133. // } else {
  134. // Db::rollback();
  135. // return error_show(1002, "新建失败");
  136. // }
  137. // } catch (\Exception $e) {
  138. // Db::rollback();
  139. // return error_show(1005, $e->getMessage());
  140. // }
  141. }
  142. public function list()
  143. {
  144. $param = $this->request->filter('trim')->post();
  145. $userCommon = \app\admin\common\User::getIns();
  146. $rs = $userCommon->handle('cList',$param);
  147. return json_show($rs['code'],$rs['message'],$rs['data']);
  148. // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  149. // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  150. // $where = [["a.is_del", "=", 0]];
  151. // $companyName = isset($this->post['companyName']) && $this->post['companyName'] !== "" ? trim($this->post['companyName']) : "";
  152. // if ($companyName != "") {
  153. // $where[] = ['b.companyName', "like", "%$companyName%"];
  154. // }
  155. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  156. // :"";
  157. // if($status!==""){
  158. // $where[]=['status',"=",$status];
  159. // }
  160. // $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? intval($this->post['creater']) : "";
  161. // if ($creater != "") {
  162. // $where[] = ['a.creater', "like", "%$creater%"];
  163. // }
  164. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  165. // if ($start !== "") {
  166. // $where[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  167. // }
  168. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  169. // if ($end !== "") {
  170. // $where[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  171. // }
  172. // $count = Db::name('customer_member')->alias('a')->join('customer_info b', "b.companyNo=a.companyNo", "left")
  173. // ->where($where)->count();
  174. // $total = ceil($count / $size);
  175. // $page = $page >= $total ? $total : $page;
  176. // $list = Db::name('customer_member')->alias('a')->join('customer_info b', "b.companyNo=a.companyNo", "left")
  177. // ->where($where)->page($page, $size)->order("addtime desc")->field("a.*,b.companyName,b.parent")->select();
  178. // return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  179. }
  180. public function edit()
  181. {
  182. $param = $this->request->filter('trim')->post();
  183. $param['uid']= $this->uid;
  184. $param['uname']= $this->uname;
  185. $userCommon = \app\admin\common\User::getIns();
  186. $rs = $userCommon->handle('cEdit',$param);
  187. return json_show($rs['code'],$rs['message'],$rs['data']);
  188. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  189. // if ($token == '') {
  190. // return error_show(1005, "参数token不能为空");
  191. // }
  192. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  193. // if ($id == "") {
  194. // return error_show(1002, "参数id不能为空");
  195. // }
  196. // $idinfo = Db::name('customer_info')->where(['id' => $id, 'is_del' => 0])->find();
  197. // if (empty($idinfo)) {
  198. // return error_show(1004, "未找到数据");
  199. // }
  200. // if($idinfo['status']==1){
  201. // return error_show(1002,"状态是启用状态,无法编辑");
  202. // }
  203. //// $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? $this->post['companyNo'] : "";
  204. //// if ($companyNo == "") {
  205. //// return error_show(1002, "参数companyNo不能为空");
  206. //// }
  207. //// $company = Db::name('customer_info')->where(['companyNo'=>$companyNo,'is_del'=>0])->find();
  208. //// if(empty($company)){
  209. //// return error_show(1004,"未找到数据");
  210. //// }
  211. // $companyName = isset($this->post['companyName']) && $this->post['companyName'] !== "" ? $this->post['companyName'] : "";
  212. // if ($companyName == "") {
  213. // return error_show(1002, "参数companyName不能为空");
  214. // }
  215. // $parent = isset($this->post['parent']) && $this->post['parent'] !== "" ? $this->post['parent'] : "";
  216. // if ($parent == "") {
  217. // return error_show(1002, "参数parent不能为空");
  218. // }
  219. // $rename = Db::name('customer_org1')->where(['is_del' =>0,'id'=>$parent])->find();
  220. // $item = Db::name('customer_info')->where(['itemid'=>$rename['id'],'companyName'=>$companyName,'is_del'=>0])->where([['id','<>',$id]])->find();
  221. // if ($item!=false) {
  222. // return error_show(1002, "公司名称已存在");
  223. // }
  224. // $customer_member = isset($this->post['customer_member']) && $this->post['customer_member'] !== "" ? $this->post['customer_member'] : "";
  225. // if ($customer_member == "") {
  226. // return error_show(1002, "参数customer_member不能为空");
  227. // }
  228. // $user = GetUserInfo($token);
  229. // if (empty($user) || $user['code'] != 0) {
  230. // return error_show(102, "创建人数据不存在");
  231. // }
  232. // $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  233. // $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  234. // Db::startTrans();
  235. // try {
  236. // $data = [
  237. // "id" => $id,
  238. // "companyName" => $companyName,
  239. // //"companyNo" => $companyNo,
  240. // "parent" => $parent,
  241. // "updatetime" => date("Y-m-d H:i:s"),
  242. // ];
  243. // $datainfo = Db::name('customer_info')->save($data);
  244. // // var_dump(Db::name('customer_info')->getLastSql());
  245. // $stn = array_diff($data,$idinfo);
  246. // $json = json_encode($stn,JSON_UNESCAPED_UNICODE);
  247. // $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
  248. // if ($datainfo) {
  249. // ChangeLog::logAdd("2",$idinfo['companyNo'],$jsp,$json,$this->post['token'],$this->post);
  250. // // $var=[];
  251. //// var_dump($customer_member);
  252. // foreach ($customer_member as $value) {
  253. //// $to = GetInfoById($token, ['id' => $value['ownerid']]);
  254. ////
  255. //// if (empty($to) || $to['code'] != 0) {
  256. //// return app_show(1002, "数据拥有者信息不存在");
  257. //// }
  258. // $item = [];
  259. //// $info = $to['data'];
  260. //// $item['owner'] = $info['nickname'];
  261. //// $item['ownerid'] = $info['id'];
  262. // $item['commobile'] =isset($value['commobile']) ? $value['commobile'] : "";
  263. // $item['comtel'] = "";
  264. // // $item['id'] =isset($value['id']) ? $value['id'] : "";
  265. // isset($value['id'])&&$value['id']!=="" ? $item['id'] = $value['id']:'';
  266. // $item['contactor'] = isset($value['contactor']) ? $value['contactor'] : "";
  267. // $item['position'] = isset($value['position']) ? $value['position'] : "";
  268. // $item['wxaccount'] = isset($value['wxaccount']) ? $value['wxaccount'] : "";
  269. // $item['qqaccount'] = isset($value['qqaccount']) ? $value['qqaccount'] : "";
  270. // $item['email'] = isset($value['email']) ? $value['email'] : "";
  271. // $item['comdepart'] = isset($value['comdepart']) ? $value['comdepart'] : "";
  272. // // $item['is_private'] = isset($value['is_private']) ? $value['is_private'] : "";
  273. // $item['status'] = $value['status'];
  274. // $item['createrid'] = $createrid;
  275. // $item['creater'] = $creater;
  276. // $item['companyNo'] = isset( $idinfo['companyNo']) ? $idinfo['companyNo'] : "";
  277. // $item['is_del'] = 0;
  278. // $item['addtime']=date("Y-m-d H:i:s");
  279. // $item['updatetime'] = date("Y-m-d H:i:s");
  280. // // $var[]=$item;
  281. //
  282. // $vp = Db::name('customer_member')->save($item);
  283. //
  284. //// var_dump(Db::name('customer_member')->getLastSql());
  285. //// $var = array_diff($customer_member,$item);
  286. //// $jsn = json_encode($var);
  287. // if ($vp == false) {
  288. //// ChangeLog::logAdd("2",$item['companyNo'],$item,$jsn,$this->post['token'],$this->post);
  289. // Db::rollback();
  290. // return error_show(1003, "更新失败");
  291. // }
  292. // }
  293. // Db::commit();
  294. // return error_show(0, "更新成功");
  295. // } else {
  296. // Db::rollback();
  297. // return error_show(1002, "更新失败");
  298. // }
  299. // } catch (\Exception $e) {
  300. // Db::rollback();
  301. // return error_show(1005, $e->getMessage());
  302. // }
  303. }
  304. public function info()
  305. {
  306. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  307. if ($companyNo == "") return error_show(1002, "参数companyNo不能为空");
  308. $userCommon = \app\admin\common\User::getIns();
  309. $rs = $userCommon->handle('cInfo',['companyNo'=>$companyNo]);
  310. return json_show($rs['code'],$rs['message'],$rs['data']);
  311. //>field("companyNo,companyName,itemid as parent,id")-
  312. // $idinfo = Db::name('customer_info')->where(['companyNo' => $companyNo, 'is_del' => 0])->find();
  313. // if ($idinfo == "") {
  314. // return error_show(1002, "未找到数据");
  315. // }
  316. // $info = Db::name("customer_member")->where(['companyNo' => $idinfo['companyNo'], "is_del" => 0])->select();
  317. // if ($info == "") {
  318. // return error_show(1002, "未找到customer_member数据");
  319. // }
  320. // $in = Db::name("customer_attr")->where(['id' => $idinfo['parent'], "is_del" => 0])->find();
  321. // if ($in == "") {
  322. // return error_show(1002, "未找到customer_attr数据");
  323. // }
  324. // $idinfo['attr_name'] = $in['name'];
  325. // $idinfo['member'] = $info;
  326. // if ($idinfo == "") {
  327. // return error_show(1002, "未找到数据");
  328. // }
  329. // return app_show(0, "获取成功", $idinfo);
  330. }
  331. public function del(){
  332. $param = $this->request->only(['id' => 0], 'post', 'trim');
  333. $userCommon = \app\admin\common\User::getIns();
  334. $rs = $userCommon->handle('delete', [
  335. 'ids' => [$param['id']],
  336. 'type' => 2,
  337. 'updater' => $this->uname,
  338. 'updaterid' => $this->uid,
  339. ]);
  340. return json_show($rs['code'], $rs['message'], $rs['data']);
  341. // $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  342. // if($id===""){
  343. // return error_show(1004,"参数id不能为空");
  344. // }
  345. // $str= Db::name('customer_info')->where(['id'=>$id,'is_del'=>0])->find();
  346. // if(empty($str)){
  347. // return error_show(1002,"未找到数据");
  348. // }
  349. // if($str['status']==1){
  350. // return error_show(1005,"启用状态,不允许删除");
  351. // }
  352. // $end = Db::name('customer_info')->update(['id'=>$id,'is_del'=>1]);
  353. // if($end){
  354. // return error_show(0,"删除成功");
  355. // }else{
  356. // return error_show(1002,"删除失败");
  357. // }
  358. }
  359. public function status(){
  360. // $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  361. // if($id==""){
  362. // return error_show(1002,"参数id不能为空");
  363. // }
  364. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  365. $param = array_merge($param, [
  366. 'type' => 2,
  367. 'updater' => $this->uname,
  368. 'updaterid' => $this->uid,
  369. ]);
  370. $userCommon = \app\admin\common\User::getIns();
  371. $rs = $userCommon->handle('status', $param);
  372. return json_show($rs['code'], $rs['message'], $rs['data']);
  373. // $info = Db::name("customer_info")->where([["id","=",$id],["is_del","=",0]])->find();
  374. // if(!$info){
  375. // return error_show(1002,"未找到对应数据");
  376. // }
  377. // $status = isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
  378. // if($status===""){
  379. // return error_show(1002,"参数status不能为空");
  380. // }
  381. // if(!in_array($status,[0,1])){
  382. // return error_show(1002,"参数status无效");
  383. // }
  384. // $info['status']=$status;
  385. // $msg = $status==1?"启用":"禁用";
  386. // $update = Db::name("customer_info")->save($info);
  387. // return $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
  388. }
  389. }