index.php 12 KB

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