Info.php 13 KB

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