GetKennelDetailWorkCommand.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: PHP
  5. * Date: 2016/11/23
  6. * Time: 9:11
  7. */
  8. class GetKennelDetailWorkCommand extends CConsoleCommand {
  9. public function run($args){
  10. //error_reporting(E_ERROR);
  11. ini_set('memory_limit', '256M');
  12. //ini_set('mongo.long_as_object',1);
  13. set_time_limit(0);
  14. self::getKennel();
  15. }
  16. public function getKennel()
  17. {
  18. $end_time = date("Y-m-d 13:59:59");
  19. $start_time = date("Y-m-d 14:00:00",strtotime("-1 day"));
  20. $criteria = new EMongoCriteria();
  21. $criteria->addCond('time','>=',strtotime(date('Y-m-d H:i:s',strtotime($start_time))));
  22. $criteria->addCond('time','<=',strtotime(date('Y-m-d H:i:s',strtotime($end_time))));
  23. $cursor = JRecord::model()->findAll($criteria);
  24. $rows = CommonFn::getRowsFromCursor($cursor);
  25. $parsedRows = JRecord::model()->parse($rows);
  26. $data = [];
  27. foreach ($parsedRows as &$row) {
  28. if ($row['type'] == 0) {
  29. $data[] = $row;
  30. }
  31. }
  32. if (count($data) == 0) {
  33. exit;
  34. }
  35. $type_name = 'food';
  36. $res=Service::factory('JRecordService')->push($data,$type_name,['start' => $start_time, 'end' => $end_time],1);
  37. $mail = Yii::app()->mailer;
  38. try {
  39. $mail->SMTPDebug = 2; // Enable verbose debug output
  40. $mail->isSMTP(); // Set mailer to use SMTP
  41. $mail->Host = 'smtp.163.com'; // Specify main and backup SMTP servers
  42. $mail->SMTPAuth = true; // Enable SMTP authentication
  43. $mail->Username = 'insur_zhq1@163.com'; // SMTP username
  44. $mail->Password = 'JgCoupon365'; // SMTP password
  45. $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
  46. $mail->Port = 587; // TCP port to connect to
  47. $mail->setFrom('insur_zhq1@163.com', 'JinGuo365');
  48. $mail->AddAddress('sh.zhq@163.com');
  49. $mail->AddAddress('511276154@qq.com');
  50. $mail->AddAddress('1340652578@qq.com');
  51. $mail->addAttachment(Yii::app()->basePath.'/export/'.$res); // Add attachments
  52. $mail->isHTML(true); // Set email format to HTML
  53. $mail->Subject = 'Pick up record'.date('Y-m-d');
  54. $mail->Body = $res;
  55. $mail->AltBody = $res;
  56. $mail->send();
  57. echo 'Message has been sent';
  58. } catch (Exception $e) {
  59. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  60. }
  61. }
  62. }