12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Subscribe
- {
- # 获取小刊订阅列表
- public function get($id, $type = 4)
- {
- $where['type'] = $type;
- $where['data_id'] = $id;
- $data = Dever::db('act/subscribe')->getAll($where);
- 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, $type = 4)
- {
- $where['uid'] = $uid;
- $where['data_id'] = $id;
- $where['type'] = $type;
- $table = 'act/subscribe';
- $info = Dever::db($table)->one($where);
- if (!$info) {
- Dever::db($table)->insert($where);
- }
- # 更新订阅数
- $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 true;
- }
- }
|