1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\commands;
- use yii\console\Controller;
- use app\modules\doc\models\DocReal;
- use app\modules\doc\models\DocRealData;
- use app\modules\doc\models\DocMail;
- use app\common\components\Emailer;
- use Yii;
- class MailerController extends Controller
- {
- public $logFile;
- public function init()
- {
- parent::init();
- $this->logFile = Yii::getAlias('@runtime').DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.'mailer_'.date("Ymd").'.log';
- }
- public function actionIndex()
- {
- $task = DocMail::find()->where("status=0")->orderBy(['id'=>SORT_ASC])->one();
- if(empty($task))return;
- $doc = DocReal::findOne($task->doc_id);
- $docData = DocRealData::findOne($task->doc_id);
- //处理文件
- $docConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='doc'")->queryOne();
- $docConfig = string2array($docConfigResult['value']);
- $file = sys_auth($docData->file,'DECODE',$docData->hash);
- if($doc->doc_type==1)
- {
- $tempFile = locateFile(getFileUrl($file),'download');
- $file = initBigfileTorent($tempFile,$doc,$docConfig);
- $bigFileTip = '【下载说明】';
- }
- else if($doc->doc_type==3)//网盘资源
- {
- $file = initPanfile($doc,$docConfig);
- $bigFileTip = '【提取说明】';
- }
- else if($doc->doc_type==2)//合辑文档
- {
- $allsize = 0;
- $docIds = Yii::$app->db->createCommand("SELECT doc_id FROM {{%doc_col}} where col_id=".$doc->id)->queryColumn();
- $resultList = DocReal::findAll($docIds);
- foreach($resultList as $result)
- {
- $allsize += $result->filesize;
- $contentList[] = array('title'=>$result->title,'ext'=>$result->ext,'file'=>sys_auth($result->data->file,'DECODE',$result->data->hash));
- }
- $tempFile = locateColFile($doc,$contentList);
- $file = initBigfileTorent($tempFile,$doc,$docConfig);
- $bigFileTip = '【下载说明】';
- }
- $msg = https_request($file);
- $mailer = new Emailer();
- if($mailer->send('download',$task->email,['title'=>$doc->title,'msg'=>$msg]))
- {
- $task->status = 1;
- $task->send_time = time();
- $task->save();
- $this->_saveLog($task->email,$doc);
- }
- }
- //写日志
- private function _saveLog($email,$doc)
- {
- file_put_contents($this->logFile,$email."(".$doc->title."-".get_date(time(),'Y-m-d H:i:s').")\r\n",FILE_APPEND);
- }
- }
|