index.php 12 KB

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