special.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/9/7
  6. * Time: 下午3:52
  7. */
  8. defined('InShopNC') or exit('Access Invalid!');
  9. require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
  10. require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
  12. require_once(BASE_ROOT_PATH . '/helper/model_helper.php');
  13. require_once(BASE_ROOT_PATH . '/helper/user_session/storage.php');
  14. require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
  15. class specialControl extends mobileHomeControl
  16. {
  17. public function __construct() {
  18. parent::__construct();
  19. }
  20. public function indexOp()
  21. {
  22. $special_id = intval($_GET['special_id']);
  23. if($special_id < 0) {
  24. return self::outerr(errcode::ErrParamter);
  25. }
  26. if($special_id == 0) {
  27. $ret = $this->pub_special($special_id);
  28. self::outsuccess($ret);
  29. }
  30. else
  31. {
  32. $spitem = spid_helper::instance()->special($special_id);
  33. if($spitem == false) {
  34. return self::outerr(errcode::ErrParamter,"该专题不存在");
  35. }
  36. if($spitem->from_user())
  37. {
  38. $ret = $this->pri_special($special_id);
  39. $ret['spitem'] = $spitem;
  40. $tpl_obj = new tpl_ugc($ret);
  41. self::outsuccess(['tpl_obj' => $tpl_obj],'ugc/content');
  42. } else {
  43. $ret = $this->pub_special($special_id);
  44. self::outsuccess($ret);
  45. }
  46. }
  47. }
  48. public function voteOp()
  49. {
  50. $special_id = intval($_GET['special_id']);
  51. if(!empty($_GET['options'])) {
  52. $options = explode(',',$_GET['options']);
  53. }
  54. if($special_id < 0 || empty($options)) {
  55. return self::outerr(errcode::ErrParamter,"该文章不存在或者没有选中选项");
  56. }
  57. $spitem = spid_helper::instance()->special($special_id);
  58. if($spitem->has_vote())
  59. {
  60. $result = ugc_helper::vote($special_id,$options,$err);
  61. if($result == false) {
  62. return self::outerr($err['code'],$err['msg']);
  63. }
  64. else
  65. {
  66. $vote_result = $result['vote_result'];
  67. $type_sn = $result['type_sn'];
  68. if(!empty($type_sn)) {
  69. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&type_sn={$type_sn}";
  70. } else {
  71. $url = "";
  72. }
  73. return self::outsuccess(['special_id' => $special_id,'vote_result' => $vote_result,'bonus_url' => $url]);
  74. }
  75. }
  76. else {
  77. return self::outerr(errcode::ErrSpecial,"本文不支持投票");
  78. }
  79. }
  80. protected function pub_special($special_id)
  81. {
  82. $specials = special_manager::instance()->special($special_id,$goods_ids,true);
  83. if (!empty($goods_ids))
  84. {
  85. $helper = new goods_helper();
  86. $goodsex = $helper->online_summary($goods_ids, $related_goods);
  87. return array('special_list' => $specials,
  88. 'summary' => $goodsex['summary'],
  89. 'groupbuy' => $goodsex['groupbuy'],
  90. 'limitime' => $goodsex['limitime'],
  91. 'bundling' => $goodsex['bundling'],
  92. 'mobile_page' => mobile_page(1));
  93. }
  94. else
  95. {
  96. return array('special_list' => $specials,
  97. 'summary' => array(),
  98. 'groupbuy' => array(),
  99. 'limitime' => array(),
  100. 'bundling' => array(),
  101. 'mobile_page' => mobile_page(1));
  102. }
  103. }
  104. protected function pri_special($special_id)
  105. {
  106. $result = special_manager::instance()->special($special_id,$goods_ids,false);
  107. if (!empty($goods_ids))
  108. {
  109. $helper = new goods_helper();
  110. $goodsex = $helper->online_summary($goods_ids, $related_goods);
  111. return array('special_list' => $result['specials'],
  112. 'sender_info' => $result['sender_info'],
  113. 'special_info' => $result['special_info'],
  114. 'summary' => $goodsex['summary'],
  115. 'groupbuy' => $goodsex['groupbuy'],
  116. 'limitime' => $goodsex['limitime'],
  117. 'bundling' => $goodsex['bundling'],
  118. 'mobile_page' => mobile_page(1));
  119. }
  120. else
  121. {
  122. return array('special_list' => $result['specials'],
  123. 'sender_info' => $result['sender_info'],
  124. 'special_info' => $result['special_info'],
  125. 'summary' => array(),
  126. 'groupbuy' => array(),
  127. 'limitime' => array(),
  128. 'bundling' => array(),
  129. 'mobile_page' => mobile_page(1));
  130. }
  131. }
  132. }
  133. class tpl_ugc
  134. {
  135. private $spitem;
  136. private $special_list;
  137. private $summary;
  138. private $mem_info;
  139. private $special_info;
  140. public function __construct($output)
  141. {
  142. $this->spitem = $output['spitem'];
  143. $this->special_list = $output['special_list'];
  144. $this->summary = $output['summary'];
  145. if(!empty($output['sender_info'])) {
  146. $this->mem_info = new member_info($output['sender_info']);
  147. } else {
  148. $this->mem_info = null;
  149. }
  150. if(!empty($output['special_info'])) {
  151. $this->special_info = new special_info($output['special_info']);
  152. } else {
  153. $this->special_info = null;
  154. }
  155. }
  156. public function title() {
  157. return $this->spitem->share_title();
  158. }
  159. public function show_title()
  160. {
  161. $title = $this->spitem->share_title();
  162. if(!empty($title))
  163. {
  164. $str = "<div class=\"title\">
  165. <h3>{$title}</h3>
  166. <span class=\"br\"></span>
  167. </div>";
  168. echo $str;
  169. }
  170. }
  171. public function show_sender()
  172. {
  173. if($this->mem_info != null)
  174. {
  175. $nick_name = $this->mem_info->nickname();
  176. $avatar = $this->mem_info->avatar();
  177. $str = "<img src=\"{$avatar}\" alt=\"熊猫美妆\">文/{$nick_name}";
  178. } else {
  179. $str = '';
  180. }
  181. echo $str;
  182. }
  183. public function show_blocks()
  184. {
  185. foreach ($this->special_list as $block)
  186. {
  187. $item_type = $block['item_type'];
  188. $items = $block['items'];
  189. if($item_type == 'home_ugc' && !empty($items)) {
  190. $this->show_items($items);
  191. }
  192. }
  193. }
  194. private function show_items($items)
  195. {
  196. $qindex = 0;
  197. foreach ($items as $item)
  198. {
  199. $show_type = $item['show_type'];
  200. if($show_type == 'image') {
  201. $this->show_image($item);
  202. }
  203. elseif($show_type == 'text') {
  204. $this->show_text($item);
  205. }
  206. elseif($show_type == 'vote') {
  207. $this->show_vote($item);
  208. }
  209. elseif($show_type == 'question') {
  210. $this->show_question($item,$qindex);
  211. $qindex++;
  212. }
  213. else {
  214. }
  215. }
  216. }
  217. private function show_question($item,$qindex)
  218. {
  219. }
  220. private function show_vote($item)
  221. {
  222. if(empty($item['data'])) return false;
  223. $options = json_decode($item['data'],true);
  224. if(empty($options)) return false;
  225. $title = $item['title'];
  226. $reserved = $item['reserved'];
  227. $kv = preg_split('/=/',$reserved);
  228. if(!empty($kv))
  229. {
  230. $k = trim($kv[0]);
  231. $v = trim($kv[1]);
  232. if(!empty($k) && $k == 'vote_type') {
  233. $vote_type = $v;
  234. }
  235. }
  236. $vote_type = intval($vote_type);
  237. if($vote_type == 0) {
  238. $svote_type = '单选';
  239. }
  240. elseif ($vote_type == 1) {
  241. $svote_type = '最多选两项';
  242. }
  243. else {
  244. $svote_type = '多选';
  245. }
  246. if($this->special_info != null) {
  247. $special_id = $this->special_info->special_id();
  248. } else {
  249. $special_id = -1;
  250. }
  251. $str = "<div class=\"vote\" data-special_id=\"{$special_id}\">
  252. <div class=\"vote_pro\">
  253. <div class=\"vote_question\">{$title}</div>
  254. <div class=\"vote_type\">/{$svote_type}</div>
  255. </div>
  256. <div class=\"vote_options\">";
  257. foreach ($options as $val)
  258. {
  259. $key = $val['id'];
  260. $option = $val['text'];
  261. $soption = "<div class=\"vote_option\">
  262. <label>
  263. <input type=\"checkbox\" value=\"{$key}\" class=\"check\" name=\"submit_vote\">
  264. <span class=\"label\">{$option}</span>
  265. </label>
  266. </div>";
  267. $str .= $soption;
  268. }
  269. $str .= '</div></div><button class="button_vote" id="submit_btn">投票</button>';
  270. echo $str;
  271. }
  272. private function show_text($item)
  273. {
  274. $data = $item['data'];
  275. echo "<article>{$data}</article>";
  276. }
  277. private function show_image($item)
  278. {
  279. $image = $item['show_data'];
  280. $type = $item['type'];
  281. $title = $item['title'];
  282. if($type == 'url')
  283. {
  284. $url = $item['data'];
  285. $str = "<div class=\"thumbnail\">
  286. <a href=\"{$url}\">
  287. <div class=\"thumbnail_image\">
  288. <img src=\"{$image}\" alt=\"熊猫美妆\">
  289. </div>
  290. </a>
  291. <div class=\"thumbnail_pro\">{$title}</div>
  292. </div>";
  293. }
  294. elseif($type == 'video')
  295. {
  296. $video = $item['data'];
  297. $str = "<div class=\"thumbnail\">
  298. <video poster=\"$image\" src=\"{$video}\">
  299. 您的设备不支持视频播放
  300. </video>
  301. <div class=\"thumbnail_pro\">
  302. 《化妆小教程》
  303. </div>
  304. </div>";
  305. }
  306. else
  307. {
  308. $str = "<div class=\"thumbnail\">
  309. <div class=\"thumbnail_image\">
  310. <img src=\"{$image}\" alt=\"熊猫美妆\">
  311. </div>
  312. <div class=\"thumbnail_pro\">{$title}</div>
  313. </div>";
  314. }
  315. echo $str;
  316. }
  317. }