123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Subscribe
- {
- private $key = 'use_sub_';
- # 获取小刊是否被人订阅
- public function get($id, $uid, $type = 4, $cache = false)
- {
- $key = $this->key . $uid . '_' . $id;
- $data = Dever::cache($key);
- if ($data == 1) {
- return 1;
- } else {
- if (!$cache) {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['state'] = 1;
- $data = Dever::db('act/subscribe')->one($where);
- if ($data) {
- Dever::cache($key, 1, 864000);
- return 1;
- } else {
- return 2;
- }
- }
- return 2;
- }
- }
- public function getInfo($id, $uid, $type = 4)
- {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['state'] = 1;
- $data = Dever::db('act/subscribe')->one($where);
- return $data;
- }
-
- # 获取小刊订阅列表
- public function getList($id, $type = 4)
- {
- $key = 'subscribe_' . $type . '_' . $id;
- //$data = Dever::cache($key);
- $data = array();
- if (!$data) {
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['avatar'] = 'null';
- $data = Dever::db('act/subscribe')->getAll($where);
- if ($data) {
- //Dever::cache($key, $data, 900);
- }
- }
-
- /*
- if ($data) {
- foreach ($data as $k => $v) {
- $user = Dever::load('passport/api')->info($v['uid']);
- $data[$k]['username'] = $user['username'];
- $data[$k]['avatar'] = $user['avatar'];
- }
- }
- */
- return $data;
- }
- # 订阅
- public function submit($uid, $id, $source = 1, $type = 4)
- {
- $where['uid'] = $uid;
- $where['data_id'] = $id;
- $where['type'] = $type;
- $table = 'act/subscribe';
- $info = Dever::db($table)->one($where);
- $key = $this->key . $uid . '_' . $id;
- Dever::cache($key, 1, 864000);
- if (!$info) {
- $where['source'] = $source;
- Dever::db($table)->insert($where);
- return true;
- }
- return false;
- # 更新订阅数
- $where = array();
- $where['data_id'] = $id;
- $where['type'] = $type;
- $where['state'] = 1;
- $total = Dever::db($table)->total($where);
- $table = Dever::config('base')->type_table[$type];
- Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
- return false;
- }
- }
|