comment.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * 微商城评论
  4. *
  5. *
  6. *
  7. */
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class commentControl extends MircroShopControl{
  10. public function __construct() {
  11. parent::__construct();
  12. }
  13. /**
  14. * 评论保存
  15. **/
  16. public function comment_saveOp() {
  17. $data = array();
  18. $data['result'] = 'true';
  19. $comment_id = intval($_POST['comment_id']);
  20. $comment_type = self::get_channel_type($_GET['type']);
  21. if($comment_id <= 0 || empty($comment_type) || empty($_POST['comment_message']) || mb_strlen($_POST['comment_message']) > 140) {
  22. $data['result'] = 'false';
  23. $data['message'] = Language::get('wrong_argument');
  24. self::echo_json($data);
  25. }
  26. if(!empty($_SESSION['member_id'])) {
  27. $param = array();
  28. $param['comment_type'] = $comment_type['type_id'];
  29. $param["comment_object_id"] = $comment_id;
  30. if (strtoupper(CHARSET) == 'GBK'){
  31. $param['comment_message'] = Language::getGBK(trim($_POST['comment_message']));
  32. } else {
  33. $param['comment_message'] = trim($_POST['comment_message']);
  34. }
  35. $param['comment_member_id'] = $_SESSION['member_id'];
  36. $param['comment_time'] = time();
  37. $model_comment = Model('micro_comment');
  38. $result = $model_comment->save($param);
  39. if($result) {
  40. //评论计数加1
  41. $model = Model("micro_{$_GET['type']}");
  42. $update = array();
  43. $update['comment_count'] = array('exp','comment_count+1');
  44. $condition = array();
  45. $condition[$comment_type['type_key']] = $comment_id;
  46. $model->table("micro_{$_GET['type']}")->where($condition)->update($update);
  47. //返回信息
  48. $data['result'] = 'true';
  49. $data['message'] = Language::get('nc_common_save_succ');
  50. $data['member_name'] = $_SESSION['member_name'].Language::get('nc_colon');
  51. $data['member_avatar'] = getMemberAvatar($_SESSION['member_avatar']);
  52. $data['member_link'] = MICROSHOP_SITE_URL.'/index.php?act=home&member_id='.$_SESSION['member_id'];
  53. $data['comment_message'] = parsesmiles(stripslashes($param['comment_message']));
  54. $data['comment_time'] = date('Y-m-d H:i:s',$param['comment_time']);
  55. $data['comment_id'] = $result;
  56. //分享内容
  57. if(isset($_POST['share_app_items'])) {
  58. $condition = array();
  59. $condition[$comment_type['type_key']] = $_POST['comment_id'];
  60. if($_GET['type'] == 'store') {
  61. $info = $model->getOneWithStoreInfo($condition);
  62. } else {
  63. $info = $model->getOne($condition);
  64. }
  65. $info['commend_message'] = $param['comment_message'];
  66. $info['type'] = $_GET['type'];
  67. $info['url'] = MICROSHOP_SITE_URL.DS."index.php?act={$_GET['type']}&op=detail&{$_GET['type']}_id=".$_POST['comment_id'].'#widgetcommenttitle';
  68. self::share_app_publish('comment',$info);
  69. }
  70. } else {
  71. $data['result'] = 'false';
  72. $data['message'] = Language::get('nc_common_save_fail');
  73. }
  74. } else {
  75. $data['result'] = 'false';
  76. $data['message'] = Language::get('no_login');
  77. }
  78. self::echo_json($data);
  79. }
  80. /**
  81. * 评论列表
  82. **/
  83. public function comment_listOp() {
  84. $comment_id = intval($_GET['comment_id']);
  85. if($comment_id > 0) {
  86. $condition = array();
  87. $condition["comment_object_id"] = $comment_id;
  88. $comment_type = self::get_channel_type($_GET['type']);
  89. if(!empty($comment_type)) {
  90. $condition["comment_type"] = $comment_type['type_id'];
  91. $model_comment = Model("micro_comment");
  92. $comment_list = $model_comment->getListWithUserInfo($condition,5,'comment_time desc');
  93. Tpl::output('list',$comment_list);
  94. Tpl::output('show_page',$model_comment->showpage(2));
  95. }
  96. }
  97. Tpl::showpage('widget_comment_list','null_layout');
  98. }
  99. /**
  100. * 评论删除
  101. **/
  102. public function comment_dropOp() {
  103. $data['result'] = 'false';
  104. $data['message'] = Language::get('nc_common_del_fail');
  105. $comment_id = intval($_GET['comment_id']);
  106. if($comment_id > 0) {
  107. $model_comment = Model('micro_comment');
  108. $comment_info = $model_comment->getOne(array('comment_id'=>$comment_id));
  109. if($comment_info['comment_member_id'] == $_SESSION['member_id']) {
  110. $result = $model_comment->drop(array('comment_id'=>$comment_id));
  111. if($result) {
  112. //评论计数减1
  113. $comment_type = self::get_channel_type($_GET['type']);
  114. if(!empty($comment_type)) {
  115. $model = Model();
  116. $update = array();
  117. $update['comment_count'] = array('exp','comment_count-1');
  118. $condition = array();
  119. $condition[$comment_type['type_key']] = $comment_info['comment_object_id'];
  120. $model->table("micro_{$_GET['type']}")->where($condition)->update($update);
  121. }
  122. $data['result'] = 'true';
  123. $data['message'] = Language::get('nc_common_del_succ');
  124. }
  125. }
  126. }
  127. self::echo_json($data);
  128. }
  129. }