index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. class indexControl extends mobileHomeControl
  12. {
  13. private $mb_special;
  14. const HomeSpecialID = 0;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->mb_special = Model('mb_special');
  19. }
  20. /**
  21. * 首页
  22. */
  23. public function indexOp()
  24. {
  25. if ($_GET['type'] == 'html') {
  26. $model_mb_special = Model('mb_special');
  27. $data = $model_mb_special->getMbSpecialIndex();
  28. $this->_output_special($data, $_GET['type']);
  29. } else {
  30. $special_list = $this->mb_special->getMbSpecialItemUsableListByIDEx(self::HomeSpecialID);
  31. $sale_list = $this->sale_list();
  32. $this->_output_special(array('special_list' => $special_list, 'sale_list' => $sale_list), $_GET['type']);
  33. }
  34. }
  35. /**
  36. * 专题
  37. */
  38. public function specialOp()
  39. {
  40. $model_mb_special = Model('mb_special');
  41. $special_list = $model_mb_special->getMbSpecialItemUsableListByIDEx($_GET['special_id']);
  42. $this->_output_special(array('special_list' => $special_list), $_GET['type'], $_GET['special_id']);
  43. }
  44. static private function validate_type($type, $data)
  45. {
  46. $types = array('keyword', 'special', 'goods', 'url');
  47. if (empty($type) || !in_array($type, $types)) {
  48. joutput_error(errcode::ErrSpecial, 'error type.');
  49. return false;
  50. }
  51. $validator = new Validate();
  52. if ($type === 'special') {
  53. $validator->setValidate(Validate::verify_number($data, 'special data error.'));
  54. } elseif ($type === 'keyword') {
  55. } elseif ($type === 'goods') {
  56. } else {
  57. }
  58. $err = $validator->validate();
  59. if ($err != '') {
  60. joutput_error(errcode::ErrSpecial, $err);
  61. return false;
  62. } else {
  63. return true;
  64. }
  65. }
  66. public function advOp()
  67. {
  68. $type = $_GET['type'];
  69. $data = $_GET['data'];
  70. if (self::validate_type($type, $data) == false) return;
  71. if ($type === 'special') {
  72. $ret = $this->mb_special->getMbSpecialItemUsableListByID($data);
  73. } elseif ($type === 'keyword') {
  74. } elseif ($type === 'goods') {
  75. } else {
  76. }
  77. joutput_data($ret);
  78. }
  79. public function sale_listOp()
  80. {
  81. $prefix = 'mb_salelist_content';
  82. $codeid = 122;
  83. $ret = rcache($codeid, $prefix);
  84. if (empty($ret)) {
  85. $web_code = Model('web_code');
  86. $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
  87. if (!empty($result)) {
  88. $top = $result[0];
  89. $tops = unserialize($top['code_info']);
  90. }
  91. if (empty($tops)) return NULL;
  92. $ret = array();
  93. foreach ($tops as $id => $val) {
  94. $item['id'] = $id;
  95. //$item['image'] = UPLOAD_SITE_URL. DS.substr($val['img_name'],0,-4);
  96. $item['image'] = UPLOAD_SITE_URL . DS . $val['img_name'];
  97. $item['title'] = $val['recommend']['name'];
  98. $goods_list = $val['goods_list'];
  99. $item['goods_list'] = array();
  100. foreach ($goods_list as $goods_val) {
  101. $goods_val['goods_pic'] = UPLOAD_SITE_URL . DS . $goods_val['goods_pic'];
  102. array_push($item['goods_list'], $goods_val);
  103. }
  104. array_push($ret, $item);
  105. }
  106. wcache($codeid, array("salelist_content" => serialize($ret)), $prefix);
  107. } else {
  108. $ret = unserialize($ret['salelist_content']);
  109. }
  110. joutput_data(array('sale_list' => $ret));
  111. }
  112. /**
  113. * 获取打赏接口数据
  114. */
  115. private function sale_list()
  116. {
  117. $prefix = 'mb_salelist';
  118. $codeid = 122;
  119. $ret = rcache($codeid, $prefix);
  120. if (empty($ret)) {
  121. $web_code = Model('web_code');
  122. $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
  123. if (!empty($result)) {
  124. $top = $result[0];
  125. $tops = unserialize($top['code_info']);
  126. }
  127. if (empty($tops)) return NULL;
  128. $ret = array();
  129. foreach ($tops as $id => $val) {
  130. $item = array();
  131. $item['id'] = $id;
  132. $img = $val['img_name'];
  133. if (!empty($img)) {
  134. //$item['image'] = UPLOAD_SITE_URL. DS. substr($img,0,-4);
  135. $item['image'] = UPLOAD_SITE_URL . DS . $img;
  136. $item['title'] = $val['recommend']['name'];
  137. array_push($ret, $item);
  138. }
  139. }
  140. wcache($codeid, array("salelist" => serialize($ret)), $prefix);
  141. } else {
  142. $ret = unserialize($ret['salelist']);
  143. }
  144. return $ret;
  145. }
  146. /**
  147. * 输出专题
  148. */
  149. private function _output_special($data, $type = 'json', $special_id = 0)
  150. {
  151. //$model_special = Model('mb_special');
  152. if ($type == 'html') {
  153. //$html_path = $model_special->getMbSpecialHtmlPath($special_id);
  154. //if(!is_file($html_path)) {
  155. //ob_start();
  156. Tpl::output('list', $data['special_list']);
  157. Tpl::showpage('mb_special');
  158. //file_put_contents($html_path, ob_get_clean());
  159. // }
  160. //header('Location: ' . $model_special->getMbSpecialHtmlUrl($special_id));
  161. } else {
  162. if (empty($data)) {
  163. $data = array();
  164. }
  165. joutput_data($data);
  166. }
  167. }
  168. /**
  169. * android客户端版本号
  170. */
  171. public function apk_versionOp()
  172. {
  173. $version = C('mobile_apk_version');
  174. $url = C('mobile_apk');
  175. if (empty($version)) {
  176. $version = '';
  177. }
  178. if (empty($url)) {
  179. $url = '';
  180. }
  181. output_data(array('version' => $version, 'url' => $url));
  182. }
  183. public function show_goodsOp()
  184. {
  185. $goods_ids = rkcache('home_goods',true);
  186. $ret = array_chunk($goods_ids,$this->page_size());
  187. $pages = count($ret);
  188. $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
  189. $goods_ids = $ret[$page_no - 1];
  190. //所需字段
  191. $fieldstr = 'goods_id,goods_commonid,store_id,brand_id,gc_id,goods_name,goods_price,goods_marketprice,goods_promotion_price,
  192. goods_image,goods_salenum,evaluation_good_star,evaluation_count,goods_storage,goods_storage_alarm,is_virtual,is_presell,is_fcode,have_gift,goods_mobile_name,goods_jingle';
  193. $helper = new goods_helper();
  194. $goods_list = $helper->get_infos($goods_ids,$fieldstr);
  195. self::outsuccess(array('goods_list' => $goods_list, 'mobile_page' => mobile_page($pages)));
  196. }
  197. }