123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Like
- {
- private $table = 'act/like';
- # 获取当前用户是否点赞
- public function get($uid, $id, $type)
- {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['state'] = 1;
- $info = Dever::db($this->table)->one($where);
- if ($info) {
- return 1;
- } else {
- return 2;
- }
- }
- # 获取当前用户的点赞列表
- public function getList($uid)
- {
- $where['uid'] = $uid;
- //$where['type'] = '1,2,3,6';
- $info = Dever::db($this->table)->getAll($where);
- return $info;
- }
- # 点赞
- public function submit($uid, $id, $type)
- {
- $where['uid'] = $uid;
- $where['data_id'] = $id;
- $where['type'] = $type;
- $info = Dever::db($this->table)->one($where);
- if (!$info) {
- Dever::db($this->table)->insert($where);
- } else {
- if ($info['state'] == 1) {
- Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 2));
- } else {
- Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 1));
- }
- }
- # 更新点赞数
-
- if (isset(Dever::config('base')->type_table[$type])) {
- $where = array();
- $where['data_id'] = $id;
- $where['type'] = $type;
- $where['state'] = 1;
- $total = Dever::db($this->table)->total($where);
- $table = Dever::config('base')->type_table[$type];
- Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
- Dever::score($uid, 'submit_' . $this->table, $this->name);
- }
- return true;
- }
- }
|