1
This commit is contained in:
@@ -98,11 +98,125 @@ class Promotion extends Base
|
||||
|
||||
}
|
||||
|
||||
/**获取官网文章列表
|
||||
* @return void
|
||||
*/
|
||||
public function getWebArticles(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**获取邮件模版列表
|
||||
* @return void
|
||||
*/
|
||||
public function getEmailModel(){
|
||||
$list = $this->promotion_email_obj->where('state',0)->select();
|
||||
$re['list'] = $list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**添加推广任务主体
|
||||
* @return void
|
||||
*/
|
||||
public function addPromotion(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'user_id'=>"require",
|
||||
'journal_id'=>"require",
|
||||
"library"=>"require",
|
||||
"category"=>"require",
|
||||
"pagesize"=>"require",
|
||||
"email_title"=>"require",
|
||||
"template"=>"require",
|
||||
"has_hb"=>"require",
|
||||
"frequency"=>"require"
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$insert['user_id'] = $data['user_id'];
|
||||
$insert['journal_id'] = $data['journal_id'];
|
||||
$insert['library'] = $data['library'];
|
||||
$insert['category'] = $data['category'];
|
||||
if($data['category']=="major"){
|
||||
$insert['major'] = $data['major'];
|
||||
}else{
|
||||
$insert['keyword'] = trim($data['keyword']);
|
||||
}
|
||||
$insert['pagesize'] = $data['pagesize'];
|
||||
$insert['email_title'] = $data['email_title'];
|
||||
$insert['template']=$data['template'];
|
||||
$insert['has_hb'] = $data['has_hb'];
|
||||
$insert['frequency'] = $data['frequency'];
|
||||
$insert['ctime'] = time();
|
||||
$this->promotion_obj->insert($insert);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**执行推广任务主方法
|
||||
* @return void
|
||||
*/
|
||||
public function autoPushPromotion(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
"pro_id"=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$pro_info = $this->promotion_obj->where('pro_id',$data['pro_id'])->find();
|
||||
$journal_info = $this->journal_obj->where('journal_id',$pro_info['journal_id'])->find();
|
||||
if(!$pro_info||$pro_info['is_end']==1){
|
||||
return jsonError('ended');
|
||||
}
|
||||
$push_arr = json_decode($pro_info['pushed']);
|
||||
$pageIndex = $pro_info['pushed']==""?1:end($push_arr)+1;
|
||||
//选择人员
|
||||
$list = $this->getLibraryList($pro_info['library'],$pro_info['category'],$pro_info['category']=="major"?$pro_info['major']:$pro_info['keyword'],$pageIndex,$pro_info['pagesize']);
|
||||
// $l['email'] = "751475802@qq.com";
|
||||
// $l['name'] = "wangjinlei";
|
||||
// $l['type'] = "ash";
|
||||
// $l['id'] = 35;
|
||||
// $list[] = $l;
|
||||
//组合模版
|
||||
$template = $pro_info['template'];
|
||||
$template = str_replace("{{journal_title}}",$journal_info['title'],$template);
|
||||
$template = str_replace("{{journal_abbr}}",$journal_info['abbr'],$template);
|
||||
$template = str_replace("{{journal_email}}",$journal_info['email'],$template);
|
||||
$template = str_replace("{{journal_jabbr}}",$journal_info['jabbr'],$template);
|
||||
$template = str_replace("{{journal_issn}}",$journal_info['issn'],$template);
|
||||
//发送邮件
|
||||
foreach ($list as $v){
|
||||
$template = str_replace("{{user_name}}",$v['name'],$template);
|
||||
$template = str_replace("{{unsubscribe}}","http://journalapi.tmrjournals.com/public/index.php/api/Promotion/NoEmail?lib=".$v['type']."&id=".$v['id'],$template);
|
||||
$ali['email'] = $v['email'];
|
||||
$ali['title'] = $pro_info['email_title'];
|
||||
$ali['content'] = $template;
|
||||
$ali['has_hb'] = $pro_info['has_hb'];
|
||||
// aliemail($v['email'],$pro_info['email_title'],$template,$pro_info['has_hb']);
|
||||
Queue::push('app\api\job\mail@promotion',$ali,'mail');
|
||||
}
|
||||
|
||||
//更改各种状态
|
||||
//如果后续没有待发数据,要关闭此推广项目
|
||||
$check_next = $this->getLibraryList($pro_info['library'],$pro_info['category'],$pro_info['category']=="major"?$pro_info['major']:$pro_info['keyword'],$pageIndex+1,$pro_info['pagesize']);
|
||||
if(count($check_next)==0){
|
||||
$this->promotion_obj->where('pro_id',$data['pro_id'])->update(['is_end'=>1]);
|
||||
}
|
||||
//发送过的数据加一页
|
||||
$push_arr[] = $pageIndex;
|
||||
$this->promotion_obj->where('pro_id',$data['pro_id'])->update(["pushed"=>json_encode($push_arr)]);
|
||||
|
||||
$re['msg'] = "push email :".count($list);
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user