Info.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <?php
  2. namespace Clue\lib;
  3. use Dever;
  4. Class Info
  5. {
  6. #更新次数
  7. public function getNum($id)
  8. {
  9. $html = array();
  10. $info = Dever::db('clue/info')->find($id);
  11. if ($info['gdate']) {
  12. $info['gdate'] = '<br/>'.date('Y.m.d H:i',$info['gdate']);
  13. } else {
  14. $info['gdate'] = '';
  15. }
  16. if ($info['area']) {
  17. $area = Dever::load("area/api.string", $info['area']);
  18. if (strpos($area,',')!=false) {
  19. $area = str_replace(',', '/', $area);
  20. }
  21. }
  22. if ($info['follow'] ) {
  23. $branch = explode(',',$info['follow']);
  24. // print_R($branch);die;
  25. $html['people'] = $this->group_admin($info['company_id'],$branch[0],$branch[1]);
  26. }
  27. $html['area'] = $area;
  28. $html['time'] = date('Y.m.d H:i',$info['cdate']).$info['gdate'];
  29. $html['user'] = $info['name'].'<br/>'.$info['mobile'];
  30. $data= Dever::db('clue/follow')->getCount(array('info_id'=>$id));
  31. $follow = Dever::db('clue/follow')->find(array('info_id'=>$id));
  32. if ($follow){
  33. if ($follow['xdate']) {
  34. $html['xdate'] = date('Y.m.d H:i',$follow['xdate']);
  35. }
  36. }
  37. if ($info['num'] && $info['num'] > 0) {
  38. $html['num'] = $info['num'];
  39. } else {
  40. $html['num'] = $data;
  41. }
  42. return $html;
  43. }
  44. public function insertInfo($id,$name,$data)
  45. {
  46. $mobile = Dever::param('mobile',$data);
  47. $info = Dever::db('clue/info')->find(array('mobile'=>$mobile));
  48. if ($info){
  49. Dever::alert('手机号已存在,不能重复提交');
  50. }
  51. }
  52. #更新线索表
  53. public function updateInfo($id,$name,$data)
  54. {
  55. Dever::config('base')->hook = true;
  56. $status_id = Dever::param('status_id',$data);
  57. $follow = Dever::param('follow',$data);
  58. $where['wechat'] = Dever::param('wechat',$data);
  59. $where['name'] = Dever::param('name',$data);
  60. $where['status_id'] = Dever::param('status_id',$data);
  61. $where['userset_id'] = Dever::param('userset_id',$data);
  62. $info = Dever::db('clue/info')->find($id);
  63. $where['where_id'] = $id;
  64. if (!$info['day'] || $info['day'] <=0) {
  65. $where['day'] = time();
  66. }
  67. if ($where['status_id'] == 1) {
  68. $where['type'] = 1;
  69. } elseif ($where['status_id'] == 2) {
  70. $where['type'] = 2;
  71. } elseif ($where['status_id'] > 2 && $where['status_id'] <= 4) {
  72. $where['type'] = 3;
  73. } else if ($where['status_id'] == 5) {
  74. $where['type'] = 4;
  75. } else if ($where['status_id'] == 6) {
  76. $where['type'] = 5;
  77. } else if ($where['status_id'] == 7) {
  78. $where['type'] = 6;
  79. }
  80. if ($follow && $follow[0]>0 ) {
  81. $fgroup_admin = implode(',',$follow);
  82. $follow_info = Dever::db('clue/follow')->find(array('info_id'=>$id,'follow_admin_id'=>$fgroup_admin));
  83. if ($follow_info) {
  84. $where['type'] = 3;
  85. } else {
  86. $where['type'] = 2;
  87. if ($where['status_id'] == 3 || $where['status_id'] == 4){
  88. $where['type'] = 3;
  89. } elseif ($where['status_id'] == 7) {
  90. $where['type'] = 6;
  91. } elseif($where['status_id'] == 5) {
  92. $where['type'] = 4;
  93. } elseif ($where['status_id'] == 6) {
  94. $where['type'] = 5;
  95. }
  96. }
  97. $where['follow'] = $follow;
  98. if ($info['follow_group_id'] && $info['follow_group_id']!=$follow[0]) {
  99. $where['follow_group_id'] = $follow[0];
  100. } elseif (!$info['follow_group_id'] || $info['follow_group_id']<=0) {
  101. $where['follow_group_id'] = $follow[0];
  102. }
  103. if ($info['follow_admin_id'] && $info['follow_admin_id']!=$follow[1]) {
  104. $where['follow_admin_id'] = $follow[1];
  105. } elseif (!$info['follow_group_id'] || $info['follow_admin_id']<=0) {
  106. $where['follow_admin_id'] = $follow[1];
  107. }
  108. if (!$info['create_group_id'] || $info['create_group_id']<=0) {
  109. $where['create_group_id'] = $follow[0];
  110. }
  111. if (!$info['create_admin_id'] || $info['create_admin_id']<=0) {
  112. $where['create_admin_id'] = $follow[1];
  113. }
  114. }
  115. if ($status_id && ($status_id == 5 || $status_id == 6)) {
  116. $where['fdate'] = time();
  117. }
  118. if ($info) {
  119. if ($follow && $follow[0]<0) {
  120. $where['type'] = 2;
  121. if ($where['status_id'] == 3 || $where['status_id'] == 4){
  122. $where['type'] = 3;
  123. } elseif ($where['status_id'] == 7) {
  124. $where['type'] = 6;
  125. } elseif($where['status_id'] == 5) {
  126. $where['type'] = 4;
  127. } elseif ($where['status_id'] == 6) {
  128. $where['type'] = 5;
  129. }
  130. $auth = Dever::load("manage/auth.info");
  131. $admin_group = Dever::db('manage/admin_group')->all(array('admin_id'=>$auth['id']));
  132. foreach ($admin_group as $k => $v) {
  133. $admin[$v['group_id']] = $v['group_id'];
  134. }
  135. foreach ($admin as $k1 =>$v1) {
  136. $group = Dever::db('manage/group')->find(array('company_id'=>$info['company_id'],'id'=>$v1));
  137. if ($group) {
  138. $where['follow'] = $group['id'].','.$auth['id'];
  139. if ($info['follow_group_id'] && $info['follow_group_id']!=$group['id']) {
  140. $where['follow_group_id'] = $group['id'];
  141. } elseif (!$info['follow_group_id'] || $info['follow_group_id'] <=0) {
  142. $where['follow_group_id'] = $group['id'];
  143. }
  144. if ($info['follow_admin_id'] && $info['follow_admin_id']!=$auth['id']) {
  145. $where['follow_admin_id'] = $auth['id'];
  146. } elseif (!$info['follow_group_id'] || $info['follow_group_id'] <=0) {
  147. $where['follow_admin_id'] = $auth['id'];
  148. }
  149. if (!$info['create_group_id'] || $info['create_group_id']<=0) {
  150. $where['create_group_id'] = $group['id'];
  151. }
  152. if (!$info['create_admin_id'] || $info['create_admin_id']<=0) {
  153. $where['create_admin_id'] = $auth['id'];
  154. }
  155. }
  156. }
  157. // $w['admin_id'] = $where['follow'];
  158. // $w['info_id'] = $id;
  159. // if ($where['type'] == 3) {
  160. // $w['status'] = 3;
  161. // } else {
  162. // $w['status'] = 2;
  163. // }
  164. // $ids = Dever::db('clue/follow')->insert($w);
  165. // if ($ids) {
  166. // $where['follow_id'] = $ids;
  167. // }
  168. }
  169. if (isset($where['follow']) && $where['follow']) {
  170. $where['follow'] = $where['follow'];
  171. } else {
  172. $where['follow'] = $info['follow'];
  173. }
  174. $w['follow_admin_id'] = $where['follow'];
  175. $w['info_id'] = $id;
  176. // if ($where['type'] == 3) {
  177. // $w['status'] = 3;
  178. // } else {
  179. // $w['status'] = 2;
  180. // }
  181. $w['status'] = 2;
  182. $ids = Dever::db('clue/follow')->insert($w);
  183. if ($ids) {
  184. $where['follow_id'] = $ids;
  185. }
  186. if (!$info['clue_num']) {
  187. $where['clue_num'] = $this->getClueNum();
  188. }
  189. Dever::db('clue/info')->update($where);
  190. }
  191. }
  192. #获取线索编号
  193. public function getClueNum()
  194. {
  195. $where['clue_num'] = Dever::order('X');
  196. $state = Dever::db('clue/info')->one($where);
  197. if (!$state) {
  198. return $where['clue_num'];
  199. } else {
  200. return $this->getClueNum();
  201. }
  202. }
  203. #通过跟进人信息修改线索表
  204. public function updateFollow($id,$name,$data)
  205. {
  206. Dever::config('base')->hook = true;
  207. $follow = Dever::db('clue/follow')->find($id);
  208. $info = Dever::db('clue/info')->find($follow['info_id']);
  209. if ($info) {
  210. $where['where_id'] = $info['id'];
  211. $where['follow_id'] = $id;
  212. $where['gdate'] = time();
  213. $where['day']= $follow['xdate'];
  214. $where['num'] = $info['num']+1;
  215. $where['type'] = 3;
  216. Dever::db('clue/info')->update($where);
  217. $w['where_id'] = $id;
  218. $w['follow_admin_id'] = $info['follow'];
  219. Dever::db('clue/follow')->update($w);
  220. }
  221. $auth = Dever::load('manage/auth.info');
  222. $admin = Dever::db('manage/admin')->find($auth['id']);
  223. $group_id = explode(',',$admin['group']);
  224. if ($group_id) {
  225. foreach($group_id as $k => $v) {
  226. $group = Dever::db('manage/group')->find(array('company_id'=>$info['company_id'],'id'=>$v));
  227. }
  228. }
  229. $branch_id = explode(',',$info['follow']);
  230. $i['crate_admin_id'] = $admin['id'];
  231. $i['crate_group_id'] = $group['id'];
  232. $i['crate_group_admin'] = $admin['id'].','.$group['id'];
  233. $i['follow_id'] = $id;
  234. $i['follow_group_admin'] = $info['follow'];
  235. $i['follow_group_id'] = $branch_id[0];
  236. $i['follow_admin_id'] = $branch_id[1];
  237. $i['info_id'] = $info['id'];
  238. Dever::db('clue/info_log')->insert($i);
  239. }
  240. #线索详情页
  241. public function show_api()
  242. {
  243. $id = Dever::input('id');
  244. $data['info'] = Dever::db('clue/info')->find($id);
  245. $admin = Dever::db('manage/admin')->find($data['info']['audit_admin']);
  246. $data['info']['admin_name'] = '';
  247. if ($admin) {
  248. $data['info']['admin_name'] = $admin['username'];
  249. }
  250. $data['info']['source_name'] = '';
  251. if ($data['info']['source']) {
  252. $source = Dever::db('clue/source')->find($data['info']['source']);
  253. if ($source) {
  254. $data['info']['source_name'] = $source['name'];
  255. }
  256. }
  257. $sex = Dever::db('clue/info')->config['config_sex'];
  258. $data['info']['sex_name'] = Dever::status($sex,$data['info']['sex']);
  259. $data['info']['area_name'] = '';
  260. if ($data['info']['area']) {
  261. $area = Dever::load("area/api.string", $data['info']['area']);
  262. if ($area) {
  263. $area = explode(',',$area);
  264. if (isset($area[1]) && $area[1]) {
  265. $data['info']['area_name'] = $area[0].'/'.$area[1];
  266. } else {
  267. $data['info']['area_name'] = $area[0];
  268. }
  269. }
  270. }
  271. // guanli.uat.churenyiliao.com/package/manage/?l=project/database/list&project=work&table=info&menu=work&search_option_state=1&search_option_dever_auth=2&menu_id=347
  272. $data['info']['status_name'] = '';
  273. if($data['info']['status_id']) {
  274. $status = Dever::db('clue/sale_status')->find($data['info']['status_id']);
  275. if ($status) {
  276. $data['info']['status_name'] = $status['name'];
  277. }
  278. }
  279. $userset = Dever::db('clue/user_set')->find($data['info']['userset_id']);
  280. if ($userset) {
  281. $data['info']['userset_name'] = $userset['name'];
  282. }
  283. $data['follow'] = Dever::db('clue/follow')->getAll(array('info_id'=>$id));
  284. $config_type = Dever::db('clue/follow')->config['config_type'];
  285. $people = array();
  286. foreach ($data['follow'] as $k => $v) {
  287. $admin_id = explode(',',$v['follow_admin_id']);
  288. $data['follow'][$k]['group_name'] = '';
  289. if (isset($admin_id[0]) && $admin_id[0]) {
  290. $group = Dever::db('manage/group')->find(array('id'=>$admin_id[0],'company_id'=>$data['info']['company_id']));
  291. if ($group) {
  292. $data['follow'][$k]['group_name'] = $group['name'];
  293. }
  294. }
  295. $data['follow'][$k]['admin_name'] = '';
  296. if (isset($admin_id[1]) && $admin_id[1]) {
  297. $admin = Dever::db('manage/admin')->find(array('id'=>$admin_id[1]));
  298. if ($admin) {
  299. $data['follow'][$k]['admin_name'] = $admin['username'];
  300. }
  301. }
  302. if ($data['follow'][$k]['admin_name']) {
  303. $data['follow'][$k]['group_name'] = $data['follow'][$k]['group_name'].' / '.$data['follow'][$k]['admin_name'];
  304. }
  305. $data['follow'][$k]['type_name'] = Dever::status($config_type,$v['type']);
  306. $data['follow'][$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
  307. $data['follow'][$k]['xdate'] = date('Y-m-d H:i',$v['xdate']);
  308. if ($v['pic']) {
  309. $data['follow'][$k]['pic'] = explode(',',$v['pic']);
  310. } else {
  311. $data['follow'][$k]['pic'] = '';
  312. }
  313. if (!$v['desc']) {
  314. unset($data['follow'][$k]);
  315. }
  316. }
  317. $data['info']['people'] = '';
  318. $branch = explode(',',$data['info']['follow']);
  319. $data['info']['people'] = $this->group_admin($data['info']['company_id'],$branch[0],$branch[1],1);
  320. $follow = 0;
  321. $follow = Dever::db('clue/follow')->getCount(array('info_id'=>$id));
  322. if ($data['info']['num'] && $data['info']['num']>0) {
  323. $data['info']['cishu'] = $data['info']['num'].'次';
  324. } else {
  325. $data['info']['cishu'] = $follow.'次';
  326. }
  327. $f = Dever::db('clue/follow')->getOne(array('info_id'=>$id));
  328. // print_R($f);die;
  329. if ($f) {
  330. $data['info']['xdate'] = date('Y-m-d',$f['xdate']);
  331. $data['info']['day'] = floor((time()-$f['cdate'])/86400).'天';
  332. } else {
  333. $data['info']['xdate'] = '-';
  334. $data['info']['day'] = floor((time()-$data['info']['cdate'])/86400).'天';
  335. }
  336. $data['info']['cdate'] = date('Y-m-d H:i',$data['info']['cdate']);
  337. $data['xiu'] = Dever::url('project/database/update?project=clue&table=info&where_id='.$id.'&col=wechat,qq,area,sex,age,trade,desc,remark', 'manage');
  338. if (Dever::load('manage/auth')->checkFunc('clue.info', 'infojichu', '基础信息修改')) {
  339. $data['jichu'] = Dever::url('project/database/update?project=clue&table=info&where_id='.$id.'&col=name,mobile,source', 'manage');
  340. }
  341. $data['gen'] = Dever::url('project/database/update?project=clue&table=follow&search_option_info_id='.$id, 'manage');
  342. $data['pai'] = Dever::url('project/database/update?project=clue&table=info&where_id='.$id.'&col=follow', 'manage');
  343. $data['ke'] = Dever::url('project/database/update?project=clue&table=info&where_id='.$id.'&col=userset_id', 'manage');
  344. $data['status'] = Dever::url('project/database/update?project=clue&table=info&where_id='.$id.'&col=status_id,status_desc', 'manage');
  345. return Dever::render('index', $data);
  346. }
  347. public function group_admin($company_id,$group_id,$admin_id,$type=false)
  348. {
  349. $group = Dever::db('manage/group')->find(array('company_id'=>$company_id,'id'=>$group_id));
  350. $admin = Dever::db('manage/admin')->find($admin_id);
  351. if ($type == 1) {
  352. return $group['name'].' <br/> '.$admin['username'];
  353. } else {
  354. return $group['name'].' / '.$admin['username'];
  355. }
  356. }
  357. public function source_Num($id)
  358. {
  359. $data = Dever::db('clue/info')->state(array('source'=>$id,'out_type'=>2));
  360. $html = array();
  361. $string = '';
  362. $url = Dever::url('project/database/list?project=clue&table=info&search_option_source='.$id.'&search_option_out_type=2&[refer]', 'manage');
  363. if (count($data) > 0) {
  364. $string = '<a href="'.$url.'">(查看)</a>';
  365. }
  366. return count($data).$string;
  367. }
  368. public function insertSell($id,$name,$data) {
  369. $group = Dever::param('group',$data);
  370. if ($group) {
  371. $res = Dever::db('clue/salepeople')->find(array('group'=>$group));
  372. if ($res && isset($id['where_id']) && $id['where_id']){
  373. if ($res['id'] != $id['where_id']){
  374. Dever::alert('销售员不可重复提交');
  375. }
  376. } elseif ($res) {
  377. Dever::alert('部门已存在');
  378. }
  379. }
  380. }
  381. public function updateSell($id,$name,$data)
  382. {
  383. $group = Dever::param('group',$data);
  384. if ($group) {
  385. if (isset($group[0]) && $group[0]) {
  386. $w['where_id'] = $id;
  387. $w['group_id'] = $group[0];
  388. Dever::db('clue/salepeople')->update($w);
  389. }
  390. }
  391. }
  392. public function back_people_api($id)
  393. {
  394. Dever::config('base')->hook = true;
  395. $data = Dever::db('clue/salepeople')->find($id);
  396. $branch = Dever::db('work/branch')->find(array('group_id'=>$data['group_id']));
  397. $admin_id = explode(',',$branch['group']);
  398. if ($data['group']!=$branch['group']) {
  399. $info = Dever::db('clue/info')->state(array('follow'=>$data['group']));
  400. if ($info) {
  401. foreach ($info as $k =>$v) {
  402. $where['where_id'] = $v['id'];
  403. $where['follow'] = $branch['group'];
  404. $where['follow_group_id'] = $branch['group_id'];
  405. $where['follow_admin_id'] = $admin_id[1];
  406. Dever::db('clue/info')->update($where);
  407. // print_R($v);die;
  408. // echo dever::sql();die;
  409. }
  410. }
  411. }
  412. return 'ok';
  413. // print_R($branch);die;
  414. // print_R($data);die;
  415. }
  416. }