first commit
This commit is contained in:
107
application/common/service/Experience.php
Normal file
107
application/common/service/Experience.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Experience as ExperienceModel;
|
||||
use app\common\model\ExperienceTags as ExperienceTagsModel;
|
||||
use app\common\validate\Experience as ExperienceValidate;
|
||||
|
||||
class Experience extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function tags($uid, $id)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($id);
|
||||
if (!$ExperienceInfo) {
|
||||
return '要评论的信息不存在';
|
||||
} elseif ($ExperienceInfo->status != 1) {
|
||||
return '信息被禁用';
|
||||
}
|
||||
$map = [
|
||||
'experience_id' => $id,
|
||||
'uid' => $uid,
|
||||
];
|
||||
$comment = ExperienceTagsModel::where($map)->find();
|
||||
if ($comment) {
|
||||
return '不能重复点赞';
|
||||
}
|
||||
$data = [
|
||||
'experience_id' => $id,
|
||||
'uid' => $uid,
|
||||
];
|
||||
if (ExperienceTagsModel::create($data)) {
|
||||
$ExperienceInfo->setInc('tags');
|
||||
return true;
|
||||
} else {
|
||||
return '点赞失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发表评论
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function comment($pid, $uid, $content)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($pid);
|
||||
if (!$ExperienceInfo) {
|
||||
return '要评论的信息不存在';
|
||||
} elseif ($ExperienceInfo->status != 1) {
|
||||
return '信息被禁用';
|
||||
}
|
||||
$data = [
|
||||
'pid' => $pid,
|
||||
'uid' => $uid,
|
||||
'content' => $content,
|
||||
];
|
||||
$validate = new ExperienceValidate();
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
if (ExperienceModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '评论失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function add($data, $uid)
|
||||
{
|
||||
$data['uid'] = $uid;
|
||||
$validate = new ExperienceValidate();
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
if (ExperienceModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '发布失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($id, $uid)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($id);
|
||||
if (!$ExperienceInfo) {
|
||||
return '没有这条信息';
|
||||
} else if ($ExperienceInfo->uid != $uid) {
|
||||
return '这个不是您的经验信息,您不能删除。';
|
||||
} else if ($ExperienceInfo->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user