评论架构设计图
评论系统如下图所示,具有登录系统,注册系统,站点管理,贴子管理,游客系统,评论管理,评论发表,评论删除,评论回复,评论点赞等等。这是一个简单的模型,作为三方评论系统的基本结构。
注册系统
用户数据表在上一篇已经介绍过了,这里不再重复介绍。注册使用的基本信息为用户名,密码,邮箱。与其他数据表关联时,不使用自增id,而是生成唯一id,这样在数据库迁移时也可以把数据很好的对应上,同样的对每一条评论数据,也要单独生成uuid。另外,为方便用户,我们提供了游客账号,稍后讲解。相关代码如下:
public function doRegisterComment()
{
$user_validate = new \app\index\validate\CommentUser;
if(!$user_validate->check($this->request->param('', null, 'urldecode'))){
dump($user_validate->getError());
}
$jsoncallback = $this->get('jsoncallback');
$account = $this->get('account');
$newPwd = $this->get('newPwd');
$confirmPwd = $this->get('confirmPwd');
$email = $this->get('email');
$securityCode = $this->get('securityCode');
$admin = $this->get('admin1234');
if(Db::name('user')->where('account', $account)->find()){
return $this->create_res([
"info"=>"用户名[$account]已存在"
]);
}
$uniqid = uniqid();
//create user, usertype:0 normal member, 1 admin, 2 guest
$id = Db::name('user')->insertGetId([
'uuid'=>$uniqid,
'user_type' => $admin ? 1 : 0,
'account'=>$account,
'password'=>md5($confirmPwd),
'email'=>$email,
'regtime'=>time(),
'lastlogintime'=>time(),
'islogin'=>1,
'head'=>''
]);
//注册成功后
$second = md5($email);
$third = md5(time());
cookie('cookieUserLoginEntityInfos', $uniqid.'_'.$second.'_'.$third);
$user_data = [
'id'=>$id,
'uuid'=>$uniqid,
'account'=>$account,
'password'=>md5($confirmPwd),
'email'=>$email,
'user_type'=>$admin ? 1 : 0,
'head'=>'',
'lastlogintime'=>time()