Act.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php namespace Place\Lib;
  2. use Dever;
  3. use Place;
  4. class Act
  5. {
  6. private $db;
  7. private $type;
  8. public function __construct($name)
  9. {
  10. $this->type = Dever::input('type');
  11. $this->type_id = Dever::input('type_id');
  12. $this->db = Dever::db($name, 'place');
  13. }
  14. protected function check()
  15. {
  16. if (!$this->type || !$this->type_id) {
  17. Dever::error('传入参数错误');
  18. }
  19. }
  20. # 更新互动信息
  21. public function up($data = array(), $msg = '')
  22. {
  23. if ($this->getInfo($data)) {
  24. $msg && Dever::error($msg);
  25. } else {
  26. $this->db->insert($this->data);
  27. }
  28. return 'ok';
  29. }
  30. # 删除
  31. public function del($data = array())
  32. {
  33. if ($info = $this->getInfo($data)) {
  34. $this->db->delete($info['id']);
  35. }
  36. return 'ok';
  37. }
  38. # 获取用户互动相关的信息
  39. public function getInfo($data = array())
  40. {
  41. $this->check();
  42. $this->data = $data;
  43. $this->data['type'] = $this->type;
  44. $this->data['type_id'] = $this->type_id;
  45. $this->data['uid'] = Place::$uid;
  46. return $this->db->find($this->data);
  47. }
  48. # 评论列表
  49. public function getList()
  50. {
  51. $data['type'] = Dever::input('type', 'is_numeric', '类型');
  52. $data['type_id'] = Dever::input('type_id', 'is_numeric', '类型ID');
  53. # 每页10条
  54. $set['num'] = 10;
  55. $data = Dever::db('review', 'place')->select($where, $set);
  56. if ($data) {
  57. foreach ($data as &$v) {
  58. $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
  59. $v['oper'] = 2;
  60. if (Place::$uid == $v['uid']) {
  61. $v['oper'] = 1;
  62. }
  63. $v['user'] = Dever::db('member', 'place')->find($v['uid'], array('col' => 'mobile,name,avatar'));
  64. }
  65. }
  66. return $data;
  67. }
  68. # 获取用户的互动列表
  69. public function getUserList($field = array(), $page = 10)
  70. {
  71. $where['uid'] = Place::$uid;
  72. if ($this->type) {
  73. $where['type'] = $this->type;
  74. }
  75. # 每页10条
  76. $set['num'] = $page;
  77. $data = $this->db->select($where, $set);
  78. $result = array();
  79. if ($data) {
  80. foreach ($data as $k => $v) {
  81. $info = $this->getTypeInfo($v['type'], $v['type_id']);
  82. if ($info) {
  83. $info['data_id'] = $v['id'];
  84. $info['cdate'] = $v['cdate'];
  85. $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
  86. if ($field) {
  87. foreach ($field as $v1) {
  88. $info[$v1] = $v[$v1];
  89. }
  90. }
  91. if ($v['type'] == 3) {
  92. $info['detail'] = Dever::load('order', 'goods')->getDetail($v['id']);
  93. }
  94. $result[] = $info;
  95. }
  96. }
  97. }
  98. return $result;
  99. }
  100. private function getTypeInfo($type, $type_id)
  101. {
  102. $app = Dever::config('setting')['type'][$type];
  103. if ($type > 0) {
  104. $db = Dever::db('info', $app);
  105. $info = $db->find($type_id, array('col' => 'id,name,pic,info'));
  106. $info['pic'] = explode(',', $info['pic']);
  107. $info['pic'] = $info['pic'][0] ?? '';
  108. return $info;
  109. }
  110. }
  111. }