Act.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. $this->app = Dever::config('setting')['type'][$this->type];
  14. }
  15. protected function check()
  16. {
  17. if (!$this->type || !$this->type_id) {
  18. Dever::error('传入参数错误');
  19. }
  20. }
  21. # 更新互动信息
  22. public function up($data = array(), $msg = '')
  23. {
  24. if ($this->getInfo($data)) {
  25. $msg && Dever::error($msg);
  26. } else {
  27. $this->db->insert($this->data);
  28. }
  29. return 'ok';
  30. }
  31. # 删除
  32. public function del($data = array())
  33. {
  34. if ($info = $this->getInfo($data)) {
  35. $this->db->delete($info['id']);
  36. }
  37. return 'ok';
  38. }
  39. # 获取用户互动相关的信息
  40. public function getInfo($data = array(), $field = array())
  41. {
  42. $this->check();
  43. $this->data = $data;
  44. $this->data['type'] = $this->type;
  45. $this->data['type_id'] = $this->type_id;
  46. $this->data['uid'] = Place::$uid;
  47. return $this->handleInfo($this->db->find($this->data), $field);
  48. }
  49. # 获取详情页
  50. public function getView($field = array())
  51. {
  52. $info = $this->getInfo(array(), $field);
  53. return Dever::load('order', $this->app)->getView($info);
  54. }
  55. # 评论列表
  56. public function getList()
  57. {
  58. $data['type'] = Dever::input('type', 'is_numeric', '类型');
  59. $data['type_id'] = Dever::input('type_id', 'is_numeric', '类型ID');
  60. # 每页10条
  61. $set['num'] = 10;
  62. $data = Dever::db('review', 'place')->select($where, $set);
  63. if ($data) {
  64. foreach ($data as &$v) {
  65. $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
  66. $v['oper'] = 2;
  67. if (Place::$uid == $v['uid']) {
  68. $v['oper'] = 1;
  69. }
  70. $v['user'] = Dever::db('member', 'place')->find($v['uid'], array('col' => 'mobile,name,avatar'));
  71. }
  72. }
  73. return $data;
  74. }
  75. # 获取用户的互动列表
  76. public function getUserList($field = array(), $page = 10)
  77. {
  78. $where['uid'] = Place::$uid;
  79. if ($this->type) {
  80. $where['type'] = $this->type;
  81. }
  82. # 每页10条
  83. $set['num'] = $page;
  84. $data = $this->db->select($where, $set);
  85. $result = array();
  86. if ($data) {
  87. foreach ($data as $k => $v) {
  88. $info = $this->handleInfo($v, $field);
  89. if ($info) {
  90. $result[] = $info;
  91. }
  92. }
  93. }
  94. return $result;
  95. }
  96. private function getTypeInfo($type, $type_id)
  97. {
  98. $app = Dever::config('setting')['type'][$type];
  99. if ($type > 0) {
  100. $db = Dever::db('info', $app);
  101. $info = $db->find($type_id, array('col' => 'id,name,pic,info'));
  102. $info['pic'] = explode(',', $info['pic']);
  103. $info['pic'] = $info['pic'][0] ?? '';
  104. return $info;
  105. }
  106. }
  107. private function handleInfo($v, $field = array())
  108. {
  109. if (!$v) {
  110. return array();
  111. }
  112. $info = $this->getTypeInfo($v['type'], $v['type_id']);
  113. if ($info) {
  114. $info['status_name'] = $this->db->value('status', $v['status']);
  115. $info['type'] = $v['type'];
  116. $info['type_id'] = $v['id'];
  117. //$info['cdate'] = $v['cdate'];
  118. $info['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
  119. if ($field) {
  120. foreach ($field as $v1) {
  121. $info[$v1] = $v[$v1];
  122. }
  123. }
  124. if ($this->db->config['load'] == 'place/order') {
  125. $info['cash'] = Dever::load('price', 'place')->getText($info['cash'], $info['type']);
  126. if ($v['type'] == 3) {
  127. $info['detail'] = Dever::load('order', $this->app)->getDetail($v['id']);
  128. $info['info'] = '共' . intval($info['num']) . '件商品';
  129. } else {
  130. $detail['id'] = $info['id'];
  131. $detail['name'] = $info['name'];
  132. $detail['pic'] = $info['pic'];
  133. $detail['sku_name'] = '';
  134. $detail['sku_id'] = 0;
  135. $detail['cash'] = $info['cash'];
  136. $detail['num'] = $info['num'];
  137. $info['detail'][] = $detail;
  138. $info['info'] = '';
  139. }
  140. }
  141. return $info;
  142. }
  143. }
  144. }