123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- /**
- * cms首页
- *
- *
- *
- */
- //use Shopnc\Tpl;
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
- class indexControl extends mobileHomeControl
- {
- private $mb_special;
- const HomeSpecialID = 0;
- public function __construct()
- {
- parent::__construct();
- $this->mb_special = Model('mb_special');
- }
- /**
- * 首页
- */
- public function indexOp()
- {
- if ($_GET['type'] == 'html') {
- $model_mb_special = Model('mb_special');
- $data = $model_mb_special->getMbSpecialIndex();
- $this->_output_special($data, $_GET['type']);
- } else {
- $special_list = $this->mb_special->getMbSpecialItemUsableListByIDEx(self::HomeSpecialID);
- $sale_list = $this->sale_list();
- $this->_output_special(array('special_list' => $special_list, 'sale_list' => $sale_list), $_GET['type']);
- }
- }
- /**
- * 专题
- */
- public function specialOp()
- {
- $model_mb_special = Model('mb_special');
- $special_list = $model_mb_special->getMbSpecialItemUsableListByIDEx($_GET['special_id']);
- $this->_output_special(array('special_list' => $special_list), $_GET['type'], $_GET['special_id']);
- }
- static private function validate_type($type, $data)
- {
- $types = array('keyword', 'special', 'goods', 'url');
- if (empty($type) || !in_array($type, $types)) {
- joutput_error(errcode::ErrSpecial, 'error type.');
- return false;
- }
- $validator = new Validate();
- if ($type === 'special') {
- $validator->setValidate(Validate::verify_number($data, 'special data error.'));
- } elseif ($type === 'keyword') {
- } elseif ($type === 'goods') {
- } else {
- }
- $err = $validator->validate();
- if ($err != '') {
- joutput_error(errcode::ErrSpecial, $err);
- return false;
- } else {
- return true;
- }
- }
- public function advOp()
- {
- $type = $_GET['type'];
- $data = $_GET['data'];
- if (self::validate_type($type, $data) == false) return;
- if ($type === 'special') {
- $ret = $this->mb_special->getMbSpecialItemUsableListByID($data);
- } elseif ($type === 'keyword') {
- } elseif ($type === 'goods') {
- } else {
- }
- joutput_data($ret);
- }
- public function sale_listOp()
- {
- $prefix = 'mb_salelist_content';
- $codeid = 122;
- $ret = rcache($codeid, $prefix);
- if (empty($ret)) {
- $web_code = Model('web_code');
- $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
- if (!empty($result)) {
- $top = $result[0];
- $tops = unserialize($top['code_info']);
- }
- if (empty($tops)) return NULL;
- $ret = array();
- foreach ($tops as $id => $val) {
- $item['id'] = $id;
- //$item['image'] = UPLOAD_SITE_URL. DS.substr($val['img_name'],0,-4);
- $item['image'] = UPLOAD_SITE_URL . DS . $val['img_name'];
- $item['title'] = $val['recommend']['name'];
- $goods_list = $val['goods_list'];
- $item['goods_list'] = array();
- foreach ($goods_list as $goods_val) {
- $goods_val['goods_pic'] = UPLOAD_SITE_URL . DS . $goods_val['goods_pic'];
- array_push($item['goods_list'], $goods_val);
- }
- array_push($ret, $item);
- }
- wcache($codeid, array("salelist_content" => serialize($ret)), $prefix);
- } else {
- $ret = unserialize($ret['salelist_content']);
- }
- joutput_data(array('sale_list' => $ret));
- }
- /**
- * 获取打赏接口数据
- */
- private function sale_list()
- {
- $prefix = 'mb_salelist';
- $codeid = 122;
- $ret = rcache($codeid, $prefix);
- if (empty($ret)) {
- $web_code = Model('web_code');
- $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
- if (!empty($result)) {
- $top = $result[0];
- $tops = unserialize($top['code_info']);
- }
- if (empty($tops)) return NULL;
- $ret = array();
- foreach ($tops as $id => $val) {
- $item = array();
- $item['id'] = $id;
- $img = $val['img_name'];
- if (!empty($img)) {
- //$item['image'] = UPLOAD_SITE_URL. DS. substr($img,0,-4);
- $item['image'] = UPLOAD_SITE_URL . DS . $img;
- $item['title'] = $val['recommend']['name'];
- array_push($ret, $item);
- }
- }
- wcache($codeid, array("salelist" => serialize($ret)), $prefix);
- } else {
- $ret = unserialize($ret['salelist']);
- }
- return $ret;
- }
- /**
- * 输出专题
- */
- private function _output_special($data, $type = 'json', $special_id = 0)
- {
- //$model_special = Model('mb_special');
- if ($type == 'html') {
- //$html_path = $model_special->getMbSpecialHtmlPath($special_id);
- //if(!is_file($html_path)) {
- //ob_start();
- Tpl::output('list', $data['special_list']);
- Tpl::showpage('mb_special');
- //file_put_contents($html_path, ob_get_clean());
- // }
- //header('Location: ' . $model_special->getMbSpecialHtmlUrl($special_id));
- } else {
- if (empty($data)) {
- $data = array();
- }
- joutput_data($data);
- }
- }
- /**
- * android客户端版本号
- */
- public function apk_versionOp()
- {
- $version = C('mobile_apk_version');
- $url = C('mobile_apk');
- if (empty($version)) {
- $version = '';
- }
- if (empty($url)) {
- $url = '';
- }
- output_data(array('version' => $version, 'url' => $url));
- }
- public function show_goodsOp()
- {
- $goods_ids = rkcache('home_goods',true);
- $ret = array_chunk($goods_ids,$this->page_size());
- $pages = count($ret);
- $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
- $goods_ids = $ret[$page_no - 1];
- //所需字段
- $fieldstr = 'goods_id,goods_commonid,store_id,brand_id,gc_id,goods_name,goods_price,goods_marketprice,goods_promotion_price,
- 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';
- $helper = new goods_helper();
- $goods_list = $helper->get_infos($goods_ids,$fieldstr);
- self::outsuccess(array('goods_list' => $goods_list, 'mobile_page' => mobile_page($pages)));
- }
- }
|