Info.php 14 KB

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