index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * cms首页
  4. *
  5. *
  6. *
  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/index_tab.php');
  12. require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
  13. require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  14. require_once(BASE_ROOT_PATH . '/mobile/control/special.php');
  15. require_once (BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
  16. require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
  17. class indexControl extends specialControl
  18. {
  19. const HomeSpecialID = 0;
  20. public function __construct()
  21. {
  22. parent::__construct();
  23. }
  24. public function tabsOp()
  25. {
  26. $tabs = index_tab::instance()->tabs();
  27. return self::outsuccess(array('tabs' => $tabs));
  28. }
  29. public function splashOp()
  30. {
  31. $sig = $_GET['sig'];
  32. $ret = $this->pub_special($this->splash_id());
  33. if(empty($ret['special_list'])) {
  34. return self::outsuccess(null);
  35. }
  36. $block = $ret['special_list'][0];
  37. if(empty($block) || empty($block['items'])) {
  38. return self::outsuccess(null);
  39. }
  40. $image = $block['items'][0]['image'];
  41. if(empty($sig) || $sig != md5($image)) {
  42. return self::outsuccess(array('sig' => md5($image),'url' => $image));
  43. } else {
  44. return self::outsuccess(null);
  45. }
  46. }
  47. private function splash_id()
  48. {
  49. if(is_publish()) {
  50. return 144;
  51. } else {
  52. return 38;
  53. }
  54. }
  55. public function inoherbOp()
  56. {
  57. return self::outsuccess(['direct_uri' => 'http://p.lrlz.com/hfive/inoherb/index.html?2'],"redirect");
  58. }
  59. public function memberOp()
  60. {
  61. $relay_id = $_GET['member_id'];
  62. if(empty($relay_id)) {
  63. return self::outerr(errcode::ErrParamter);
  64. }
  65. if(session_helper::need_wechat_author()) {
  66. $author = new thrid_author\wxauthor();
  67. $url = BASE_SITE_URL . "/mobile/index.php?act=index&op=member&member_id={$relay_id}";
  68. $url = $author->enter($url);
  69. return self::outsuccess(['direct_uri' => $url],"redirect");
  70. }
  71. $relay_id = urldecode($relay_id);
  72. $relay_id = intval(util::decrypt_data($relay_id));
  73. if(session_helper::logined())
  74. {
  75. $member_id = $_SESSION['member_id'];
  76. $relateion = new \relation\mem_relation($member_id);
  77. $isfriend = $relateion->is_follower($relay_id);
  78. $minfo = new member_info($relay_id);
  79. return self::outsuccess(array('info' => $minfo,'is_friend' => $isfriend),"member/index",'wap');
  80. }
  81. else
  82. {
  83. $type_sn = account_helper::invite_bonus($relay_id);
  84. if($type_sn == false) {
  85. return self::outerr(errcode::ErrBonus,"生成邀请红包失败.");
  86. }
  87. else
  88. {
  89. $ref_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}&relay_id={$relay_id}";
  90. return self::outsuccess(['direct_uri' => $ref_url],"redirect");
  91. }
  92. }
  93. }
  94. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  95. public function homeOp()
  96. {
  97. if($this->cur_page == 1) {
  98. $start = microtime(true);
  99. $ret = $this->pub_special(self::HomeSpecialID);
  100. $ret['mobile_page'] = mobile_page(2);
  101. perfor_period("home",$start,"index");
  102. return self::outsuccess($ret,"shop/home");
  103. }
  104. else
  105. {
  106. $goods_ids = activity_helper::recomoned_goodsids();
  107. $ret = array_chunk($goods_ids,$this->page_size());
  108. $pages = count($ret);
  109. $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
  110. $goods_ids = $ret[$page_no - 1];
  111. $helper = new goods_helper();
  112. $ret = $helper->online_summary($goods_ids,$other_goods);
  113. $blocks = [];
  114. $blocks[] = special_formater::format_goods($goods_ids,"热门推荐",$ret['sort_summary']);
  115. self::outsuccess(array('special_list' => $blocks,
  116. 'summary' => $ret['summary'],
  117. 'groupbuy' => $ret['groupbuy'],
  118. 'limitime' => $ret['limitime'],
  119. 'bundling' => $ret['bundling'],
  120. 'mobile_page' => mobile_page($pages + 1)));
  121. }
  122. }
  123. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. private function old_homeid()
  125. {
  126. if(is_publish()) {
  127. return 61;
  128. } else {
  129. return 36;
  130. }
  131. }
  132. public function indexOp()
  133. {
  134. $mb_special = Model('mb_special');
  135. $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($this->old_homeid());
  136. $sale_list = $this->sale_list();
  137. return self::outsuccess(array('special_list' => $special_list, 'sale_list' => $sale_list));
  138. }
  139. public function indexexOp()
  140. {
  141. $helper = new special_formater($this->old_homeid());
  142. $ret = $helper->format($goods_ids);
  143. $sale_list = $this->sale_list();
  144. $helper = new goods_helper();
  145. $goods_list = $helper->get_infos($goods_ids);
  146. return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list, 'sale_list' => $sale_list));
  147. }
  148. /**
  149. * 专题
  150. */
  151. public function specialOp()
  152. {
  153. if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
  154. return self::outerr(errcode::ErrParamter);
  155. }
  156. $mb_special = Model('mb_special');
  157. $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($_GET['special_id']);
  158. return self::outsuccess(array('special_list' => $special_list));
  159. }
  160. public function specialexOp()
  161. {
  162. if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
  163. return self::outerr(errcode::ErrParamter);
  164. }
  165. $special_id = intval($_GET['special_id']);
  166. $helper = new special_formater($special_id);
  167. $ret = $helper->format($goods_ids);
  168. $mod_goods = Model('goods');
  169. $items = $mod_goods->field('goods_commonid')->where(array('goods_id' => array('in',$goods_ids)))->limit(false)->select();
  170. $goods_commonids = array();
  171. foreach ($items as $val) {
  172. array_push($goods_commonids,intval($val['goods_commonid']));
  173. }
  174. $helper = new goods_helper();
  175. $goods_list = $helper->get_distinct($goods_commonids);
  176. return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list));
  177. }
  178. static private function validate_type($type, $data)
  179. {
  180. $types = array('keyword', 'special', 'goods', 'url');
  181. if (empty($type) || !in_array($type, $types)) {
  182. return array('code' => errcode::ErrSpecial, 'msg' => '错误的参数.');
  183. }
  184. $validator = new Validator();
  185. if ($type === 'special') {
  186. $validator->setValidate(Validator::verify_number($data, 'special data error.'));
  187. } elseif ($type === 'keyword') {
  188. } elseif ($type === 'goods') {
  189. } else {
  190. }
  191. $err = $validator->validate();
  192. if ($err != '') {
  193. return array('code' => errcode::ErrSpecial,'msg' => $err);
  194. } else {
  195. return true;
  196. }
  197. }
  198. public function advOp()
  199. {
  200. $type = $_GET['type'];
  201. $data = $_GET['data'];
  202. $ret = self::validate_type($type, $data);
  203. if ($ret != true) {
  204. return self::outerr($ret['code'],$ret['msg']);
  205. }
  206. if ($type === 'special') {
  207. $mb_special = Model('mb_special');
  208. $ret = $mb_special->getMbSpecialItemUsableListByID($data);
  209. } elseif ($type === 'keyword') {
  210. } elseif ($type === 'goods') {
  211. } else {
  212. }
  213. self::outsuccess($ret);
  214. }
  215. /**
  216. * 获取打赏接口数据
  217. */
  218. private function sale_list()
  219. {
  220. $prefix = 'mb_salelist';
  221. $codeid = 122;
  222. $ret = rcache($codeid, $prefix);
  223. if (empty($ret))
  224. {
  225. $web_code = Model('web_code');
  226. $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
  227. if (!empty($result)) {
  228. $top = $result[0];
  229. $tops = unserialize($top['code_info']);
  230. }
  231. if (empty($tops)) return array();
  232. $ret = array();
  233. foreach ($tops as $id => $val) {
  234. $item = array();
  235. $item['id'] = $id;
  236. $img = $val['img_name'];
  237. if (!empty($img)) {
  238. $item['image'] = UPLOAD_SITE_URL . DS . $img;
  239. $item['title'] = $val['recommend']['name'];
  240. array_push($ret, $item);
  241. }
  242. }
  243. wcache($codeid, array("salelist" => serialize($ret)), $prefix);
  244. } else {
  245. $ret = unserialize($ret['salelist']);
  246. }
  247. return $ret;
  248. }
  249. public function sale_listOp()
  250. {
  251. $prefix = 'mb_salelist_content';
  252. $codeid = 122;
  253. $ret = rcache($codeid, $prefix);
  254. if (empty($ret))
  255. {
  256. $web_code = Model('web_code');
  257. $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
  258. if (!empty($result)) {
  259. $top = $result[0];
  260. $tops = unserialize($top['code_info']);
  261. }
  262. if (empty($tops)) return NULL;
  263. $ret = array();
  264. foreach ($tops as $id => $val) {
  265. $item['id'] = $id;
  266. $item['image'] = UPLOAD_SITE_URL . DS . $val['img_name'];
  267. $item['title'] = $val['recommend']['name'];
  268. $goods_list = $val['goods_list'];
  269. $item['goods_list'] = array();
  270. foreach ($goods_list as $goods_val) {
  271. $goods_val['goods_pic'] = UPLOAD_SITE_URL . DS . $goods_val['goods_pic'];
  272. array_push($item['goods_list'], $goods_val);
  273. }
  274. array_push($ret, $item);
  275. }
  276. wcache($codeid, array("salelist_content" => serialize($ret)), $prefix);
  277. } else {
  278. $ret = unserialize($ret['salelist_content']);
  279. }
  280. self::outsuccess(array('sale_list' => $ret));
  281. }
  282. /**
  283. * android客户端版本号
  284. */
  285. public function apk_versionOp()
  286. {
  287. $version = C('mobile_apk_version');
  288. $url = C('mobile_apk');
  289. if (empty($version)) {
  290. $version = '';
  291. }
  292. if (empty($url)) {
  293. $url = '';
  294. }
  295. return self::outsuccess(array('version' => $version, 'url' => $url));
  296. }
  297. public function show_goodsOp()
  298. {
  299. $goods_ids = activity_helper::recomoned_goodsids();
  300. $ret = array_chunk($goods_ids,$this->page_size());
  301. $pages = count($ret);
  302. $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
  303. $goods_ids = $ret[$page_no - 1];
  304. $helper = new goods_helper();
  305. $goods_list = $helper->get_infos($goods_ids);
  306. self::outsuccess(array('goods_list' => $goods_list, 'mobile_page' => mobile_page($pages)));
  307. }
  308. }
  309. class tpl_member
  310. {
  311. private $mOutput;
  312. public function __construct($output)
  313. {
  314. $this->mOutput = $output;
  315. }
  316. public function output_group()
  317. {
  318. $minfo = $this->mOutput['info'];
  319. $amount = $minfo->available_bonus();
  320. $amount = intval($amount * 100 + 0.5) / 100;
  321. $discount = $minfo->discount_self();
  322. $discount = intval($discount * 100 + 0.5) / 100;
  323. $result = "<div class=\"cell\">
  324. <span class=\"cell_label\">红包余额</span><span class=\"cell_content\"><span class=\"letter_pro\">$amount</span>元</span>
  325. </div>
  326. <div class=\"cell\">
  327. <span class=\"cell_label\">累计节省</span><span class=\"cell_content\"><span class=\"letter_pro\">$discount</span>元</span>
  328. </div>";
  329. if(!session_helper::isapp()) {
  330. $from = '<div class="cell">
  331. <span class="cell_label">信息来源</span><span class="cell_content">来自扫一扫</span>
  332. </div>';
  333. $result .= $from;
  334. }
  335. return $result;
  336. }
  337. public function output_btn()
  338. {
  339. $is_friend = $this->mOutput['is_friend'];
  340. if(!session_helper::isapp())
  341. {
  342. $result = '<div class="submit">';
  343. if($is_friend) {
  344. $result .= '<p class="cell_label">你已经是他的粉丝了</p>';
  345. } else {
  346. $result .= '<button type="button" id="btn_add_friend" class="add_friend_btn">关注</button>';
  347. }
  348. $result .= '</div>';
  349. }
  350. else
  351. {
  352. $result = '<div class="submit">
  353. <button type="button" id="btn_thief_bonus" class="add_friend_btn">偷一点</button>
  354. </div>
  355. <div class="submit">
  356. <button type="button" id="btn_send_bonus" class="send_bonus_btn">发红包</button>
  357. </div>';
  358. }
  359. return $result;
  360. }
  361. }