You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1016 B
46 lines
1016 B
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use app\admin\model\Navigation;
|
|
|
|
/**
|
|
* 首页接口
|
|
*/
|
|
class Newsletter extends Api
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
protected $newsletter = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->newsletter = new \app\admin\model\Newsletter;
|
|
}
|
|
|
|
/**
|
|
* subscribed
|
|
*
|
|
*/
|
|
public function subscribed()
|
|
{
|
|
$email = (string)$this->request->request('email');
|
|
if(!$email){
|
|
$this->error('Parameter error');
|
|
}
|
|
|
|
$reg = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/";
|
|
if(!preg_match_all($reg, $email, $matches)){
|
|
$this->error('Email error');
|
|
}
|
|
|
|
if($this->newsletter->insert(['email'=>$email,'createtime'=>time()])){
|
|
$this->success('Request succeeded');
|
|
}else{
|
|
$this->error('Request fail');
|
|
}
|
|
}
|
|
}
|