Info.php 14 KB

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