special($special_id);
if($spitem == false) {
return self::outerr(errcode::ErrParamter,"该专题不存在");
}
QueueClient::push('onClickSpecial',['special_id' => $special_id]);
if($spitem->from_user())
{
if(session_helper::need_wechat_author()) {
$author = new thrid_author\wxauthor();
$url = author_url::ugc_url($special_id);
$url = $author->enter($url);
return self::outsuccess(['direct_uri' => $url],"redirect");
}
$ret = $this->pri_special($special_id);
$ret['spitem'] = $spitem;
$tpl_obj = new tpl_ugc($ret);
self::outsuccess(['tpl_obj' => $tpl_obj],'ugc/content');
} else {
$ret = $this->pub_special($special_id);
self::outsuccess($ret);
}
}
public function submitOp()
{
$special_id = intval($_GET['special_id']);
$spitem = spid_helper::instance()->special($special_id);
if($special_id < 0 || $spitem == false) {
return self::outerr(errcode::ErrParamter,"该文章不存在");
}
$content = urldecode($_GET['content']);
if(empty($content)) {
$options = false;
}
else {
$options = json_decode($content,true);
if($options == null) $options = false;
}
$result = ugc_helper::submit($special_id,$options,$err);
if($result == false) {
return self::outerr($err['code'],$err['msg']);
}
else
{
$vote_result = $result['vote_result'];
$type_sn = $result['type_sn'];
if(!empty($type_sn)) {
$url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&type_sn={$type_sn}";
$type = bonus\type::create_by_sn($type_sn);
$sender_id = $type->sender_id();
$minfo = new member_info($sender_id);
$avatar = $minfo->avatar();
} else {
$url = "";
$avatar = '';
}
$answer_diff = $result['answer_diff'];
return self::outsuccess(['special_id' => $special_id,
'vote_result' => $vote_result,
'answer_diff' => $answer_diff,
'bonus_url' => $url,
'num' => $result['num'],
'amount' => $result['amount'],
'bonus_type' => $result['bonus_type'],
'sender_avatar' => $avatar]);
}
}
protected function pub_special($special_id)
{
$specials = special_manager::instance()->special($special_id,$goods_ids,true);
if (!empty($goods_ids))
{
$helper = new goods_helper();
$goodsex = $helper->online_summary($goods_ids, $related_goods);
return array('special_list' => $specials,
'tabs' => special_manager::instance()->tabs($special_id),
'summary' => $goodsex['summary'],
'groupbuy' => $goodsex['groupbuy'],
'limitime' => $goodsex['limitime'],
'bundling' => $goodsex['bundling'],
'bargain_create' => $goodsex['bargain_create'],
'mobile_page' => mobile_page(1));
}
else
{
return array('special_list' => $specials,
'summary' => array(),
'groupbuy' => array(),
'limitime' => array(),
'bundling' => array(),
'mobile_page' => mobile_page(1));
}
}
protected function pri_special($special_id)
{
$result = special_manager::instance()->special($special_id,$goods_ids,false);
if (!empty($goods_ids))
{
$helper = new goods_helper();
$goodsex = $helper->online_summary($goods_ids, $related_goods);
return array('special_list' => $result['specials'],
'sender_info' => $result['sender_info'],
'special_info' => $result['special_info'],
'summary' => $goodsex['summary'],
'groupbuy' => $goodsex['groupbuy'],
'limitime' => $goodsex['limitime'],
'bundling' => $goodsex['bundling'],
'mobile_page' => mobile_page(1));
}
else
{
return array('special_list' => $result['specials'],
'sender_info' => $result['sender_info'],
'special_info' => $result['special_info'],
'summary' => array(),
'groupbuy' => array(),
'limitime' => array(),
'bundling' => array(),
'mobile_page' => mobile_page(1));
}
}
}
class tpl_ugc
{
private $spitem;
private $special_list;
private $summary;
private $mem_info;
private $special;
private $mQuestionIndex;
private $mVoteIndex;
private $mAuthorRelation;
public function __construct($output)
{
$this->mQuestionIndex = 0;
$this->mVoteIndex = 0;
$this->spitem = $output['spitem'];
$this->special_list = $output['special_list'];
$this->summary = $output['summary'];
if(!empty($output['sender_info'])) {
$this->mem_info = new member_info($output['sender_info']);
} else {
$this->mem_info = null;
}
$special_id = $output['special_info']['special_id'];
$mod_special = Model('mb_special');
$special_info = $mod_special->getMbSpecialByID($special_id,'*',true);
if(!empty($special_info)) {
$this->special = new ugc\special($special_info);
} else {
$this->special = null;
}
if(session_helper::logined())
{
$memberid = session_helper::memberid();
if($this->special->memberid() == $memberid) {
$this->mAuthorRelation = 2;
}
else
{
$ret = relation_helper::subscribed($memberid,$this->special->memberid());
$this->mAuthorRelation = $ret == true ? 1 : 0;
}
} else {
$this->mAuthorRelation = false;
}
}
public function preview()
{
return $this->special->preview();
}
public function special_id()
{
return $this->special->special_id();
}
public function browse_title()
{
if(session_helper::isapp()) {
return "文章内容";
} else {
$title = $this->special->share_title();
return $title;
}
}
public function title() {
$title = $this->special->share_title();
$title = str_replace( array( "\n", "\r" ), array( " ", " " ), $title );
return $title;
}
public function image() {
return $this->special->share_img();
}
public function url() {
$special_id = $this->special_id();
return url_helper::ugc_url($special_id);
}
public function sub_title()
{
$desc = $this->special->description();
$desc = str_replace( array( "\n", "\r" ), array( " ", " " ), $desc);
if(empty($desc)) return "";
else
return $desc;
}
public function last_title()
{
$submit_rule = $this->special->submit_rule();
if(!empty($submit_rule)) {
$submit_rule->avaliable();
$desc = "点击领取红包";
} else {
$desc = "熊猫美妆";
}
return $desc;
}
public function show_title()
{
$title = $this->spitem->share_title();
if(!empty($title))
{
$str = "
{$title}
";
echo $str;
}
}
private function format_time($tm)
{
$cur_tm = time();
$delta = $cur_tm - $tm;
if($delta < 600) {
return "刚刚";
}
elseif ($delta < 3600) {
$delta = intval($delta / 60);
return "{$delta}分钟前";
}
elseif($delta < 3600 * 24) {
$delta = intval($delta / 3600);
return "{$delta}小时前";
}
else {
return strftime("%m-%d",$tm);
}
}
public function show_sender()
{
if($this->mem_info != null)
{
$nick_name = $this->mem_info->nickname();
$avatar = $this->mem_info->avatar();
$pubtime = $this->special->pubtime();
$pubtime = $this->format_time($pubtime);
$av_str = "
";//
$name_str = "
文/{$nick_name}
{$pubtime}
";
$str = $av_str . $name_str;
} else {
$str = '';
}
echo $str;
}
public function show_blocks()
{
$this->mQuestionIndex = 0;
foreach ($this->special_list as $block)
{
$item_type = $block['item_type'];
$items = $block['items'];
if($item_type == 'home_ugc' && !empty($items)) {
$this->show_items($items);
}
}
$this->show_submit();
$this->show_answer_page();
$this->show_appreciate();
$this->show_comment_header();
}
private function show_submit()
{
$vote_single = $this->special->vote_single();
$submitor = new ugc\special_submitor($this->special_id(),$vote_single);
$special = $this->special;
if(!$submitor->submited())
{
$rule = $special->submit_rule();
if($rule != false) {
$avaliable = $rule->avaliable();
} else {
$avaliable = false;
}
if($special->has_vote() || $special->has_question())
{
if($special->has_vote() && $special->has_question()) {
$content = "提交";
}
elseif($special->has_vote()) {
$content = "投票";
}
else{
$content = "提交";
}
if($rule != false && $avaliable == true)
{
$content .= " (领红包)";
}
if($special->has_over()) {
$str = "";
} else {
$str = "";
}
}
else
{
if($rule == false) {
return;
}
else
{
if($avaliable)
{
$content = "领红包";
if($special->has_over()) {
$str = "";
} else {
$str = "";
}
}
}
}
}
else {
$str = "";
}
echo $str;
}
private function show_comment_header()
{
$report_url = BASE_SITE_URL . "/mobile/index.php?act=member_ugc&op=report_page&special_id={$this->special_id()}";
$str = '';
$clicks = $this->special->clicks();
if(!$this->preview())
{
$str .= "";
}
echo $str;
}
private function show_items($items)
{
foreach ($items as $item)
{
$show_type = $item['show_type'];
if($show_type == 'image') {
$this->show_image($item);
}
elseif($show_type == 'text') {
$this->show_text($item);
}
elseif($show_type == 'vote')
{
$vote_single = $this->special->vote_single();
$submitor = new ugc\special_submitor($this->special_id(),$vote_single);
if($submitor->submited()) {
$this->show_vote_result($item);
} else {
$this->show_vote($item);
}
$this->mVoteIndex++;
}
elseif($show_type == 'question') {
$this->show_question($item);
$this->mQuestionIndex++;
}
elseif($show_type == 'goods') {
$this->show_goods($item);
}
else {
}
}
}
private function goods_summary($goods_id)
{
foreach ($this->summary as $summary)
{
if($summary['goods_id'] == $goods_id) {
return $summary;
}
}
return false;
}
private function show_goods($item)
{
$goods_id = intval($item['data']);
$summary = $this->goods_summary($goods_id);
if($summary == false) return;
$recoment = $item['reserved'];
if(session_helper::isapp()) {
$url = "xmmz://p.lrlz.com/goods/goods?goodsId={$goods_id}";
} else {
$url = BASE_SITE_URL . "/mshop/goods_detail?goods_id={$goods_id}";
}
if($summary['goods_storage'] <= 0) {
$state = '已经售罄';
}
elseif($summary['act_id'] > 0) {
$state = '限时特价';
}
elseif($summary['is_new']) {
$state = '熊猫新品';
}
else {
$state = '';
}
$goods_price = $summary['goods_price'];
$bonus_price = $summary['bonus_price'];
$discount = $goods_price - $bonus_price;
$str = "";
echo $str;
}
private function show_question($item)
{
if(empty($item['data'])) return false;
$options = json_decode($item['data'],true);
$title = $item['title'];
$qindex = $this->mQuestionIndex;
$i = $qindex + 1;
$show_title = "第{$i}题、{$title}";
$reserved = $item['reserved'];
$kv = preg_split('/=/',$reserved);
if(!empty($kv))
{
$k = trim($kv[0]);
$v = trim($kv[1]);
if(!empty($k) && $k == 'answer_type') {
$answer_type = $v;
}
}
$answer_type = intval($answer_type);
if($answer_type == 0) {
$sanswer_type = '单选';
$box = "radio";
}
else {
$sanswer_type = '多选';
$box = "checkbox";
}
$header = "
{$show_title}
/{$sanswer_type}
";
$opindex = 65;
$soptions = '';
foreach ($options as $val)
{
$key = $val['id'];
$option = $val['text'];
$si = sprintf("%c",$opindex++);
$soptions .= "
";
}
$end = '
';
$str = "{$header}{$soptions}{$end}";
echo $str;
}
private function show_vote($item)
{
if(empty($item['data'])) return false;
$options = json_decode($item['data'],true);
if(empty($options)) return false;
$title = $item['title'];
$reserved = $item['reserved'];
$kv = preg_split('/=/',$reserved);
if(!empty($kv))
{
$k = trim($kv[0]);
$v = trim($kv[1]);
if(!empty($k) && $k == 'vote_type') {
$vote_type = $v;
}
}
$vote_type = intval($vote_type);
if($vote_type == 0) {
$svote_type = '单选';
$box = "radio";
}
elseif ($vote_type == 1) {
$svote_type = '多选';
$box = "checkbox";
}
else {
$svote_type = '最多选两项';
$box = "checkbox";
}
$index = $this->mVoteIndex + 1;
$str = "
投票{$index}: {$title}
/{$svote_type}
";
foreach ($options as $val)
{
$key = $val['id'];
$option = $val['text'];
$soption = "
";
$str .= $soption;
}
$str .= '
';
$str .= '
';
echo $str;
}
private function show_vote_result($item)
{
if(empty($item['data'])) return false;
$options = json_decode($item['data'],true);
if(empty($options)) return false;
$title = $item['title'];
$reserved = $item['reserved'];
$kv = preg_split('/=/',$reserved);
if(!empty($kv))
{
$k = trim($kv[0]);
$v = trim($kv[1]);
if(!empty($k) && $k == 'vote_type') {
$vote_type = $v;
}
}
$vote_type = intval($vote_type);
if($vote_type == 0) {
$svote_type = '单选';
}
elseif ($vote_type == 1) {
$svote_type = '多选';
}
else {
$svote_type = '最多选两项';
}
$str = "
";
$str .= '
';
$vote_result = $this->special->vote_result();
$result = $vote_result[$this->mVoteIndex];
$total = 0;
foreach ($result as $key => $val) {
$total += $val;
}
foreach ($options as $val)
{
$id = $val['id'];
$title = $val['text'];
$count = $result[$id];
if($total > 0) {
$per = intval($count * 100 / $total + 0.5);
} else {
$per = 0;
}
$option = "
";
$str .= $option;
}
$str .= '
';
$str .= '
';
echo $str;
}
private function show_text($item)
{
$data = $item['data'];
echo "{$data}";
}
private function show_image($item)
{
$image = $item['show_data'];
$type = $item['type'];
$title = $item['title'];
if($type == 'url')
{
$url = $item['data'];
$str = "";
}
elseif($type == 'video')
{
$video = $item['data'];
$str = "";
}
else
{
$str = "";
}
echo $str;
}
public function show_comments()
{
if($this->preview()) return;
$supporter = new ugc\special_support($this->special_id(),0);
$supported = $supporter->supported();
$str = "
我来说两句
";
if($supported) {
$str .= "
";
} else {
$str .= "
";
}
$str .= "";
if(session_helper::isapp())
{
$str .= "
";
} else {
$str .= "打开APP";
}
echo $str;
}
private function show_appreciate()
{
$fappreciate = $this->special->has_appreciate();
if($fappreciate == false) return;
$nums = $this->special->appreciates();
$header = "
如果你喜欢该文章,请随意打赏。
";
if($nums > 0)
{
$header .= "打赏 | 已有{$nums}次打赏";
$header .= "
";
$avatars = $this->appreciate_avatars($this->special_id(),20);
$sAvatars = '';
foreach ($avatars as $avatar) {
$sAvatars .= "

";
}
$header .= $sAvatars;
$header .= '
';
if($nums > 20) {
$header .= '
....超20人打赏
';
}
}
else {
$header .= "打赏";
$header .= "
";
$header .= "";
}
$header .='';
echo $header;
}
private function appreciate_avatars($special_id,$count)
{
$mod = Model('appreciate');
$items = $mod->getTopAppreciate($special_id,'*',$count);
$uids = [];
foreach ($items as $item) {
$uid = intval($item['member_id']);
$uids[] = $uid;
}
$avatars = [];
if(!empty($uids))
{
$mod_member = Model('member');
$mInfos = $mod_member->getMemberList(array('member_id' => ['in',$uids]));
foreach ($mInfos as $info) {
$minfo = new member_info($info);
$avatar = $minfo->avatar();
$avatars[] = $avatar;
}
}
return $avatars;
}
private function show_answer_page()
{
$specialid = $this->special_id();
if($specialid <= 0) return;
$special = $this->special;
if($special->has_question()) {
$answer_page = true;
}
if(isset($answer_page) && $answer_page == true)
{
$mod_answer = Model('ugc_answer');
$count = $mod_answer->counts($specialid);
if($count > 0) {
$url = BASE_SITE_URL . "/mobile/index.php?act=member_ugc&op=answer_page&client_type=wap&special_id={$specialid}";
$str = "查看答题情况>>
";
echo $str;
return;
}
}
$rule = $this->special->submit_rule();
if(!empty($rule))
{
$type_sn = $rule->type_sn();
if(!empty($type_sn)) {
$url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=detail&client_type=wap&type_sn={$type_sn}";
$str = "查看红包领取情况>>
";
echo $str;
return;
}
}
}
public function show_relation()
{
if($this->mAuthorRelation == 0) {
echo '+关注
';
}
elseif($this->mAuthorRelation == 1) {
echo '已关注
';
}
else {
}
}
}