123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/7/5
- * Time: 下午4:02
- */
- require_once(BASE_ROOT_PATH . '/mobile/control/special.php');
- require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
- require_once(BASE_ROOT_PATH . '/helper/text_filter.php');
- class member_ugcControl extends specialControl
- {
- const greater = 0;
- const lesser = 1;
- public function __construct()
- {
- parent::__construct();
- }
- public function pub_listOp()
- {
- return $this->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']);
- }
- }
|