special.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. if(session_helper::need_wechat_author())
  39. {
  40. $author = new thrid_author\wxauthor();
  41. $url = BASE_SITE_URL . "/mobile/index.php?act=special&op=index&special_id={$special_id}&client_type=wap";
  42. $url = $author->enter($url);
  43. return self::outsuccess(['direct_uri' => $url],"redirect");
  44. }
  45. $ret = $this->pri_special($special_id);
  46. $ret['spitem'] = $spitem;
  47. $tpl_obj = new tpl_ugc($ret);
  48. self::outsuccess(['tpl_obj' => $tpl_obj],'ugc/content');
  49. } else {
  50. $ret = $this->pub_special($special_id);
  51. self::outsuccess($ret);
  52. }
  53. }
  54. }
  55. public function submitOp()
  56. {
  57. $special_id = intval($_GET['special_id']);
  58. $spitem = spid_helper::instance()->special($special_id);
  59. if($special_id < 0 || $spitem == false) {
  60. return self::outerr(errcode::ErrParamter,"该文章不存在");
  61. }
  62. $content = urldecode($_GET['content']);
  63. if(empty($content)) {
  64. $options = false;
  65. }
  66. else {
  67. $options = json_decode($content,true);
  68. if($options == null) $options = false;
  69. }
  70. $result = ugc_helper::submit($special_id,$options,$err);
  71. if($result == false) {
  72. return self::outerr($err['code'],$err['msg']);
  73. }
  74. else
  75. {
  76. $vote_result = $result['vote_result'];
  77. $type_sn = $result['type_sn'];
  78. if(!empty($type_sn)) {
  79. $url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&type_sn={$type_sn}";
  80. $type = bonus\type::create_by_sn($type_sn);
  81. $sender_id = $type->sender_id();
  82. $minfo = new member_info($sender_id);
  83. $avatar = $minfo->avatar();
  84. } else {
  85. $url = "";
  86. $avatar = '';
  87. }
  88. $answer_diff = $result['answer_diff'];
  89. return self::outsuccess(['special_id' => $special_id,
  90. 'vote_result' => $vote_result,
  91. 'answer_diff' => $answer_diff,
  92. 'bonus_url' => $url,
  93. 'num' => $result['num'],
  94. 'amount' => $result['amount'],
  95. 'bonus_type' => $result['bonus_type'],
  96. 'sender_avatar' => $avatar]);
  97. }
  98. }
  99. protected function pub_special($special_id)
  100. {
  101. $specials = special_manager::instance()->special($special_id,$goods_ids,true);
  102. if (!empty($goods_ids))
  103. {
  104. $helper = new goods_helper();
  105. $goodsex = $helper->online_summary($goods_ids, $related_goods);
  106. return array('special_list' => $specials,
  107. 'summary' => $goodsex['summary'],
  108. 'groupbuy' => $goodsex['groupbuy'],
  109. 'limitime' => $goodsex['limitime'],
  110. 'bundling' => $goodsex['bundling'],
  111. 'mobile_page' => mobile_page(1));
  112. }
  113. else
  114. {
  115. return array('special_list' => $specials,
  116. 'summary' => array(),
  117. 'groupbuy' => array(),
  118. 'limitime' => array(),
  119. 'bundling' => array(),
  120. 'mobile_page' => mobile_page(1));
  121. }
  122. }
  123. protected function pri_special($special_id)
  124. {
  125. $result = special_manager::instance()->special($special_id,$goods_ids,false);
  126. if (!empty($goods_ids))
  127. {
  128. $helper = new goods_helper();
  129. $goodsex = $helper->online_summary($goods_ids, $related_goods);
  130. return array('special_list' => $result['specials'],
  131. 'sender_info' => $result['sender_info'],
  132. 'special_info' => $result['special_info'],
  133. 'summary' => $goodsex['summary'],
  134. 'groupbuy' => $goodsex['groupbuy'],
  135. 'limitime' => $goodsex['limitime'],
  136. 'bundling' => $goodsex['bundling'],
  137. 'mobile_page' => mobile_page(1));
  138. }
  139. else
  140. {
  141. return array('special_list' => $result['specials'],
  142. 'sender_info' => $result['sender_info'],
  143. 'special_info' => $result['special_info'],
  144. 'summary' => array(),
  145. 'groupbuy' => array(),
  146. 'limitime' => array(),
  147. 'bundling' => array(),
  148. 'mobile_page' => mobile_page(1));
  149. }
  150. }
  151. }
  152. class tpl_ugc
  153. {
  154. private $spitem;
  155. private $special_list;
  156. private $summary;
  157. private $mem_info;
  158. private $special;
  159. private $mQuestionIndex;
  160. public function __construct($output)
  161. {
  162. $this->mQuestionIndex = 0;
  163. $this->spitem = $output['spitem'];
  164. $this->special_list = $output['special_list'];
  165. $this->summary = $output['summary'];
  166. if(!empty($output['sender_info'])) {
  167. $this->mem_info = new member_info($output['sender_info']);
  168. } else {
  169. $this->mem_info = null;
  170. }
  171. $special_id = $output['special_info']['special_id'];
  172. $mod_special = Model('mb_special');
  173. $special_info = $mod_special->getMbSpecialByID($special_id,'*',true);
  174. if(!empty($special_info)) {
  175. $this->special = new ugc\special($special_info);
  176. } else {
  177. $this->special = null;
  178. }
  179. }
  180. public function preview()
  181. {
  182. return $this->special->preview();
  183. }
  184. public function special_id()
  185. {
  186. return $this->special->special_id();
  187. }
  188. public function title() {
  189. return $this->special->share_title();
  190. }
  191. public function image() {
  192. return $this->special->share_img();
  193. }
  194. public function url() {
  195. $special_id = $this->special_id();
  196. $url = BASE_SITE_URL . "/mobile/index.php?act=special&op=index&special_id={$special_id}&client_type=wap";
  197. return $url;
  198. }
  199. public function sub_title() {
  200. return "熊猫美妆";
  201. }
  202. public function show_title()
  203. {
  204. $title = $this->spitem->share_title();
  205. if(!empty($title))
  206. {
  207. $str = "<div class=\"title\">
  208. <h3>{$title}</h3>
  209. <span class=\"br\"></span>
  210. </div>";
  211. echo $str;
  212. }
  213. }
  214. public function show_sender()
  215. {
  216. if($this->mem_info != null)
  217. {
  218. $nick_name = $this->mem_info->nickname();
  219. $avatar = $this->mem_info->avatar();
  220. $str = "<img src=\"{$avatar}\" alt=\"熊猫美妆\">文/{$nick_name}";
  221. } else {
  222. $str = '';
  223. }
  224. echo $str;
  225. }
  226. public function show_blocks()
  227. {
  228. $this->mQuestionIndex = 0;
  229. foreach ($this->special_list as $block)
  230. {
  231. $item_type = $block['item_type'];
  232. $items = $block['items'];
  233. if($item_type == 'home_ugc' && !empty($items)) {
  234. $this->show_items($items);
  235. }
  236. }
  237. $this->show_submit();
  238. $this->show_appreciate();
  239. $this->show_comment_header();
  240. }
  241. private function show_submit()
  242. {
  243. $vote_single = $this->special->vote_single();
  244. $submitor = new ugc\special_submitor($this->special_id(),$vote_single);
  245. if(!$submitor->submited())
  246. {
  247. $special = $this->special;
  248. $rule = $special->submit_rule();
  249. if($special->has_vote() || $special->has_question())
  250. {
  251. if($special->has_vote() && $special->has_question()) {
  252. $content = "提交";
  253. }
  254. elseif($special->has_vote()) {
  255. $content = "投票";
  256. }
  257. else{
  258. $content = "提交";
  259. }
  260. if($rule != false) {
  261. $content .= " (领红包)";
  262. }
  263. }
  264. else
  265. {
  266. if($rule == false) {
  267. return;
  268. } else {
  269. $content = "领红包";
  270. }
  271. }
  272. if($special->has_over()) {
  273. $str = "<button class=\"button_vote button_null\" id=\"submit_btn\" disabled>{$content} 已过期</button>";
  274. } else {
  275. $str = "<button class=\"button_vote\" id=\"submit_btn\">{$content}</button>";
  276. }
  277. }
  278. else {
  279. $str = "<button class=\"button_vote button_null\" disabled>您已经提交过</button>";
  280. }
  281. echo $str;
  282. }
  283. private function show_comment_header()
  284. {
  285. $str = '';
  286. if(!$this->preview())
  287. {
  288. $str .= '<div class="comment">
  289. <div class="pro">
  290. <div class="pro_title">评论</div>
  291. </div>
  292. <div class="comment_list"></div>
  293. </div>';
  294. }
  295. echo $str;
  296. }
  297. private function show_items($items)
  298. {
  299. foreach ($items as $item)
  300. {
  301. $show_type = $item['show_type'];
  302. if($show_type == 'image') {
  303. $this->show_image($item);
  304. }
  305. elseif($show_type == 'text') {
  306. $this->show_text($item);
  307. }
  308. elseif($show_type == 'vote')
  309. {
  310. $vote_single = $this->special->vote_single();
  311. $submitor = new ugc\special_submitor($this->special_id(),$vote_single);
  312. if($submitor->submited()) {
  313. $this->show_vote_result($item);
  314. } else {
  315. $this->show_vote($item);
  316. }
  317. }
  318. elseif($show_type == 'question') {
  319. $this->show_question($item);
  320. $this->mQuestionIndex++;
  321. }
  322. elseif($show_type == 'goods') {
  323. $this->show_goods($item);
  324. }
  325. else {
  326. }
  327. }
  328. }
  329. private function goods_summary($goods_id)
  330. {
  331. foreach ($this->summary as $summary)
  332. {
  333. if($summary['goods_id'] == $goods_id) {
  334. return $summary;
  335. }
  336. }
  337. return false;
  338. }
  339. private function show_goods($item)
  340. {
  341. $goods_id = intval($item['data']);
  342. $summary = $this->goods_summary($goods_id);
  343. if($summary == false) return;
  344. $recoment = $item['reserved'];
  345. $str = "<div class=\"recommend_goods\">
  346. <div class=\"goods_item\">
  347. <a href=\"\">
  348. <div class=\"goods\">
  349. <div class=\"goods_img\"><img src=\"{$summary['goods_image_url']}\" alt=\"熊猫美妆\"></div>
  350. <div class=\"goods_desc\">
  351. <p class=\"goods_title\">{$summary['goods_mobile_name']}</p>
  352. <p class=\"goods_pro\">{$summary['goods_jingle']}</p>
  353. <p class=\"goods_price\">¥{$summary['goods_price']}</p>
  354. </div>
  355. </div>";
  356. if(!empty($recoment))
  357. {
  358. $str .= "<div class=\"recommend\">
  359. <span class=\"label\">推荐理由:{$recoment}</span><span></span>
  360. </div>";
  361. }
  362. $str .= "</a>
  363. </div>
  364. </div>";
  365. echo $str;
  366. }
  367. private function show_question($item)
  368. {
  369. if(empty($item['data'])) return false;
  370. $options = json_decode($item['data'],true);
  371. $title = $item['title'];
  372. $qindex = $this->mQuestionIndex;
  373. $i = $qindex + 1;
  374. $show_title = "第{$i}题、{$title}";
  375. $reserved = $item['reserved'];
  376. $kv = preg_split('/=/',$reserved);
  377. if(!empty($kv))
  378. {
  379. $k = trim($kv[0]);
  380. $v = trim($kv[1]);
  381. if(!empty($k) && $k == 'answer_type') {
  382. $answer_type = $v;
  383. }
  384. }
  385. $answer_type = intval($answer_type);
  386. if($answer_type == 0) {
  387. $sanswer_type = '单选';
  388. $box = "radio";
  389. }
  390. else {
  391. $sanswer_type = '多选';
  392. $box = "checkbox";
  393. }
  394. $header = "<div class=\"question_list\">
  395. <div class=\"question\">
  396. <div class=\"question_pro\">
  397. <div class=\"question_title\">{$show_title}</div>
  398. <div class=\"question_type\" data-type=\"{$answer_type}\">/{$sanswer_type}</div>
  399. </div>
  400. <div class=\"question_options\">";
  401. $opindex = 65;
  402. $soptions = '';
  403. foreach ($options as $val)
  404. {
  405. $key = $val['id'];
  406. $option = $val['text'];
  407. $si = sprintf("%c",$opindex++);
  408. $soptions .= "<div class=\"question_option\">
  409. <label>
  410. <input type=\"{$box}\" value=\"{$key}\" class=\"check\" name=\"question{$qindex}\">
  411. <span class=\"label\">{$si}、{$option}</span>
  412. </label>
  413. </div>";
  414. }
  415. $end = '</div>
  416. </div>
  417. </div>';
  418. $str = "{$header}{$soptions}{$end}";
  419. echo $str;
  420. }
  421. private function show_vote($item)
  422. {
  423. if(empty($item['data'])) return false;
  424. $options = json_decode($item['data'],true);
  425. if(empty($options)) return false;
  426. $title = $item['title'];
  427. $reserved = $item['reserved'];
  428. $kv = preg_split('/=/',$reserved);
  429. if(!empty($kv))
  430. {
  431. $k = trim($kv[0]);
  432. $v = trim($kv[1]);
  433. if(!empty($k) && $k == 'vote_type') {
  434. $vote_type = $v;
  435. }
  436. }
  437. $vote_type = intval($vote_type);
  438. if($vote_type == 0) {
  439. $svote_type = '单选';
  440. $box = "radio";
  441. }
  442. elseif ($vote_type == 1) {
  443. $svote_type = '多选';
  444. $box = "checkbox";
  445. }
  446. else {
  447. $svote_type = '最多选两项';
  448. $box = "checkbox";
  449. }
  450. $str = "<div class=\"vote\">
  451. <div class=\"vote_pro\">
  452. <div class=\"vote_question\">{$title}</div>
  453. <div class=\"vote_type\" data-type=\"{$vote_type}\">/{$svote_type}</div>
  454. </div>
  455. <div class=\"vote_options\">";
  456. foreach ($options as $val)
  457. {
  458. $key = $val['id'];
  459. $option = $val['text'];
  460. $soption = "<div class=\"vote_option\">
  461. <label>
  462. <input type=\"{$box}\" value=\"{$key}\" class=\"check\" name=\"submit_vote\">
  463. <span class=\"label\">{$option}</span>
  464. </label>
  465. </div>";
  466. $str .= $soption;
  467. }
  468. $str .= '</div>';
  469. $str .= '</div>';
  470. echo $str;
  471. }
  472. private function show_vote_result($item)
  473. {
  474. if(empty($item['data'])) return false;
  475. $options = json_decode($item['data'],true);
  476. if(empty($options)) return false;
  477. $title = $item['title'];
  478. $reserved = $item['reserved'];
  479. $kv = preg_split('/=/',$reserved);
  480. if(!empty($kv))
  481. {
  482. $k = trim($kv[0]);
  483. $v = trim($kv[1]);
  484. if(!empty($k) && $k == 'vote_type') {
  485. $vote_type = $v;
  486. }
  487. }
  488. $vote_type = intval($vote_type);
  489. if($vote_type == 0) {
  490. $svote_type = '单选';
  491. }
  492. elseif ($vote_type == 1) {
  493. $svote_type = '多选';
  494. }
  495. else {
  496. $svote_type = '最多选两项';
  497. }
  498. $str = "<div class=\"vote\">
  499. <div class=\"vote_pro\">
  500. <div class=\"vote_question\">{$title}</div>
  501. <div class=\"vote_type\" data-type=\"{$vote_type}\">/{$svote_type}</div>
  502. </div>";
  503. $str .= '<div class="results">';
  504. $result = $this->special->vote_result();
  505. $total = 0;
  506. foreach ($result as $key => $val) {
  507. $total += $val;
  508. }
  509. foreach ($options as $val)
  510. {
  511. $id = $val['id'];
  512. $title = $val['text'];
  513. $count = $result[$id];
  514. if($total > 0) {
  515. $per = intval($count * 100 / $total + 0.5);
  516. } else {
  517. $per = 0;
  518. }
  519. $option = "<div class=\"result\">
  520. <div class=\"result_option\">{$title}</div>
  521. <div class=\"status\">
  522. <div class=\"status_line\">
  523. <div class=\"stat\"></div>
  524. <div class=\"status_bg\"></div>
  525. </div>
  526. <span class=\"num\">{$count}票</span>
  527. <span class=\"percentage\">{$per}%</span>
  528. </div>
  529. </div>";
  530. $str .= $option;
  531. }
  532. $str .= '</div>';
  533. $str .= '</div>';
  534. echo $str;
  535. }
  536. private function show_text($item)
  537. {
  538. $data = $item['data'];
  539. echo "<article>{$data}</article>";
  540. }
  541. private function show_image($item)
  542. {
  543. $image = $item['show_data'];
  544. $type = $item['type'];
  545. $title = $item['title'];
  546. if($type == 'url')
  547. {
  548. $url = $item['data'];
  549. $str = "<div class=\"thumbnail\">
  550. <a href=\"{$url}\">
  551. <div class=\"thumbnail_image\">
  552. <img src=\"/data/resource/mobile/ugc/images/picLazy_load.png\" data-original=\"{$image}\" alt=\"熊猫美妆\">
  553. </div>
  554. </a>
  555. <div class=\"thumbnail_pro\">{$title}</div>
  556. </div>";
  557. }
  558. elseif($type == 'video')
  559. {
  560. $video = $item['data'];
  561. $str = "<div class=\"thumbnail\">
  562. <div class=\"video_box\" data-poster=\"{$image}\" data-src=\"{$video}\"></div>
  563. <div class=\"thumbnail_pro\">$title</div>
  564. </div>";
  565. }
  566. else
  567. {
  568. $str = "<div class=\"thumbnail\">
  569. <div class=\"thumbnail_image\">
  570. <img src=\"/data/resource/mobile/ugc/images/picLazy_load.png\" data-original=\"{$image}\" alt=\"熊猫美妆\">
  571. </div>
  572. <div class=\"thumbnail_pro\">{$title}</div>
  573. </div>";
  574. }
  575. echo $str;
  576. }
  577. public function show_comments()
  578. {
  579. if($this->preview()) return;
  580. $supporter = new ugc\special_support($this->special_id(),0);
  581. $supported = $supporter->supported();
  582. $str = "<div class=\"bottom_flex\">
  583. <div class=\"msg_btn\">我来说两句</div>";
  584. if($supported) {
  585. $str .= "<a href=\"javascript:void(0)\" class=\"like_btn active\">
  586. <span class=\"like_icon_null like_icon\"></span>
  587. </a>";
  588. } else {
  589. $str .= "<a href=\"javascript:void(0)\" class=\"like_btn active\">
  590. <span class=\"like_icon_null\"></span>
  591. </a>";
  592. }
  593. $str .= "<a href=\"javascript:void(0)\" class=\"comment_label\">
  594. <span class=\"msg_icon_null\"></span>";
  595. $comments = $this->special->comments();
  596. if($comments > 0) {
  597. $str .= "<span class=\"superscript\">{$comments}</span>";
  598. }
  599. $str .= "</a>";
  600. if(session_helper::isapp())
  601. {
  602. $str .= "<a href=\"javascript:void(0)\">
  603. <span class=\"share_icon_null\"></span>
  604. </a>
  605. </div>";
  606. } else {
  607. $str .= "<a href=\" \" class=\"open_app_btn\">打开APP</a></div>";
  608. }
  609. echo $str;
  610. }
  611. private function show_appreciate()
  612. {
  613. $fappreciate = $this->special->has_appreciate();
  614. if($fappreciate == false) return;
  615. $nums = $this->special->appreciates();
  616. $header = "<div class=\"appreciate\">
  617. <p class=\"appreciate_pro\">如果你喜欢该文章,请随意打赏。</p >
  618. <div class=\"appreciate_box\">
  619. <div class=\"btn_appreciate\">";
  620. if($nums > 0)
  621. {
  622. $header .= "赞赏<span class=\"appreciate_num\"> | 已有{$nums}次打赏</span>";
  623. $header .= "</div>
  624. </div>
  625. <div class=\"appreciate_users\">";
  626. $avatars = $this->appreciate_avatars($this->special_id(),20);
  627. $sAvatars = '';
  628. foreach ($avatars as $avatar) {
  629. $sAvatars .= "<img src=\"{$avatar}\">";
  630. }
  631. $header .= $sAvatars;
  632. $header .= '</div>';
  633. if($nums > 20) {
  634. $header .= '<div class="appreciate_label">....超20人赞赏</div>';
  635. }
  636. }
  637. else {
  638. $header .= "赞赏";
  639. $header .= "</div>";
  640. $header .= "</div>";
  641. }
  642. $header .='</div>';
  643. echo $header;
  644. }
  645. private function appreciate_avatars($special_id,$count)
  646. {
  647. $mod = Model('appreciate');
  648. $items = $mod->getTopAppreciate($special_id,'*',$count);
  649. $uids = [];
  650. foreach ($items as $item) {
  651. $uid = intval($item['member_id']);
  652. $uids[] = $uid;
  653. }
  654. $avatars = [];
  655. if(!empty($uids))
  656. {
  657. $mod_member = Model('member');
  658. $mInfos = $mod_member->getMemberList(array('member_id' => ['in',$uids]));
  659. foreach ($mInfos as $info) {
  660. $minfo = new member_info($info);
  661. $avatar = $minfo->avatar();
  662. $avatars[] = $avatar;
  663. }
  664. }
  665. return $avatars;
  666. }
  667. }