搜索
系统检测到您的用户名不符合规范:

thinkphp点赞功能和实体设计

浏览:4097 发布日期:2017年12月06日 分类:功能实现 关键字: thinkphp
thinkphp点赞功能实现和实体表设计
新建了一个QQ群,如果想加可以加一下。

实体表设计:
id,category_id,all_ids,user_id,create_time这五个字段,分别是主键,分类ID,点赞ID,用户ID,创建时间。这里的分类ID是用于有多个点赞需求的设计,例如文章,商品,视频等。 /**
* Created by .
* User: 周洪亮
* Date: 2017年3月31日
* Time: 10:30
* 点赞方法
*/
public function add()
{
$uid = $_SESSION['uid'];
$article_id = I('article_id');//文章ID
$initial_quantity = C('THANKED_INITIAL_QUANTITY');//点赞初始数量
$customer_logic=new CustomerLogic();
$result = $customer_logic->addLogic($uid, $article_id);//点赞逻辑方法
if ($result['status'] == -1) {
exit(json_encode($result));
}
if ($result['status'] == -2) {
$data = $result['result'];
$del_where['id'] = $data['id'];
$del = $this->db->where($del_where)->delete();//删除
if ($del) {
$thanked_number = ThankedCount($article_id, 1, $initial_quantity);
exit(json_encode(array('status' => 2, 'msg' => '取消点赞成功', 'thanked_number' => $thanked_number)));
}
}
if ($article_id != null) {
$db_data['all_ids'] = $article_id;
$db_data['category_id'] = 3;
}
$db_data['user_id'] = $uid;
$db_data['create_time'] = date('Y-m-d H:i:s');
$add = $this->db->data($db_data)->add();
if ($add) {
$thanked_number = ThankedCount($article_id, 1, $initial_quantity);
exit(json_encode(array('status' => 1, 'msg' => '点赞成功', 'thanked_number' => $thanked_number)));
} else {
exit(json_encode(array('status' => -404, 'msg' => '您的网络出现故障或我们服务器正在维修')));
}
}

/**
* Created by .
* User: 周宏亮
* Date: 2017年3月30日
* Time: 18:46
* 点赞逻辑方法
* @param $uid 用户唯一标识
* @param $shop_id 店铺唯一ID
* @param $goods_id 商品唯一标识
*/
public function addLogic($uid, $article_id = '')
{
if ($uid == '') {
return array('status' => -1, 'msg' => '登录后在点赞');
}
if ($article_id != null) {
$article_find = ThankedFind($uid, $article_id, 3);//查询方法
if ($article_find != '') {
return array('status' => -2, 'msg' => '已点赞', 'result' => $article_find);
}
}
}

/**
* Created by .
* User: 周宏亮
* Date: 2017年3月31日
* Time: 11:07
* 点赞,查询是否已点赞
*/
function ThankedFind($uid, $all_ids, $category)
{
$where['user_id'] = $uid;
$where['all_ids'] = $all_ids;
$where['category_id'] = $category;//3是文章,1是商品,店铺2
$find = M('Thanked')->where($where)->find();

return $find;
}

function ThankedCount($id, $category, $initial_quantity)
{
$where['all_ids'] = $id;
$where['category_id'] = $category;
$count = M('Thanked')->where($where)->count();
$number = $count + $initial_quantity;

return $number;
}
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
周三省
积分:1190 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /