12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace Community\Lib;
- use Dever;
- class Core
- {
- # 获取当前用户是否点赞
- public function get($uid, $id, $type)
- {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['type_id'] = $id;
- $where['state'] = 1;
- $info = Dever::db($this->table)->one($where);
- if ($info) {
- return true;
- } else {
- return false;
- }
- }
- # 获取当前用户的数据列表
- public function getList($uid)
- {
- $where['uid'] = $uid;
- $info = Dever::db($this->table)->getAll($where);
- return $info;
- }
- # 更新提交数据
- public function submit($uid, $id, $type, $data = array())
- {
- if ($this->otable) {
- $oinfo = Dever::load($this->otable)->get($uid, $id, $type);
- if ($oinfo) {
- Dever::alert('已经做过其他操作');
- }
- }
- $where['uid'] = $uid;
- $where['type_id'] = $id;
- $where['type'] = $type;
- $info = Dever::db($this->table)->one($where);
- if ($data) {
- $where += $data;
- }
- 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));
- }
- }
- # 更新点赞数
- $where = array();
- $where['type_id'] = $id;
- $where['type'] = $type;
- $where['state'] = 1;
- $total = Dever::db($this->table)->total($where);
- $table = Dever::config('base')->table_name[$type];
- $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
- Dever::score($uid, 'submit_' . $this->name, $this->lang);
- return true;
- }
- }
|