123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?php
- /**
- * cms首页
- *
- *
- *
- */
- //use Shopnc\Tpl;
- defined('InShopNC') or exit('Access Invalid!');
- require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/index_tab.php');
- require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
- require_once(BASE_ROOT_PATH . '/mobile/control/special.php');
- require_once (BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
- require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
- class indexControl extends specialControl
- {
- const HomeSpecialID = 0;
- public function __construct()
- {
- parent::__construct();
- }
- public function tabsOp()
- {
- $tabs = index_tab::instance()->tabs();
- return self::outsuccess(array('tabs' => $tabs));
- }
- public function splashOp()
- {
- $sig = $_GET['sig'];
- $ret = $this->pub_special($this->splash_id());
- if(empty($ret['special_list'])) {
- return self::outsuccess(null);
- }
- $block = $ret['special_list'][0];
- if(empty($block) || empty($block['items'])) {
- return self::outsuccess(null);
- }
- $image = $block['items'][0]['image'];
- if(empty($sig) || $sig != md5($image)) {
- return self::outsuccess(array('sig' => md5($image),'url' => $image));
- } else {
- return self::outsuccess(null);
- }
- }
- private function splash_id()
- {
- if(is_publish()) {
- return 144;
- } else {
- return 38;
- }
- }
- public function inoherbOp()
- {
- return self::outsuccess(['direct_uri' => 'http://p.lrlz.com/hfive/inoherb/index.html?2'],"redirect");
- }
- public function memberOp()
- {
- $relay_id = $_GET['member_id'];
- if(empty($relay_id)) {
- return self::outerr(errcode::ErrParamter);
- }
- if(session_helper::need_wechat_author()) {
- $author = new thrid_author\wxauthor();
- $url = BASE_SITE_URL . "/mobile/index.php?act=index&op=member&member_id={$relay_id}";
- $url = $author->enter($url);
- return self::outsuccess(['direct_uri' => $url],"redirect");
- }
- $relay_id = urldecode($relay_id);
- $relay_id = intval(util::decrypt_data($relay_id));
- if(session_helper::logined())
- {
- $member_id = $_SESSION['member_id'];
- $relateion = new \relation\mem_relation($member_id);
- $isfriend = $relateion->is_follower($relay_id);
- $minfo = new member_info($relay_id);
- return self::outsuccess(array('info' => $minfo,'is_friend' => $isfriend),"member/index",'wap');
- }
- else
- {
- $type_sn = account_helper::invite_bonus($relay_id);
- if($type_sn == false) {
- return self::outerr(errcode::ErrBonus,"生成邀请红包失败.");
- }
- else
- {
- $ref_url = BASE_SITE_URL . "/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn={$type_sn}&relay_id={$relay_id}";
- return self::outsuccess(['direct_uri' => $ref_url],"redirect");
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function homeOp()
- {
- if($this->cur_page == 1) {
- $start = microtime(true);
- $ret = $this->pub_special(self::HomeSpecialID);
- $ret['mobile_page'] = mobile_page(2);
- perfor_period("home",$start,"index");
- return self::outsuccess($ret,"shop/home");
- }
- else
- {
- $goods_ids = activity_helper::recomoned_goodsids();
- $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];
- $helper = new goods_helper();
- $ret = $helper->online_summary($goods_ids,$other_goods);
- $blocks = [];
- $blocks[] = special_formater::format_goods($goods_ids,"热门推荐",$ret['sort_summary']);
- self::outsuccess(array('special_list' => $blocks,
- 'summary' => $ret['summary'],
- 'groupbuy' => $ret['groupbuy'],
- 'limitime' => $ret['limitime'],
- 'bundling' => $ret['bundling'],
- 'mobile_page' => mobile_page($pages + 1)));
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private function old_homeid()
- {
- if(is_publish()) {
- return 61;
- } else {
- return 36;
- }
- }
- public function indexOp()
- {
- $mb_special = Model('mb_special');
- $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($this->old_homeid());
- $sale_list = $this->sale_list();
- return self::outsuccess(array('special_list' => $special_list, 'sale_list' => $sale_list));
- }
- public function indexexOp()
- {
- $helper = new special_formater($this->old_homeid());
- $ret = $helper->format($goods_ids);
- $sale_list = $this->sale_list();
- $helper = new goods_helper();
- $goods_list = $helper->get_infos($goods_ids);
- return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list, 'sale_list' => $sale_list));
- }
- /**
- * 专题
- */
- public function specialOp()
- {
- if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
- return self::outerr(errcode::ErrParamter);
- }
- $mb_special = Model('mb_special');
- $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($_GET['special_id']);
- return self::outsuccess(array('special_list' => $special_list));
- }
- public function specialexOp()
- {
- if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
- return self::outerr(errcode::ErrParamter);
- }
- $special_id = intval($_GET['special_id']);
- $helper = new special_formater($special_id);
- $ret = $helper->format($goods_ids);
- $mod_goods = Model('goods');
- $items = $mod_goods->field('goods_commonid')->where(array('goods_id' => array('in',$goods_ids)))->limit(false)->select();
- $goods_commonids = array();
- foreach ($items as $val) {
- array_push($goods_commonids,intval($val['goods_commonid']));
- }
- $helper = new goods_helper();
- $goods_list = $helper->get_distinct($goods_commonids);
- return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list));
- }
- static private function validate_type($type, $data)
- {
- $types = array('keyword', 'special', 'goods', 'url');
- if (empty($type) || !in_array($type, $types)) {
- return array('code' => errcode::ErrSpecial, 'msg' => '错误的参数.');
- }
- $validator = new Validator();
- if ($type === 'special') {
- $validator->setValidate(Validator::verify_number($data, 'special data error.'));
- } elseif ($type === 'keyword') {
- } elseif ($type === 'goods') {
- } else {
- }
- $err = $validator->validate();
- if ($err != '') {
- return array('code' => errcode::ErrSpecial,'msg' => $err);
- } else {
- return true;
- }
- }
- public function advOp()
- {
- $type = $_GET['type'];
- $data = $_GET['data'];
- $ret = self::validate_type($type, $data);
- if ($ret != true) {
- return self::outerr($ret['code'],$ret['msg']);
- }
- if ($type === 'special') {
- $mb_special = Model('mb_special');
- $ret = $mb_special->getMbSpecialItemUsableListByID($data);
- } elseif ($type === 'keyword') {
- } elseif ($type === 'goods') {
- } else {
- }
- self::outsuccess($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 array();
- $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 . $img;
- $item['title'] = $val['recommend']['name'];
- array_push($ret, $item);
- }
- }
- wcache($codeid, array("salelist" => serialize($ret)), $prefix);
- } else {
- $ret = unserialize($ret['salelist']);
- }
- return $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 . $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']);
- }
- self::outsuccess(array('sale_list' => $ret));
- }
- /**
- * android客户端版本号
- */
- public function apk_versionOp()
- {
- $version = C('mobile_apk_version');
- $url = C('mobile_apk');
- if (empty($version)) {
- $version = '';
- }
- if (empty($url)) {
- $url = '';
- }
- return self::outsuccess(array('version' => $version, 'url' => $url));
- }
- public function show_goodsOp()
- {
- $goods_ids = activity_helper::recomoned_goodsids();
- $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];
- $helper = new goods_helper();
- $goods_list = $helper->get_infos($goods_ids);
- self::outsuccess(array('goods_list' => $goods_list, 'mobile_page' => mobile_page($pages)));
- }
- }
- class tpl_member
- {
- private $mOutput;
- public function __construct($output)
- {
- $this->mOutput = $output;
- }
- public function output_group()
- {
- $minfo = $this->mOutput['info'];
- $amount = $minfo->available_bonus();
- $amount = intval($amount * 100 + 0.5) / 100;
- $discount = $minfo->discount_self();
- $discount = intval($discount * 100 + 0.5) / 100;
- $result = "<div class=\"cell\">
- <span class=\"cell_label\">红包余额</span><span class=\"cell_content\"><span class=\"letter_pro\">$amount</span>元</span>
- </div>
- <div class=\"cell\">
- <span class=\"cell_label\">累计节省</span><span class=\"cell_content\"><span class=\"letter_pro\">$discount</span>元</span>
- </div>";
- if(!session_helper::isapp()) {
- $from = '<div class="cell">
- <span class="cell_label">信息来源</span><span class="cell_content">来自扫一扫</span>
- </div>';
- $result .= $from;
- }
- return $result;
- }
- public function output_btn()
- {
- $is_friend = $this->mOutput['is_friend'];
- if(!session_helper::isapp())
- {
- $result = '<div class="submit">';
- if($is_friend) {
- $result .= '<p class="cell_label">你已经是他的粉丝了</p>';
- } else {
- $result .= '<button type="button" id="btn_add_friend" class="add_friend_btn">关注</button>';
- }
- $result .= '</div>';
- }
- else
- {
- $result = '<div class="submit">
- <button type="button" id="btn_thief_bonus" class="add_friend_btn">偷一点</button>
- </div>
- <div class="submit">
- <button type="button" id="btn_send_bonus" class="send_bonus_btn">发红包</button>
- </div>';
- }
- return $result;
- }
- }
|