member_ugc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/7/5
  6. * Time: 下午4:02
  7. */
  8. require_once(BASE_ROOT_PATH . '/mobile/control/special.php');
  9. require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
  11. require_once(BASE_ROOT_PATH . '/helper/text_filter.php');
  12. class member_ugcControl extends specialControl
  13. {
  14. const greater = 0;
  15. const lesser = 1;
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. }
  20. public function pub_listOp()
  21. {
  22. return $this->fetch('pub_list');
  23. }
  24. public function pri_listOp()
  25. {
  26. $this->need_login();
  27. return $this->fetch('pri_list');
  28. }
  29. public function mine_listOp()
  30. {
  31. $this->need_login();
  32. return $this->fetch('mine_list');
  33. }
  34. private function fetch($type)
  35. {
  36. $special_id = intval($_GET['special_id']);
  37. $count = $this->page_size();
  38. if(empty($special_id) || $special_id == -1) {
  39. $special_id = -1;
  40. $direct = self::lesser;
  41. }
  42. else {
  43. $direct = $this->direct();
  44. }
  45. if($type == "pub_list") {
  46. $result = search\relation_client::instance()->fetch_pub_special(['special_id' => $special_id,'count'=> $count,'type' => $direct]);
  47. }
  48. elseif($type == 'pri_list') {
  49. $result = search\relation_client::instance()->fetch_pri_special(['user_id' => intval($_SESSION['member_id']),
  50. 'special_id' => $special_id,'count'=> $count,'type' => $direct]);
  51. }
  52. elseif($type == "mine_list") {
  53. $result = search\relation_client::instance()->fetch_self_special(['user_id' => intval($_SESSION['member_id']),
  54. 'special_id' => $special_id,'count'=> $count,'type' => $direct]);
  55. }
  56. else {
  57. return self::outerr(errcode::ErrParamter);
  58. }
  59. $specials = $this->specials($result);
  60. if($specials == false)
  61. {
  62. $page_no = $this->page_no();
  63. if($page_no == 1) $page_no = 0;
  64. return self::outsuccess(array('special_list' => null,'mobile_page' => mobile_page($page_no)));
  65. }
  66. else
  67. {
  68. $special_list = $this->special_list($specials,$ugcs);
  69. $page_no = $this->page_no();
  70. if($this->page_size() <= count($specials)) {
  71. $page_no += 1;
  72. }
  73. return self::outsuccess(['special_list' => $special_list,
  74. 'ugcs' => $ugcs,
  75. 'summary' => null,
  76. 'groupbuy' => null,
  77. 'limitime' => null,
  78. 'bundling' => null,
  79. 'mobile_page' => mobile_page($page_no)]);
  80. }
  81. }
  82. private function direct()
  83. {
  84. $cur_page = $this->page_no();
  85. if($cur_page == 1) {
  86. return self::greater;
  87. } else {
  88. return self::lesser;
  89. }
  90. }
  91. private function specials($result)
  92. {
  93. if(empty($result)) return false;
  94. $code = intval($result['code']);
  95. if($code != 200) {
  96. return false;
  97. }
  98. else {
  99. $specials = $result['data']['specials'];
  100. return empty($specials) ? false : $specials;
  101. }
  102. }
  103. private function special_list($spids, &$ugcs)
  104. {
  105. $result = [];
  106. $mod_special = Model('mb_special');
  107. $items = $mod_special->getMbSpecialList(['special_id' => ['in',$spids]]);
  108. $users = [];
  109. $specials = [];
  110. foreach ($items as $item)
  111. {
  112. $special = new ugc\special($item);
  113. $specials[] = $special;
  114. $sender = $special->memberid();
  115. $users[] = $sender;
  116. }
  117. sort($users);
  118. array_unique($users);
  119. $minfos = [];
  120. if(!empty($users))
  121. {
  122. $mod_member = Model('member');
  123. $members = $mod_member->getMemberList(['member_id' => ['in',$users]]);
  124. foreach ($members as $member) {
  125. $info = new member_info($member);
  126. $mid = $info->member_id();
  127. $minfos[$mid] = $info;
  128. }
  129. }
  130. $ugcs = [];
  131. foreach ($specials as $special)
  132. {
  133. $block = special_formater::format_ugc($special);
  134. $result[] = $block;
  135. $divider = special_formater::def_divider();
  136. $result[] = $divider;
  137. $mid = $special->memberid();
  138. $minfo = $minfos[$mid];
  139. $ugc = $this->formate_ugc($minfo,$special);
  140. $ugcs[] = $ugc;
  141. }
  142. return $result;
  143. }
  144. private function formate_ugc(member_info $minfo,ugc\special $special)
  145. {
  146. $ret['special_id'] = $special->special_id();
  147. $ret['member_avatar'] = $minfo->avatar();
  148. $ret['member_nickname'] = $minfo->nickname();
  149. $ret['has_vote'] = $special->has_vote();
  150. $ret['appreciate_num'] = $special->appreciates();
  151. $ret['comment_num'] = $special->comments();
  152. $ret['clicks'] = $special->clicks();
  153. $ret['pubtime'] = $special->editime();
  154. $ret['desc'] = $special->description();
  155. $supporter = new ugc\special_support($special->special_id(),0);
  156. $ret['supported'] = $supporter->supported();
  157. $ret['support_num'] = $special->likes();
  158. $cid = $special->category_id();
  159. $ret['category'] = ugc_helper::category_title($cid);
  160. $ret['can_del'] = false;
  161. if(session_helper::logined())
  162. {
  163. if($special->memberid() == $_SESSION['member_id']) {
  164. $ret['can_del'] = true;
  165. }
  166. }
  167. return $ret;
  168. }
  169. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  170. public function addOp()
  171. {
  172. $this->need_login();
  173. $contet = $_POST['content'];
  174. if(empty($contet)) {
  175. return self::outerr(errcode::ErrParamter,"上传的内容不能为空");
  176. }
  177. $sp_data = json_decode($contet,true);
  178. if(empty($sp_data)) {
  179. return self::outerr(errcode::ErrParamter,"上传的内容不能为空");
  180. }
  181. $spobj = ugc_helper::crate_special($sp_data,$err);
  182. if($spobj == false) {
  183. return self::outerr($err['code'],$err['msg']);
  184. }
  185. if($spobj->count() > 0)
  186. {
  187. $special_id = $spobj->save($_SESSION['member_id'],$sp_data);
  188. } else {
  189. $special_id = false;
  190. }
  191. if($special_id == false) {
  192. return self::outerr(errcode::ErrUGC,"抱歉,内容云同步失败 :(");
  193. }
  194. else {
  195. return self::outsuccess(['special_id' => $special_id]);
  196. }
  197. }
  198. public function previewOp()
  199. {
  200. $this->need_login();
  201. return parent::indexOp();
  202. }
  203. public function publishOp()
  204. {
  205. $this->need_login();
  206. $special_id = intval($_GET['special_id']);
  207. $setting = $_GET['setting'];
  208. if($special_id < 0 || empty($setting)) {
  209. return self::outerr(errcode::ErrParamter);
  210. }
  211. $setting = json_decode($setting,true);
  212. if(ugc_helper::pub_special($special_id,$setting,$err) == false) {
  213. return self::outerr($err['code'],$err['msg']);
  214. }
  215. else {
  216. return self::outsuccess(['special_id' => $special_id]);
  217. }
  218. }
  219. public function delOp()
  220. {
  221. $this->need_login();
  222. $special_id = intval($_GET['special_id']);
  223. if(ugc_helper::del_special($special_id,$err) == false) {
  224. return self::outerr($err['code'],$err['msg']);
  225. }
  226. else {
  227. return self::outsuccess(['special_id' => $special_id]);
  228. }
  229. }
  230. public function supportOp()
  231. {
  232. $special_id = intval($_GET['special_id']);
  233. if($special_id < 0) {
  234. return self::outerr(errcode::ErrParamter,"该专题不存在");
  235. }
  236. $comment_id = intval($_GET['comment_id']);
  237. $supported = ugc_helper::support_special($special_id,$comment_id);
  238. return self::outsuccess(['special_id' => $special_id,'comment_id' => $comment_id,'supported' => $supported]);
  239. }
  240. public function commentsOp()
  241. {
  242. $special_id = intval($_GET['special_id']);
  243. if($special_id < 0) {
  244. return self::outerr(errcode::ErrParamter,"该专题不存在");
  245. }
  246. $comment_id = intval($_GET['comment_id']);
  247. if($comment_id <= 0)
  248. {
  249. $mod_comment = Model('ugc_comment');
  250. $count = $mod_comment->top_counts($special_id);
  251. $items = $mod_comment->getTopCommentList($special_id,'comment_id',$this->page_size(),$count);
  252. $pages = $mod_comment->gettotalpage();
  253. $mod = Model('ugc_comment');
  254. $commentids = $this->commentids($items);
  255. $comments = $mod->getCommentList(array('top_id' => ['in',$commentids]),'*',0);
  256. $comments_obj =new ugc\comments($comments,$special_id);
  257. $comments = $comments_obj->comments();
  258. $uids = $comments_obj->users();
  259. $members = $this->users($uids);
  260. return self::outsuccess(['total_count' => $count,'comments' => $comments,'members' => $members,'mobile_page' => mobile_page($pages)]);
  261. }
  262. else
  263. {
  264. $mod_comment = Model('ugc_comment');
  265. $count = $mod_comment->comment_counts($special_id,$comment_id);
  266. $items = $mod_comment->getSubCommentList($special_id,'comment_id',$this->page_size(),$count);
  267. $pages = $mod_comment->gettotalpage();
  268. $mod = Model('ugc_comment');
  269. $commentids = $this->commentids($items);
  270. $comments = $mod->getCommentList(array('comment_id' => ['in',$commentids]),'*',0);
  271. $comments_obj =new ugc\comments($comments,$special_id);
  272. $comments = $comments_obj->comments();
  273. $uids = $comments_obj->users();
  274. $members = $this->users($uids);
  275. return self::outsuccess(['total_count' => $count,'comments' => $comments,'members' => $members,'mobile_page' => mobile_page($pages)]);
  276. }
  277. }
  278. private function users($user_ids)
  279. {
  280. if(empty($user_ids)) return [];
  281. $mod_member = Model('member');
  282. $members = $mod_member->getMemberList(array('member_id' => ['in',$user_ids]));
  283. if(empty($members)) return [];
  284. $result = [];
  285. foreach ($members as $item)
  286. {
  287. $member = new member_info($item);
  288. $val['member_id'] = $member->member_id();
  289. $val['avatar'] = $member->avatar();
  290. $val['nickname'] = $member->nickname();
  291. $result[] = $val;
  292. }
  293. return $result;
  294. }
  295. private function commentids($items)
  296. {
  297. $result = [];
  298. foreach ($items as $val) {
  299. $commentid = intval($val['comment_id']);
  300. $result[] = $commentid;
  301. }
  302. return $result;
  303. }
  304. public function commentOp()
  305. {
  306. $this->need_login();
  307. $special_id = intval($_GET['special_id']);
  308. if($special_id < 0) {
  309. return self::outerr(errcode::ErrParamter,"该专题不存在");
  310. }
  311. $comment = urldecode($_GET['content']);
  312. if(empty($comment)) {
  313. return self::outerr(errcode::ErrParamter,"评论内容不能为空.");
  314. }
  315. $comment = text_filter::filter_html($comment);
  316. if(empty($comment)) {
  317. return self::outerr(errcode::ErrParamter,"评论内容不能含非法字符.");
  318. }
  319. $comment_id = intval($_GET['comment_id']);
  320. $mod_comment = Model('ugc_comment');
  321. if($comment_id > 0) {
  322. $ret = $mod_comment->respond_comment($special_id,$comment_id,session_helper::memberid(),$comment);
  323. } else {
  324. $ret = $mod_comment->comment($special_id,session_helper::memberid(),$comment);
  325. }
  326. if($ret == false) {
  327. return self::outerr(errcode::ErrDB,"抱歉,评论出错了.");
  328. }
  329. else
  330. {
  331. $mod = Model('ugc_comment');
  332. $comments = $mod->getCommentList(['comment_id' => $ret],'*',0);
  333. $comments_obj =new ugc\comments($comments,$special_id);
  334. $comments = $comments_obj->comments();
  335. $uids = $comments_obj->users();
  336. $members = $this->users($uids);
  337. return self::outsuccess(['comments' => $comments,'members' => $members,'mobile_page' => mobile_page(0)]);
  338. }
  339. }
  340. public function appreciateOp()
  341. {
  342. $this->need_login();
  343. $special_id = intval($_GET['special_id']);
  344. $rate = intval($_GET['rate']);
  345. $money = intval($_GET['money']);
  346. }
  347. }