sns_comment.model.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * 好友动态
  4. *
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class sns_commentModel{
  8. /**
  9. * 新增评论
  10. *
  11. * @param $param 添加信息数组
  12. * @return 返回结果
  13. */
  14. public function commentAdd($param){
  15. if (empty($param)){
  16. return false;
  17. }
  18. if (is_array($param)){
  19. $result = Db::insert('sns_comment',$param);
  20. return $result;
  21. }else {
  22. return false;
  23. }
  24. }
  25. /**
  26. * 评论记录列表
  27. *
  28. * @param $condition 条件
  29. * @param $page 分页
  30. * @param $field 查询字段
  31. * @return array 数组格式的返回结果
  32. */
  33. public function getCommentList($condition,$page='',$field='*'){
  34. $condition_str = $this->getCondition($condition);
  35. $param = array();
  36. $param['table'] = 'sns_comment';
  37. $param['where'] = $condition_str;
  38. $param['field'] = $field;
  39. $param['order'] = $condition['order'] ? $condition['order'] : 'sns_comment.comment_id desc';
  40. $param['limit'] = $condition['limit'];
  41. $param['group'] = $condition['group'];
  42. return Db::select($param,$page);
  43. }
  44. /**
  45. * 评论总数
  46. *
  47. * @param $condition 条件
  48. * @param $field 查询字段
  49. * @return array 数组格式的返回结果
  50. */
  51. public function getCommentCount($condition){
  52. $condition_str = $this->getCondition($condition);
  53. return Db::getCount("sns_comment",$condition_str);
  54. }
  55. /**
  56. * 获取评论详细
  57. *
  58. * @param $condition 查询条件
  59. * @param $field 查询字段
  60. */
  61. public function getCommentRow($condition,$field='*'){
  62. $param = array();
  63. $param['table'] = 'sns_comment';
  64. $param['field'] = array_keys($condition);
  65. $param['value'] = array_values($condition);
  66. return Db::getRow($param,$field);
  67. }
  68. /**
  69. * 删除评论
  70. */
  71. public function delComment($condition){
  72. if (empty($condition)){
  73. return false;
  74. }
  75. $condition_str = '';
  76. if ($condition['comment_id'] != ''){
  77. $condition_str .= " and comment_id='{$condition['comment_id']}' ";
  78. }
  79. if($condition['comment_id_in'] != '') {
  80. $condition_str .= " and comment_id in('{$condition['comment_id_in']}')";
  81. }
  82. if ($condition['comment_originalid_in'] !=''){
  83. $condition_str .= " and comment_originalid in('{$condition['comment_originalid_in']}') ";
  84. }
  85. if ($condition['comment_originalid'] != ''){
  86. $condition_str .= " and comment_originalid='{$condition['comment_originalid']}' ";
  87. }
  88. if ($condition['comment_originaltype'] != ''){
  89. $condition_str .= " and comment_originaltype = '{$condition['comment_originaltype']}' ";
  90. }
  91. return Db::delete('sns_comment',$condition_str);
  92. }
  93. /**
  94. * 更新评论记录
  95. * @param array $param 修改信息数组
  96. * @param array $condition 条件数组
  97. */
  98. public function commentEdit($param,$condition){
  99. if(empty($param)) {
  100. return false;
  101. }
  102. //得到条件语句
  103. $condition_str = $this->getCondition($condition);
  104. $result = Db::update('sns_comment',$param,$condition_str);
  105. return $result;
  106. }
  107. /**
  108. * 将条件数组组合为SQL语句的条件部分
  109. *
  110. * @param array $condition_array
  111. * @return string
  112. */
  113. private function getCondition($condition_array){
  114. $condition_sql = '';
  115. //ID in
  116. if($condition_array['comment_id_in'] != '') {
  117. $condition_sql .= " and sns_comment.comment_id in('{$condition_array['comment_id_in']}')";
  118. }
  119. //原帖ID
  120. if($condition_array['comment_originalid'] != '') {
  121. $condition_sql .= " and sns_comment.comment_originalid = '{$condition_array['comment_originalid']}'";
  122. }
  123. //原帖类型
  124. if($condition_array['comment_originaltype'] != '') {
  125. $condition_sql .= " and sns_comment.comment_originaltype = '{$condition_array['comment_originaltype']}'";
  126. }
  127. //会员名like
  128. if($condition_array['comment_membername_like'] != '') {
  129. $condition_sql .= " and sns_comment.comment_membername like '%{$condition_array['comment_membername_like']}%'";
  130. }
  131. //状态
  132. if($condition_array['comment_state'] != '') {
  133. $condition_sql .= " and sns_comment.comment_state = '{$condition_array['comment_state']}'";
  134. }
  135. //内容
  136. if($condition_array['comment_content_like'] != '') {
  137. $condition_sql .= " and sns_comment.comment_content like '%{$condition_array['comment_content_like']}%'";
  138. }
  139. //添加时间
  140. if ($condition_array['stime'] !=''){
  141. $condition_sql .= " and `sns_comment`.comment_addtime >= {$condition_array['stime']}";
  142. }
  143. if ($condition_array['etime'] !=''){
  144. $condition_sql .= " and `sns_comment`.comment_addtime <= {$condition_array['etime']}";
  145. }
  146. return $condition_sql;
  147. }
  148. }