Cron.php 8.4 KB

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