index.php 11 KB

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