fetch('pub_list'); } public function pri_listOp() { $this->need_login(); return $this->fetch('pri_list'); } public function mine_listOp() { $this->need_login(); return $this->fetch('mine_list'); } private function fetch($type) { $special_id = intval($_GET['special_id']); $count = $this->page_size(); if(empty($special_id) || $special_id == -1) { $special_id = -1; $direct = self::lesser; } else { $direct = $this->direct(); } if($type == "pub_list") { $result = search\relation_client::instance()->fetch_pub_special(['special_id' => $special_id,'count'=> $count,'type' => $direct]); } elseif($type == 'pri_list') { $result = search\relation_client::instance()->fetch_pri_special(['user_id' => intval($_SESSION['member_id']), 'special_id' => $special_id,'count'=> $count,'type' => $direct]); } elseif($type == "mine_list") { $result = search\relation_client::instance()->fetch_self_special(['user_id' => intval($_SESSION['member_id']), 'special_id' => $special_id,'count'=> $count,'type' => $direct]); } else { return self::outerr(errcode::ErrParamter); } $specials = $this->specials($result); if($specials == false) { $page_no = $this->page_no(); if($page_no == 1) $page_no = 0; return self::outsuccess(array('special_list' => null,'mobile_page' => mobile_page($page_no))); } else { $special_list = $this->special_list($specials,$ugcs); $page_no = $this->page_no(); if($this->page_size() <= count($specials)) { $page_no += 1; } return self::outsuccess(['special_list' => $special_list, 'ugcs' => $ugcs, 'summary' => null, 'groupbuy' => null, 'limitime' => null, 'bundling' => null, 'mobile_page' => mobile_page($page_no)]); } } private function direct() { $cur_page = $this->page_no(); if($cur_page == 1) { return self::greater; } else { return self::lesser; } } private function specials($result) { if(empty($result)) return false; $code = intval($result['code']); if($code != 200) { return false; } else { $specials = $result['data']['specials']; return empty($specials) ? false : $specials; } } private function special_list($spids, &$ugcs) { $result = []; $mod_special = Model('mb_special'); $items = $mod_special->getMbSpecialList(['special_id' => ['in',$spids]]); $users = []; $specials = []; foreach ($items as $item) { $special = new ugc\special($item); $specials[] = $special; $sender = $special->memberid(); $users[] = $sender; } sort($users); array_unique($users); $minfos = []; if(!empty($users)) { $mod_member = Model('member'); $members = $mod_member->getMemberList(['member_id' => ['in',$users]]); foreach ($members as $member) { $info = new member_info($member); $mid = $info->member_id(); $minfos[$mid] = $info; } } $ugcs = []; foreach ($specials as $special) { $block = special_formater::format_ugc($special); $result[] = $block; $divider = special_formater::def_divider(); $result[] = $divider; $mid = $special->memberid(); $minfo = $minfos[$mid]; $ugc = $this->formate_ugc($minfo,$special); $ugcs[] = $ugc; } return $result; } private function formate_ugc(member_info $minfo,ugc\special $special) { $ret['special_id'] = $special->special_id(); $ret['member_avatar'] = $minfo->avatar(); $ret['member_nickname'] = $minfo->nickname(); $ret['has_vote'] = $special->has_vote(); $ret['appreciate_num'] = $special->appreciates(); $ret['comment_num'] = $special->comments(); $ret['clicks'] = $special->clicks(); $ret['pubtime'] = $special->editime(); $ret['desc'] = $special->description(); $supporter = new ugc\special_support($special->special_id(),0); $ret['supported'] = $supporter->supported(); $ret['support_num'] = $special->likes(); $cid = $special->category_id(); $ret['category'] = ugc_helper::category_title($cid); $ret['can_del'] = false; if(session_helper::logined()) { if($special->memberid() == $_SESSION['member_id']) { $ret['can_del'] = true; } } return $ret; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public function addOp() { $this->need_login(); $contet = $_POST['content']; if(empty($contet)) { return self::outerr(errcode::ErrParamter,"上传的内容不能为空"); } $sp_data = json_decode($contet,true); if(empty($sp_data)) { return self::outerr(errcode::ErrParamter,"上传的内容不能为空"); } $spobj = ugc_helper::crate_special($sp_data,$err); if($spobj == false) { return self::outerr($err['code'],$err['msg']); } if($spobj->count() > 0) { $special_id = $spobj->save($_SESSION['member_id'],$sp_data); } else { $special_id = false; } if($special_id == false) { return self::outerr(errcode::ErrUGC,"抱歉,内容云同步失败 :("); } else { return self::outsuccess(['special_id' => $special_id]); } } public function previewOp() { $this->need_login(); return parent::indexOp(); } public function publishOp() { $this->need_login(); $special_id = intval($_GET['special_id']); $setting = $_GET['setting']; if($special_id < 0 || empty($setting)) { return self::outerr(errcode::ErrParamter); } $setting = json_decode($setting,true); if(ugc_helper::pub_special($special_id,$setting,$err) == false) { return self::outerr($err['code'],$err['msg']); } else { return self::outsuccess(['special_id' => $special_id]); } } public function delOp() { $this->need_login(); $special_id = intval($_GET['special_id']); if(ugc_helper::del_special($special_id,$err) == false) { return self::outerr($err['code'],$err['msg']); } else { return self::outsuccess(['special_id' => $special_id]); } } public function supportOp() { $special_id = intval($_GET['special_id']); if($special_id < 0) { return self::outerr(errcode::ErrParamter,"该专题不存在"); } $comment_id = intval($_GET['comment_id']); $supported = ugc_helper::support_special($special_id,$comment_id); return self::outsuccess(['special_id' => $special_id,'comment_id' => $comment_id,'supported' => $supported]); } public function commentsOp() { $special_id = intval($_GET['special_id']); if($special_id < 0) { return self::outerr(errcode::ErrParamter,"该专题不存在"); } $comment_id = intval($_GET['comment_id']); if($comment_id <= 0) { $mod_comment = Model('ugc_comment'); $count = $mod_comment->top_counts($special_id); $items = $mod_comment->getTopCommentList($special_id,'comment_id',$this->page_size(),$count); $pages = $mod_comment->gettotalpage(); $mod = Model('ugc_comment'); $commentids = $this->commentids($items); $comments = $mod->getCommentList(array('top_id' => ['in',$commentids]),'*',0); $comments_obj =new ugc\comments($comments,$special_id); $comments = $comments_obj->comments(); $uids = $comments_obj->users(); $members = $this->users($uids); return self::outsuccess(['total_count' => $count,'comments' => $comments,'members' => $members,'mobile_page' => mobile_page($pages)]); } else { $mod_comment = Model('ugc_comment'); $count = $mod_comment->comment_counts($special_id,$comment_id); $items = $mod_comment->getSubCommentList($special_id,'comment_id',$this->page_size(),$count); $pages = $mod_comment->gettotalpage(); $mod = Model('ugc_comment'); $commentids = $this->commentids($items); $comments = $mod->getCommentList(array('comment_id' => ['in',$commentids]),'*',0); $comments_obj =new ugc\comments($comments,$special_id); $comments = $comments_obj->comments(); $uids = $comments_obj->users(); $members = $this->users($uids); return self::outsuccess(['total_count' => $count,'comments' => $comments,'members' => $members,'mobile_page' => mobile_page($pages)]); } } private function users($user_ids) { if(empty($user_ids)) return []; $mod_member = Model('member'); $members = $mod_member->getMemberList(array('member_id' => ['in',$user_ids])); if(empty($members)) return []; $result = []; foreach ($members as $item) { $member = new member_info($item); $val['member_id'] = $member->member_id(); $val['avatar'] = $member->avatar(); $val['nickname'] = $member->nickname(); $result[] = $val; } return $result; } private function commentids($items) { $result = []; foreach ($items as $val) { $commentid = intval($val['comment_id']); $result[] = $commentid; } return $result; } public function commentOp() { $this->need_login(); $special_id = intval($_GET['special_id']); if($special_id < 0) { return self::outerr(errcode::ErrParamter,"该专题不存在"); } $comment = urldecode($_GET['content']); if(empty($comment)) { return self::outerr(errcode::ErrParamter,"评论内容不能为空."); } $comment = text_filter::filter_html($comment); if(empty($comment)) { return self::outerr(errcode::ErrParamter,"评论内容不能含非法字符."); } $comment_id = intval($_GET['comment_id']); $mod_comment = Model('ugc_comment'); if($comment_id > 0) { $ret = $mod_comment->respond_comment($special_id,$comment_id,session_helper::memberid(),$comment); } else { $ret = $mod_comment->comment($special_id,session_helper::memberid(),$comment); } if($ret == false) { return self::outerr(errcode::ErrDB,"抱歉,评论出错了."); } else { $mod = Model('ugc_comment'); $comments = $mod->getCommentList(['comment_id' => $ret],'*',0); $comments_obj =new ugc\comments($comments,$special_id); $comments = $comments_obj->comments(); $uids = $comments_obj->users(); $members = $this->users($uids); return self::outsuccess(['comments' => $comments,'members' => $members,'mobile_page' => mobile_page(0)]); } } public function appreciateOp() { $this->need_login(); $special_id = intval($_GET['special_id']); $rate = intval($_GET['rate']); $money = intval($_GET['money']); } }