Manage.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <?php
  2. namespace Work\Lib;
  3. use Dever;
  4. Class Manage
  5. {
  6. public function getCoor_api()
  7. {
  8. $id = Dever::input('id');
  9. $info = false;
  10. if ($id) {
  11. $info = Dever::db('work/branch')->one($id);
  12. }
  13. $group = Dever::input('group');
  14. $temp = explode(',', $group);
  15. $group_id = $temp[0];
  16. $admin_id = false;
  17. if (isset($temp[1])) {
  18. $admin_id = $temp[1];
  19. } else {
  20. return 'no';
  21. }
  22. $admin = Dever::load('manage/company')->getAdmin($group_id, $admin_id);
  23. $config = array();
  24. $config['struct']['coor'] = array
  25. (
  26. 'type' => 'varchar-2000',
  27. 'name' => '协调人',
  28. 'default' => '',
  29. 'desc' => '请先选择协调人',
  30. 'match' => 'option',
  31. 'update' => 'checkbox',
  32. 'value' => $info ? $info['coor'] : false,
  33. 'option' => $admin,
  34. );
  35. $data = array();
  36. $result = Dever::load('manage/database')->update_struct($config, false, array(), -1, '', true);
  37. return implode('', $result);
  38. }
  39. public function setInfoStatus_api ()
  40. {
  41. Dever::config('base')->hook = true;
  42. $id = Dever::input('id');
  43. $status = Dever::input('status');
  44. $type = Dever::input('type');
  45. if ($id) {
  46. $info = Dever::db('work/info')->find($id);
  47. $update['where_id'] = $info['id'];
  48. if ($type == 1) {
  49. $update['status'] = 4;
  50. } else {
  51. $update['status'] = 3;
  52. }
  53. $update = $this->finish($update, $info);
  54. Dever::db('work/info')->update($update);
  55. return 'ok';
  56. }
  57. }
  58. private function finish($update, $info)
  59. {
  60. $update['fdate'] = time();
  61. $update['chdate'] = time();
  62. $app = Dever::db('work/appoint')->getAdmin(array('info_id'=>$info['id'],'admin'=>$info['audit_admin']));
  63. if ($app && $app['admin']) {
  64. $update['fpeople'] = $app['admin'];
  65. } else {
  66. if ($info['branch_id']) {
  67. $branch = explode(',',$info['branch_id']);
  68. if (isset($branch[1]) && $branch[1]) {
  69. $update['fpeople'] = $branch[1];
  70. }
  71. } else {
  72. $update['fpeople'] = $info['audit_admin'];
  73. }
  74. }
  75. $log = Dever::db('work/info_log')->find(array('info_id'=>$info['id']));
  76. if ($log) {
  77. $w = array();
  78. $w['where_id'] = $log['id'];
  79. $w['fdate'] = time();
  80. if($update['status'] == 4){
  81. $w['cloce_date'] = time();
  82. }
  83. Dever::db('work/info_log')->update($w);
  84. }
  85. return $update;
  86. }
  87. public function insertInfo($id,$name,$data) {
  88. $mobile = Dever::param('mobile',$data);
  89. if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $mobile)){
  90. Dever::alert('手机号不正确');
  91. }
  92. $cate_id = Dever::param('cate_id',$data);
  93. if ($cate_id[0]<0) {
  94. Dever::alert('问题类型不能为空');
  95. }
  96. }
  97. public function updateInfo($id,$name,$data)
  98. {
  99. Dever::config('base')->hook = true;
  100. $mobile = Dever::param('mobile',$data);
  101. $cate_id = Dever::param('cate_id',$data);
  102. $name = Dever::param('name',$data);
  103. $email = Dever::param('email',$data);
  104. $user = Dever::db('work/user')->find(array('mobile'=>$mobile));
  105. if ($user) {
  106. if ($name && $user['name'] != $name) {
  107. Dever::db('work/user')->update(array('where_id'=>$user['id'],'name'=>$name));
  108. }
  109. } else {
  110. $member = Dever::db('agent/member')->find(array('mobile'=>$mobile));
  111. if ($member) {
  112. $insert['agent_uid'] = $member['id'];
  113. }
  114. $option = Dever::db('option/member')->find(array('mobile'=>$mobile));
  115. if ($option) {
  116. $insert['option_uid'] = $option['id'];
  117. }
  118. $passport = Dever::db('passport/user')->find(array('mobile'=>$mobile));
  119. if ($passport) {
  120. $insert['passport_uid'] = $passport['id'];
  121. }
  122. if ($name) {
  123. $insert['name'] = $name;
  124. }
  125. $insert['mobile'] = $mobile;
  126. if ($insert) {
  127. Dever::db('work/user')->insert($insert);
  128. }
  129. }
  130. $info = Dever::db('work/info')->find($id);
  131. if ($info) {
  132. $w = array();
  133. if (!$info['work_num']) {
  134. $w['work_num'] = $this->getWorkId();
  135. }
  136. if ($info['cate_id']) {
  137. $cate_id = explode(',', $info['cate_id']);
  138. if (isset($cate_id[1]) && $cate_id[1]) {
  139. $info['question'] = $w['question'] = $cate_id[1];
  140. }
  141. if (!$info['cate'] || $info['cate']<=0) {
  142. $w['cate'] = $cate_id[0];
  143. }
  144. }
  145. if ($info['question']) {
  146. $product = Dever::db('work/question')->find($info['question']);
  147. $w['product'] = $product['product_id'];
  148. }
  149. if ($info['branch_id'] && strstr($info['branch_id'], ',') && $info['branch_id'] != -1) {
  150. $branch_id = explode(',', $info['branch_id']);
  151. $w['group'] = $branch_id[0];
  152. $w['appoint_id'] = $branch_id[1];
  153. }
  154. if ($info['status'] == 3 || $info['status'] == 4) {
  155. $w = $this->finish($w, $info);
  156. }
  157. if ($w) {
  158. $w['where_id'] = $id;
  159. Dever::db('work/info')->update($w);
  160. }
  161. if ($email && $email == 2) {
  162. if ($w)
  163. $admin = Dever::db('manage/admin')->find($branch_id[1]);
  164. $res = Dever::load('work/lib/manage')->getTotal($admin['id'],'1,2');
  165. // $url = Dever::url('project/database/list?project=work&table=info&search_option_dever_auth=2&search_option_state=1&[refer]', 'manage');
  166. $work_list =Dever::url('project/database/list?project=work&table=info&search_option_dever_auth=2&search_option_state=1&[refer]', 'manage');
  167. $url = Dever::url('home?link=' . urlencode($work_list) . '&group=10&parent_menu=work&menu=work.my' , 'manage');
  168. $content = '你有'.$res.'个待处理工单,<a href="'.$url.'">点此跳转至工单系统查看</a>';
  169. Dever::load('work/lib/cron')->send($admin['email'],$admin['username'],'你有新的工单待处理',$content);
  170. }
  171. }
  172. }
  173. public function getWorkId()
  174. {
  175. $where['work_num'] = Dever::order('W');
  176. $state = Dever::db('work/info')->one($where);
  177. if (!$state) {
  178. return $where['work_num'];
  179. } else {
  180. return $this->getWorkId();
  181. }
  182. }
  183. public function getUser($id)
  184. {
  185. $info = Dever::db('work/info')->find($id);
  186. if ($info && isset($info['mobile']) && $info['mobile']) {
  187. $data= Dever::db('work/user')->find(array('mobile'=>$info['mobile']));
  188. if ($data) {
  189. $html['user'] = $data['name'].'<br/>'.$data['mobile'];
  190. if (isset($info['fdate']) && $info['fdate']) {
  191. $fdate = date('Y-m-d H:i:s',$info['fdate']);
  192. } else {
  193. $fdate = '';
  194. }
  195. $html['time'] = date('Y-m-d H:i:s',$info['cdate']).'<br/>'.$fdate;
  196. $cate_id = explode(',',$info['cate_id']);
  197. $cate_name = '';
  198. $question_name = '';
  199. if (isset($cate_id[0]) && $cate_id[0]) {
  200. $cate = Dever::db('work/q_cate')->find($cate_id[0]);
  201. $cate_name = $cate['name'];
  202. }
  203. if (isset($cate_id[1]) && $cate_id[1]) {
  204. $question = Dever::db('work/question')->find($cate_id[1]);
  205. $question_name = $question['name'];
  206. }
  207. if ($info['audit_admin']) {
  208. $audit = Dever::db('manage/admin')->find($info['audit_admin']);
  209. if ($audit) {
  210. $admin['group'] = explode(',',$audit['group']);
  211. foreach ($admin['group'] as $k => $v) {
  212. $group = Dever::db('manage/group')->find(array('company_id'=>$info['company_id'],'id'=>$v));
  213. }
  214. $html['chuangjian'] = $group['name'].' / ' .$audit['username'];
  215. }
  216. }
  217. $html['cate_name'] = $cate_name.'<br/>'.$question_name;
  218. return $html;
  219. } else {
  220. return '';
  221. }
  222. } else {
  223. return '';
  224. }
  225. }
  226. public function xietiao_api($id)
  227. {
  228. $data = Dever::db('work/branch')->find($id);
  229. $data['group'] = explode(',',$data['group']);
  230. $group = Dever::db('manage/group')->find($data['group'][0]);
  231. $admin = Dever::load('manage/company')->getAdmin($group['id'], $data['group'][1]);
  232. $gad = Dever::db('manage/admin')->find($data['group'][1]);
  233. $res = array();
  234. foreach ($admin as $k => $v) {
  235. $res[$k] = $v['username'].'<br/>'.$v['email'];
  236. }
  237. // $total = Dever::db('work/info')->getquestTotal(array('group'=>$data['group'][0]));
  238. $html = array();
  239. $html['group'] = $group['name'].'<br/>'.$gad['username'];
  240. $html['name'] = implode('<br/>',$res);
  241. $total = Dever::db('work/question')->getTotal(array('branch_id'=>$data['group_id']));
  242. $html['num'] = $total;
  243. return $html;
  244. }
  245. #获取客户信息
  246. public function search_api()
  247. {
  248. $value = Dever::input('value');
  249. if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $value)){
  250. return '代理商手机号不正确';
  251. }
  252. if ($value) {
  253. $name = '';
  254. $role_name = '';
  255. $user = Dever::db('work/user')->find(array('mobile'=>$value));
  256. if(!$user) {
  257. $member = Dever::db('agent/member')->find(array('mobile'=>$value));
  258. if ($member) {
  259. $name = $member['name'];
  260. $type = "代理商";
  261. $role = Dever::db('setting/role')->find($member['role']);
  262. if ($role ) {
  263. $role_name = $role['name'];
  264. }
  265. $option = Dever::db('option/member')->find(array('mobile'=>$value));
  266. if ($option) {
  267. $type = $type.'<br/>期权账户';
  268. $passport = Dever::db('passport/user')->find(array('mobile'=>$value));
  269. if ($passport) {
  270. $type = $type.'<br/>小程序';
  271. }
  272. } else {
  273. $passport = Dever::db('passport/user')->find(array('mobile'=>$value));
  274. if ($passport) {
  275. $type = $type.'<br/>小程序';
  276. }
  277. }
  278. } else {
  279. $option = Dever::db('option/member')->find(array('mobile'=>$value));
  280. if ($option) {
  281. $name = $option['name'];
  282. $type = '期权账户';
  283. $passport = Dever::db('passport/user')->find(array('mobile'=>$value));
  284. if ($passport) {
  285. $type = $type.'<br/>小程序';
  286. }
  287. } else {
  288. $passport = Dever::db('passport/user')->find(array('mobile'=>$value));
  289. if ($passport) {
  290. $name = $passport['username'];
  291. $type = '小程序';
  292. } else {
  293. $type = '无系统关联关系';
  294. }
  295. }
  296. }
  297. } else {
  298. $name = $user['name'];
  299. $type = '客服系统用户';
  300. if ($user['agent_uid'] && $user['agent_uid'] > 0) {
  301. $member = Dever::db('agent/member')->find($user['agent_uid']);
  302. $role = Dever::db('setting/role')->find($member['role']);
  303. if ($role) {
  304. $role_name = $role['name'];
  305. }
  306. $type = $type.'<br/>代理商';
  307. }
  308. if ($user['option_uid'] && $user['option_uid'] > 0) {
  309. $type = $type.'<br/>期权账户';
  310. }
  311. if ($user['passport_uid'] && $user['passport_uid'] > 0) {
  312. $type = $type.'<br/>小程序';
  313. }
  314. }
  315. $table = array();
  316. if ($name && $role_name) {
  317. $table['head'] = array('名称', '电话号码', '平台' ,'角色');
  318. $table['body'] = array($name, $value, $type, $role_name);
  319. } elseif ($name && !$role_name) {
  320. $table['head'] = array('名称', '电话号码', '平台');
  321. $table['body'] = array($name, $value, $type);
  322. } elseif (!$name && $role_name) {
  323. $table['head'] = array('电话号码', '平台' ,'角色');
  324. $table['body'] = array($value, $type, $role_name);
  325. } else if (!$name && !$role_name) {
  326. $table['head'] = array('电话号码', '平台');
  327. $table['body'] = array($value, $type );
  328. }
  329. $result[] = array
  330. (
  331. 'type' => 'table',
  332. 'content' => $table,
  333. );
  334. $html = Dever::show('', $result, false, false);
  335. return array('html' => $html, 'data' => array('name' => $name));
  336. }
  337. }
  338. public function admin($id)
  339. {
  340. $data = Dever::db('work/product')->find(array($id));
  341. $admin_id = explode(',',$data['admin_id']);
  342. $admin = Dever::db('manage/admin')->find($admin_id[1]);
  343. if ($admin) {
  344. return $admin['username'].'<br/>'.$admin['email'];
  345. }
  346. }
  347. public function branch($id)
  348. {
  349. if (isset($id) && $id) {
  350. $group = Dever::db('manage/group')->find($id);
  351. if (isset($group) && isset($group['name']) && $group['name']) {
  352. return $group['name'];
  353. }
  354. }
  355. }
  356. #工单列表导出
  357. public function out_info($data)
  358. {
  359. $header = array('客户名称','手机号','问题类型','问题类型描述','优先级','问题描述','处理结果','创建时间','完成时间');
  360. $body = array();
  361. $config = Dever::db('work/info')->config['config_status'];
  362. foreach ($data as $k => $v ) {
  363. $cate_name = '';
  364. $cate_id = explode(',',$v['cate_id']);
  365. if (isset($cate_id[0]) && $cate_id[0]) {
  366. $cate = Dever::db('work/q_cate')->find(array('id'=>$cate_id[0]));
  367. if ($cate) {
  368. $cate_name = $cate['name'];
  369. }
  370. }
  371. $question_name = '';
  372. if (isset($cate_id[1]) && $cate_id[1]) {
  373. $question = Dever::db('work/question')->find(array('id'=>$cate_id[1]));
  374. if ($question) {
  375. $question_name = $question['name'];
  376. }
  377. }
  378. $priority_name = '';
  379. $priority = Dever::db('work/priority')->find(array('id'=>$v['priority_id']));
  380. if ($priority) {
  381. $priority_name = $priority['name'];
  382. }
  383. $status_name = Dever::status($config,$v['status']);
  384. $cdate = date('Y-m-d H:i',$v['cdate']);
  385. $fdate = '';
  386. if ($v['fdate']){
  387. $fdate = date('Y-m-d H:i',$v['fdate']);
  388. }
  389. $d = array
  390. (
  391. $v['name'],
  392. $v['mobile'],
  393. $cate_name,
  394. $question_name,
  395. $priority_name,
  396. $v['desc'],
  397. $status_name,
  398. $cdate,
  399. $fdate,
  400. );
  401. $body[] = $d;
  402. }
  403. $file = Dever::input('excel_name');
  404. return Dever::excelExport($body, $header, $file);
  405. }
  406. public function getTotal($admin_id,$status=false)
  407. {
  408. $company = Dever::load('manage/company.get');
  409. $where = array();
  410. if ($status){
  411. $where['status'] = $status;
  412. if ($where['status'] == '1,2') {
  413. $where['appoint_id'] = $admin_id;
  414. } else {
  415. $where['fpeople'] = $admin_id;
  416. }
  417. } else {
  418. $where['audit_admin'] = $admin_id;
  419. }
  420. if ($company) {
  421. $where['company_id'] = $company;
  422. }
  423. $data = Dever::db('work/info')->getTotal($where);
  424. return $data;
  425. }
  426. public function getmyTotal($admin_id,$type) {
  427. // $info = Dever::db('work/info')->getmyAll(array('audit_admin'=>$admin_id,'state'=>1));
  428. $data = Dever::db('work/info_log')->getmyAll(array('app_admin_id'=>$admin_id,'state'=>1));
  429. $res = Dever::db('work/info_log')->getmyAll(array('admin_id'=>$admin_id));
  430. $work_info = array_merge($data,$res);
  431. $rest = array();
  432. foreach($work_info as $k=>$v){
  433. $rest[$v['info_id']]=$v;
  434. }
  435. // print_R($data);die;
  436. $search_ids = '';
  437. if ($rest) {
  438. $search_ids = implode(',',array_keys($rest));
  439. }
  440. if ($type == 1) {
  441. return count($rest);
  442. } else {
  443. return $search_ids;
  444. }
  445. }
  446. }