index.php 11 KB

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