GetKennelDetailWorkCommand.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 14:00:00");
  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. foreach ($cursor as $item) {
  27. $item->status = 2;
  28. $item->save();
  29. }
  30. $type_name = '全部';
  31. $res=Service::factory('JRecordService')->push($parsedRows,$type_name,['start' => $start_time, 'end' => $end_time],1);
  32. $mail = Yii::app()->mailer;
  33. try {
  34. $mail->SMTPDebug = 2; // Enable verbose debug output
  35. $mail->isSMTP(); // Set mailer to use SMTP
  36. $mail->Host = 'smtp.qq.com'; // Specify main and backup SMTP servers
  37. $mail->SMTPAuth = true; // Enable SMTP authentication
  38. $mail->Username = '1340652578@qq.com'; // SMTP username
  39. $mail->Password = 'iaycligvfccmjdcf'; // SMTP password
  40. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  41. $mail->Port = 587; // TCP port to connect to
  42. $mail->setFrom('1340652578@qq.com', 'Mailer');
  43. $mail->AddAddress('1340652578@qq.com');
  44. $mail->addAttachment(Yii::app()->basePath.'/export/'.$res); // Add attachments
  45. $mail->isHTML(true); // Set email format to HTML
  46. $mail->Subject = '提货记录';
  47. $mail->Body = $res;
  48. $mail->AltBody = $res;
  49. $mail->send();
  50. echo 'Message has been sent';
  51. } catch (Exception $e) {
  52. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  53. }
  54. }
  55. }