Manage.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. namespace Clue\Lib;
  3. use Dever;
  4. Class Manage
  5. {
  6. #销售员
  7. public function getSale($id)
  8. {
  9. $data = Dever::db('clue/salepeople')->find($id);
  10. if ($data) {
  11. $data['group'] = explode(',',$data['group']);
  12. $group = Dever::db('manage/group')->find($data['group'][0]);
  13. $admin = Dever::db('manage/admin')->find($data['group'][1]);
  14. $html = array();
  15. $html['name'] = $admin['username'].'<br/>'.$admin['email'].'<br/>'.$group['name'];
  16. return $html;
  17. }
  18. }
  19. #线索列表导出
  20. public function out_info($data)
  21. {
  22. $header = array('客户姓名','手机号','客户等级','跟进次数','所在城市','跟进人','跟进状态','最近跟进时间');
  23. $body = array();
  24. $config_type = Dever::db('clue/info')->config['config_type'];
  25. foreach ($data as $k => $v) {
  26. $user_set = Dever::db('clue/user_set')->find($v['userset_id']);
  27. $userset_name = '';
  28. if ($user_set) {
  29. $userset_name = $user_set['name'];
  30. }
  31. $num = '';
  32. if ($v['num'] && $v['num'] > 0) {
  33. $num = $v['num'];
  34. } else {
  35. $num = Dever::db('clue/follow')->getCount(array('info_id'=>$v['id']));
  36. }
  37. $area = '';
  38. if ($v['area']) {
  39. $area = Dever::load("area/api.string", $v['area']);
  40. if (strpos($area,',')!=false) {
  41. $area = str_replace(',', '/', $area);
  42. }
  43. }
  44. $branch = '';
  45. if ($v['branch_id']) {
  46. $v['branch_id'] = explode(',',$v['branch_id']);
  47. if ($v['branch_id'][0] > 0) {
  48. $branch = Dever::load('clue/lib/info')->group_admin($v['company_id'],$v['branch_id'][0],$v['branch_id'][1]);
  49. }
  50. }
  51. $type = '';
  52. $type = Dever::status($config_type,$v['type']);
  53. $gdate = '';
  54. if ($v['gdate']) {
  55. $gdate = date('Y-m-d H:i',$v['gdate']);
  56. }
  57. $d = array
  58. (
  59. $v['name'],
  60. $v['mobile'],
  61. $userset_name,
  62. $num,
  63. $area,
  64. $branch,
  65. $type,
  66. $gdate,
  67. );
  68. $body[] = $d;
  69. }
  70. $file = Dever::input('excel_name');
  71. return Dever::excelExport($body, $header, $file);
  72. }
  73. public function out_muban_api()
  74. {
  75. $header = array('客户姓名*','手机号*','客户等级*','微信号','QQ号','所在城市','性别','年龄','行业','线索状态(默认为未分派)');
  76. $body = array();
  77. $file = "下载模板";
  78. return Dever::excelExport($body, $header, $file);
  79. }
  80. public function updateImport($id,$name,$data) {
  81. $where = array();
  82. $source = Dever::param('source',$data);
  83. if ($source) {
  84. $sou = Dever::db('clue/source')->find(array('name'=>$source));
  85. if ($sou){
  86. $where['source'] = $sou['id'];
  87. }
  88. }
  89. $file = Dever::param('file',$data);
  90. $file = Dever::local($file);
  91. $res = Dever::excelImport($file,0);
  92. if ($res) {
  93. foreach ($res as $k => $v) {
  94. if ($k >= 2) {
  95. $where['name'] = $v['A'];
  96. $where['mobile'] = $v['B'];
  97. $where['clue_num'] = Dever::load('clue/lib/info')->getClueNum();
  98. if ($v['C']) {
  99. $userset = Dever::db('clue/user_set')->find(array('name'=>$v['C']));
  100. if ($userset ) {
  101. $where['userset_id'] = $userset['id'];
  102. }
  103. }
  104. if ($v['D']) {
  105. $where['wechat'] = $v['D'];
  106. }
  107. if ($v['E']) {
  108. $where['qq'] = $v['E'];
  109. }
  110. $provice = '';
  111. $city_id = '';
  112. if ($v['F']) {
  113. $area = explode('/',$v['F']);
  114. if ($area[0]) {
  115. $pro = Dever::db('area/province')->find(array('name'=>$area[0]));
  116. if ($pro) {
  117. $province = $pro['id'];
  118. }
  119. }
  120. if(isset($area[1]) && $area[1]) {
  121. $city = Dever::db('area/city')->find(array('name'=>$area[1]));
  122. if ($city) {
  123. $city_id = ','.$city['id'];
  124. }
  125. }
  126. $where['area'] = $province.$city_id;
  127. }
  128. if ($v['G']) {
  129. if ($v['G'] == '未知') {
  130. $where['sex'] = 1;
  131. } else if ($v['G'] == '男') {
  132. $where['sex'] = 2;
  133. } else if ($v['G'] == '女') {
  134. $where['sex'] = 3;
  135. }
  136. }
  137. if ($v['H']) {
  138. $where['age'] = $v['H'];
  139. }
  140. if ($v['I']) {
  141. $where['trade'] = $v['I'];
  142. }
  143. if ($v['J']) {
  144. if ($v['J'] == '未分派') {
  145. $where['status_id'] = 1;
  146. } elseif ($v['J'] == '初期接触阶段') {
  147. $where['status_id'] = 2;
  148. } elseif ($v['J'] == '潜在客户洽谈') {
  149. $where['status_id'] = 3;
  150. } elseif ($v['J'] == '定金已付阶段') {
  151. $where['status_id'] = 4;
  152. } elseif ($v['J'] == '成交完成') {
  153. $where['status_id'] = 5;
  154. } elseif ($v['J'] == '取消关闭') {
  155. $where['status_id'] = 6;
  156. } elseif ($v['J'] == '搁置中 ') {
  157. $where['status_id'] = 7;
  158. }
  159. } else {
  160. $where['status_id'] = 1;
  161. }
  162. $group_id = '';
  163. $admin_id = '';
  164. $company = Dever::load('manage/company.get');
  165. $admin = Dever::load("manage/auth.info");
  166. $admin = Dever::db('manage/admin')->find($admin['id']);
  167. if ($admin) {
  168. $admin['group'] = explode(',',$admin['group']);
  169. foreach ($admin['group'] as $k =>$v) {
  170. $group = Dever::db('manage/group')->find(array('company_id'=>$company,'id'=>$v));
  171. }
  172. if ($group) {
  173. $group_id = $group['id'];
  174. $where['follow_group_id'] = $group['id'];
  175. $where['create_group_id'] = $group['id'];
  176. }
  177. $admin_id = $admin['id'];
  178. $where['follow_admin_id'] = $admin['id'];
  179. $where['create_admin_id'] = $admin['id'];
  180. $where['follow'] = $group_id.','.$admin_id;
  181. }
  182. $where['out_type'] = 2;
  183. $info = Dever::db('clue/info')->find(array('mobile'=>$where['mobile'],'clear'=>true));
  184. $where['clear'] = true;
  185. if (!$info && $where) {
  186. Dever::db('clue/info')->insert($where);
  187. }
  188. }
  189. }
  190. }
  191. }
  192. /*
  193. public function updateImport($id,$name,$data) {
  194. $where = array();
  195. $source = Dever::param('source',$data);
  196. if ($source) {
  197. $sou = Dever::db('clue/source')->find(array('name'=>$source));
  198. if ($sou){
  199. $where['source'] = $sou['id'];
  200. }
  201. }
  202. $file = Dever::param('file',$data);
  203. $file = Dever::local($file);
  204. $res = Dever::excelImport($file,0);
  205. if ($res) {
  206. foreach ($res as $k => $v) {
  207. if ($k >= 2) {
  208. $where['name'] = $v['A'];
  209. $where['mobile'] = $v['B'];
  210. $where['clue_num'] = Dever::load('clue/lib/info')->getClueNum();
  211. if ($v['C']) {
  212. $userset = Dever::db('clue/user_set')->find(array('name'=>$v['C']));
  213. if ($userset ) {
  214. $where['userset_id'] = $userset['id'];
  215. }
  216. }
  217. $where['num'] = $v['D'];
  218. $provice = '';
  219. $city_id = '';
  220. if ($v['E']) {
  221. $area = explode('/',$v['E']);
  222. if ($area[0]) {
  223. $pro = Dever::db('area/province')->find(array('name'=>$area[0]));
  224. if ($pro) {
  225. $province = $pro['id'];
  226. }
  227. }
  228. if(isset($area[1]) && $area[1]) {
  229. $city = Dever::db('area/city')->find(array('name'=>$area[1]));
  230. if ($city) {
  231. $city_id = ','.$city['id'];
  232. }
  233. }
  234. $where['area'] = $province.$city_id;
  235. }
  236. if ($v['F']) {
  237. $group_id = '';
  238. $admin_id = '';
  239. #跟进人
  240. $f=explode('/',$v['F']);
  241. if (isset($f[0]) && $f[0]) {
  242. $group = Dever::db('manage/group')->find(array('name'=>$f[0]));
  243. if ($group){
  244. $group_id = $group['id'];
  245. $where['follow_group_id'] = $group['id'];
  246. $where['create_group_id'] = $group['id'];
  247. }
  248. }
  249. if (isset($f[1]) && $f[1]) {
  250. $f[1] = trim($f[1]);
  251. $admin = Dever::db('manage/admin')->find(array('username'=>$f[1]));
  252. if ($admin){
  253. $admin_id = ','.$admin['id'];
  254. $where['follow_admin_id'] = $admin['id'];
  255. $where['create_admin_id'] = $admin['id'];
  256. }
  257. }
  258. $where['follow'] = $group_id.$admin_id;
  259. }
  260. if ($v['G']) {
  261. #跟进状态
  262. if ($v['G'] == '待跟进') {
  263. $where['type'] = 1;
  264. }
  265. if ($v['G'] == '未跟进') {
  266. $where['type'] = 2;
  267. }
  268. if ($v['G'] == '已跟进') {
  269. $where['type'] = 3;
  270. }
  271. if ($v['G'] == '已完成') {
  272. $where['type'] = 4;
  273. }
  274. if ($v['G'] == '已关闭') {
  275. $where['type'] = 5;
  276. }
  277. }
  278. if ($v['H']) {
  279. #跟进时间
  280. $where['gdate'] = strtotime($v['H']);
  281. }
  282. $where['out_type'] = 2;
  283. $info = Dever::db('clue/info')->find(array('mobile'=>$where['mobile'],'clear'=>true));
  284. // $where['clear'] = true;
  285. if (!$info && $where) {
  286. Dever::db('clue/info')->insert($where);
  287. }
  288. }
  289. }
  290. }
  291. }*/
  292. public function group($id)
  293. {
  294. $data = Dever::db('manage/group')->find($id);
  295. return $data['name'];
  296. }
  297. }