123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/9/7
- * Time: 下午3:52
- */
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/model_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/user_session/storage.php');
- require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
- class specialControl extends mobileHomeControl
- {
- public function __construct() {
- parent::__construct();
- }
- public function indexOp()
- {
- $special_id = intval($_GET['special_id']);
- if($special_id < 0) {
- return self::outerr(errcode::ErrParamter);
- }
- if($special_id == 0) {
- $ret = $this->pub_special($special_id);
- self::outsuccess($ret);
- }
- else
- {
- $spitem = spid_helper::instance()->special($special_id);
- if($spitem == false) {
- return self::outerr(errcode::ErrParamter,"该专题不存在");
- }
- if($spitem->from_user())
- {
- $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 voteOp()
- {
- $special_id = intval($_GET['special_id']);
- if(!empty($_GET['options'])) {
- $options = explode(',',$_GET['options']);
- }
- if($special_id < 0 || empty($options)) {
- return self::outerr(errcode::ErrParamter,"该文章不存在或者没有选中选项");
- }
- $spitem = spid_helper::instance()->special($special_id);
- if($spitem->has_vote())
- {
- $result = ugc_helper::vote($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}";
- } else {
- $url = "";
- }
- return self::outsuccess(['special_id' => $special_id,'vote_result' => $vote_result,'bonus_url' => $url]);
- }
- }
- else {
- return self::outerr(errcode::ErrSpecial,"本文不支持投票");
- }
- }
- 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,
- 'summary' => $goodsex['summary'],
- 'groupbuy' => $goodsex['groupbuy'],
- 'limitime' => $goodsex['limitime'],
- 'bundling' => $goodsex['bundling'],
- '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_info;
- public function __construct($output)
- {
- $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;
- }
- if(!empty($output['special_info'])) {
- $this->special_info = new special_info($output['special_info']);
- } else {
- $this->special_info = null;
- }
- }
- public function title() {
- return $this->spitem->share_title();
- }
- public function show_title()
- {
- $title = $this->spitem->share_title();
- if(!empty($title))
- {
- $str = "<div class=\"title\">
- <h3>{$title}</h3>
- <span class=\"br\"></span>
- </div>";
- echo $str;
- }
- }
- public function show_sender()
- {
- if($this->mem_info != null)
- {
- $nick_name = $this->mem_info->nickname();
- $avatar = $this->mem_info->avatar();
- $str = "<img src=\"{$avatar}\" alt=\"熊猫美妆\">文/{$nick_name}";
- } else {
- $str = '';
- }
- echo $str;
- }
- public function show_blocks()
- {
- 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);
- }
- }
- }
- private function show_items($items)
- {
- $qindex = 0;
- 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') {
- $this->show_vote($item);
- }
- elseif($show_type == 'question') {
- $this->show_question($item,$qindex);
- $qindex++;
- }
- else {
- }
- }
- }
- private function show_question($item,$qindex)
- {
- }
- 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 = '单选';
- }
- elseif ($vote_type == 1) {
- $svote_type = '最多选两项';
- }
- else {
- $svote_type = '多选';
- }
- if($this->special_info != null) {
- $special_id = $this->special_info->special_id();
- } else {
- $special_id = -1;
- }
- $str = "<div class=\"vote\" data-special_id=\"{$special_id}\">
- <div class=\"vote_pro\">
- <div class=\"vote_question\">{$title}</div>
- <div class=\"vote_type\">/{$svote_type}</div>
- </div>
- <div class=\"vote_options\">";
- foreach ($options as $val)
- {
- $key = $val['id'];
- $option = $val['text'];
- $soption = "<div class=\"vote_option\">
- <label>
- <input type=\"checkbox\" value=\"{$key}\" class=\"check\" name=\"submit_vote\">
- <span class=\"label\">{$option}</span>
- </label>
- </div>";
- $str .= $soption;
- }
- $str .= '</div></div><button class="button_vote" id="submit_btn">投票</button>';
- echo $str;
- }
- private function show_text($item)
- {
- $data = $item['data'];
- echo "<article>{$data}</article>";
- }
- private function show_image($item)
- {
- $image = $item['show_data'];
- $type = $item['type'];
- $title = $item['title'];
- if($type == 'url')
- {
- $url = $item['data'];
- $str = "<div class=\"thumbnail\">
- <a href=\"{$url}\">
- <div class=\"thumbnail_image\">
- <img src=\"{$image}\" alt=\"熊猫美妆\">
- </div>
- </a>
- <div class=\"thumbnail_pro\">{$title}</div>
- </div>";
- }
- elseif($type == 'video')
- {
- $video = $item['data'];
- $str = "<div class=\"thumbnail\">
- <video poster=\"$image\" src=\"{$video}\">
- 您的设备不支持视频播放
- </video>
- <div class=\"thumbnail_pro\">
- 《化妆小教程》
- </div>
- </div>";
- }
- else
- {
- $str = "<div class=\"thumbnail\">
- <div class=\"thumbnail_image\">
- <img src=\"{$image}\" alt=\"熊猫美妆\">
- </div>
- <div class=\"thumbnail_pro\">{$title}</div>
- </div>";
- }
- echo $str;
- }
- }
|