Cron.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace Work\Lib;
  3. use Dever;
  4. Class Cron
  5. {
  6. #工单日统计
  7. public function index_api(){
  8. $title = '工单每日统计';
  9. $data = Dever::db('work/branch')->state(array('type'=>1));
  10. foreach ($data as $k => $v) {
  11. $group_id = explode(',',$v['group']);
  12. $admin = Dever::db('manage/admin')->find($group_id[1]);
  13. $content = $this->email_api($v,$admin);
  14. if ($content) {
  15. $this->send($admin['email'], $admin['username'], $title, $content);
  16. }
  17. }
  18. }
  19. #发送邮件
  20. public function email_api($v,$fsadmin)
  21. {
  22. $start=mktime(0,0,0,date('m'),date('d'),date('Y'))-86400;
  23. $end = $start+86400-1;
  24. $config = Dever::db('work/info')->config['config_status'];
  25. $data['branch'] = $v;
  26. $question = Dever::db('work/question')->state(array('branch_id'=>$data['branch']['id']));
  27. $question = array_keys($question);
  28. $data['info']['app'] = Dever::db('work/info')->getCount(array('question'=>$question,'end'=>$end));
  29. $data['info']['xu'] = Dever::db('work/info')->getCount(array('group'=>$data['branch']['group_id'],'end'=>$end,'status'=>2));
  30. $admin = explode(',',$data['branch']['group']);
  31. if ($data['branch']['coor']) {
  32. $coor = explode(',',$data['branch']['coor']);
  33. if (isset($coor) && $coor[0] && $coor[0] >0) {
  34. $people = $data['branch']['coor'].','.$admin[1];
  35. } else {
  36. $people = $admin[1];
  37. }
  38. } else {
  39. $people = $admin[1];
  40. }
  41. $data['info']['yi'] = Dever::db('work/info')->getCount(array('fpeople'=>$people,'end'=>$end,'status'=>'3,4'));
  42. $data['question'] = Dever::db('work/question')->getAll(array('branch_id'=>$data['branch']['id']));
  43. $question = implode(',',$question);
  44. if ($question) {
  45. $data['app'] = Dever::db('work/info')->fetchAll('select * from churen_work_info where (`group` in ('.$data['branch']['group_id'].') or fpeople in ('.$people.') or question in ('.$question.')) and cdate <='.$end.' and state = 1');
  46. foreach ($data['app'] as $k1 => $v1) {
  47. $data['app'][$k1]['cdate'] = date('Y-m-d H:i:s',$v1['cdate']);
  48. $data['app'][$k1]['zhipai'] = date('Y-m-d H:i:s',$v1['zdate']);
  49. $data['app'][$k1]['chu'] = date('Y-m-d H:i:s',$v1['chdate']);
  50. $cate = Dever::db('work/q_cate')->find($v1['cate_id']);
  51. $data['app'][$k1]['cate_name'] = $cate['name'];
  52. $priority = Dever::db('work/priority')->find($v1['priority_id']);
  53. $data['app'][$k1]['priority_name'] = $priority['name'];
  54. $data['app'][$k1]['status']= Dever::status($config,$v1['status']);
  55. }
  56. }
  57. $msg = array();
  58. $msg['admin_email'] = $fsadmin['email'];
  59. $msg['admin_username'] = $fsadmin['username'];
  60. $msg['app'] = $data['info']['app'];
  61. $msg['xu'] = $data['info']['xu'];
  62. $msg['yi'] = $data['info']['yi'];
  63. $res = Dever::log($msg, 'work');
  64. return Dever::render('email', $data);
  65. }
  66. #代理商统计发送邮件
  67. public function send($email, $username, $title, $content)
  68. {
  69. $config = Dever::config('base', 'project')->email;
  70. Dever::apply('src/PHPMailer', 'email');
  71. Dever::apply('src/Exception', 'email');
  72. Dever::apply('src/SMTP', 'email');
  73. $mail = new \PHPMailer\PHPMailer\PHPMailer();
  74. $mail->isSMTP();
  75. //$mail->SMTPDebug = 2;
  76. $mail->CharSet = 'UTF-8';
  77. $mail->Host = $config['smtp'];
  78. $mail->Port = 465;
  79. $mail->SMTPSecure = 'ssl';
  80. $mail->SMTPAuth = true;
  81. $mail->Username = $config['username'];
  82. $mail->Password = $config['password'];
  83. $mail->setFrom($config['from'][0], '统计');
  84. $mail->addAddress($email, $username);
  85. $mail->Subject = "=?utf-8?B?" . base64_encode($title) . "?=";
  86. $mail->Body = $content;
  87. $mail->isHTML(true);
  88. //$mail->addAttachment($file);
  89. if (!$mail->send()) {
  90. Dever::alert("Mailer Error: " . $mail->ErrorInfo);
  91. } else {
  92. return 'ok';
  93. }
  94. }
  95. #同步info表中的product
  96. public function product_api()
  97. {
  98. $data = Dever::db('work/info')->state();
  99. if ($data) {
  100. foreach ($data as $k => $v) {
  101. if (!$v['product'] || $v['product']<=0) {
  102. $cate = explode(',',$v['cate_id']);
  103. if (isset($cate[1]) && $cate[1]) {
  104. $product = Dever::db('work/question')->find($cate[1]);
  105. if ($product) {
  106. $where['where_id'] = $v['id'];
  107. $where['product'] = $product['product_id'];
  108. Dever::db('work/info')->update($where);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. public function updateTime_api()
  116. {
  117. $data = Dever::db('work/info')->state();
  118. foreach ($data as $k => $v) {
  119. if (!$v['fpeople'] && ($v['status'] == 3 || $v['status'] == 4)) {
  120. $app = Dever::db('work/appoint')->getAdmin(array('info_id'=>$v['id'],'admin'=>$v['audit_admin']));
  121. if ($app && $app['admin']) {
  122. $update['fpeople'] = $app['admin'];
  123. } else {
  124. if ($v['branch_id']) {
  125. $branch = explode(',',$v['branch_id']);
  126. if (isset($branch[1]) && $branch[1]) {
  127. $update['fpeople'] = $branch[1];
  128. }
  129. } else {
  130. $update['fpeople'] = $v['audit_admin'];
  131. }
  132. }
  133. $update['where_id'] = $v['id'];
  134. Dever::db('work/info')->update($update);
  135. }
  136. }
  137. }
  138. public function user_api()
  139. {
  140. $num = Dever::input('num', 1);
  141. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  142. $end = Dever::input('end', date('Y-m-d'));
  143. $start = Dever::maketime($start . ' 00:00:00');
  144. $end = Dever::maketime($end . ' 23:59:59');
  145. $day = intval(($end - $start)/86400);
  146. for($i=0; $i<=$day; $i++) {
  147. $where['start'] = $start + 86400*$i;
  148. $where['end'] = $start + 86400*$i + 86399;
  149. $where['priority_id'] = '';
  150. $cate = Dever::db('work/q_cate')->state();
  151. foreach ($cate as $k =>$v) {
  152. $where['cate'] = $v['id'];
  153. unset($where['priority_id']);
  154. $num = Dever::db('work/info')->getNum($where);
  155. if ($num <= 0) {
  156. continue;
  157. }
  158. $data = array();
  159. $data['cate'] = $where['cate'];
  160. $data['day'] = $where['start'];
  161. $info = Dever::db('work/info_stat')->find($data);
  162. $data['question'] = $num;
  163. $where['priority_id'] = 4;
  164. $data['super'] = Dever::db('work/info')->getNum($where);
  165. $where['priority_id'] = 3;
  166. $data['urgent'] = Dever::db('work/info')->getNum($where);
  167. $where['priority_id'] = 2;
  168. $data['yb'] = Dever::db('work/info')->getNum($where);
  169. $where['priority_id'] = 1;
  170. $data['pt'] = Dever::db('work/info')->getNum($where);
  171. // echo dever::sql();
  172. // print_r($data);
  173. if (!$info) {
  174. Dever::db('work/info_stat')->insert($data);
  175. } else {
  176. $data['where_id'] = $info['id'];
  177. Dever::db('work/info_stat')->update($data);
  178. }
  179. }
  180. }
  181. return 'ok';
  182. }
  183. #修改info表中的问题分类
  184. public function updateCate_api()
  185. {
  186. $data = Dever::db('work/info')->state();
  187. foreach ($data as $k => $v) {
  188. if (!$v['cate'] || $v['cate']<=0) {
  189. if ($v['cate_id']) {
  190. $cate_id = explode(',',$v['cate_id']);
  191. $where['where_id'] = $v['id'];
  192. $where['cate'] = $cate_id[0];
  193. Dever::db('work/info')->update($where);
  194. }
  195. }
  196. }
  197. }
  198. }