123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php namespace Place\Lib;
- use Dever;
- use Place;
- class Act
- {
- private $db;
- private $type;
- public function __construct($name)
- {
- $this->type = Dever::input('type');
- $this->type_id = Dever::input('type_id');
- $this->db = Dever::db($name, 'place');
- }
- protected function check()
- {
- if (!$this->type || !$this->type_id) {
- Dever::error('传入参数错误');
- }
- }
- # 更新互动信息
- public function up($data = array(), $msg = '')
- {
- if ($this->getInfo($data)) {
- $msg && Dever::error($msg);
- } else {
- $this->db->insert($this->data);
- }
- return 'ok';
- }
- # 删除
- public function del($data = array())
- {
- if ($info = $this->getInfo($data)) {
- $this->db->delete($info['id']);
- }
- return 'ok';
- }
- # 获取用户互动相关的信息
- public function getInfo($data = array())
- {
- $this->check();
- $this->data = $data;
- $this->data['type'] = $this->type;
- $this->data['type_id'] = $this->type_id;
- $this->data['uid'] = Place::$uid;
- return $this->db->find($this->data);
- }
- # 评论列表
- public function getList()
- {
- $data['type'] = Dever::input('type', 'is_numeric', '类型');
- $data['type_id'] = Dever::input('type_id', 'is_numeric', '类型ID');
- # 每页10条
- $set['num'] = 10;
- $data = Dever::db('review', 'place')->select($where, $set);
- if ($data) {
- foreach ($data as &$v) {
- $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
- $v['oper'] = 2;
- if (Place::$uid == $v['uid']) {
- $v['oper'] = 1;
- }
- $v['user'] = Dever::db('member', 'place')->find($v['uid'], array('col' => 'mobile,name,avatar'));
- }
- }
- return $data;
- }
- # 获取用户的互动列表
- public function getUserList($field = array(), $page = 10)
- {
- $where['uid'] = Place::$uid;
- if ($this->type) {
- $where['type'] = $this->type;
- }
- # 每页10条
- $set['num'] = $page;
- $data = $this->db->select($where, $set);
- $result = array();
- if ($data) {
- foreach ($data as $k => $v) {
- $info = $this->getTypeInfo($v['type'], $v['type_id']);
- if ($info) {
- $info['data_id'] = $v['id'];
- $info['cdate'] = $v['cdate'];
- $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
- if ($field) {
- foreach ($field as $v1) {
- $info[$v1] = $v[$v1];
- }
- }
- if ($v['type'] == 3) {
- $info['detail'] = Dever::load('order', 'goods')->getDetail($v['id']);
- }
- $result[] = $info;
- }
- }
- }
- return $result;
- }
- private function getTypeInfo($type, $type_id)
- {
- $app = Dever::config('setting')['type'][$type];
- if ($type > 0) {
- $db = Dever::db('info', $app);
- $info = $db->find($type_id, array('col' => 'id,name,pic,info'));
- $info['pic'] = explode(',', $info['pic']);
- $info['pic'] = $info['pic'][0] ?? '';
- return $info;
- }
- }
- }
|