Template.php 19.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
<?php
/**
 * Created by PhpStorm.
 * User: wxd1061
 * Date: 2017-07-26
 * Time: 14:05
 */
namespace app\mobile\controller;
use think\Controller;
use think\Db;
use think\Page;

class Template extends MobileBase{
    /*
   * 初始化操作
   */
    public function _initialize()
    {
        parent::_initialize();
        $stoid=I('stoid/d',1);

        $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
        $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
        $this->assign('rank_switch',$rank_switch);
        $this->assign('mz_switch',$mz_switch);

        /*--制作自定义导航--*/
        $ms=M('store_footer')->where('store_id',getMobileStoId())->field('id')
            ->where('is_use',1)->find();
        if($ms){
            $pa='/public/template/footer/'.getMobileStoId().'/'.$ms['id'].'.html';
            if(!file_exists(ROOT_PATH.$pa))
            { $pa="public/empty";}
            else{
                $pa=".".$pa;
            }
            $this->assign('fcustom_footer', $pa);
        }else{
            $this->assign('fcustom_footer', 'public/empty');
        }
    }

    public function template()
    {
        $stoid=getMobileStoId();
//        if($stoid!=1 && $stoid!=23 && $stoid!=39) {
//            if (!strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
//                echo " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0\" /><p style='width: 100%; margin: 0 auto;max-width: 720px; font-size: 18px; padding-top: 10px;  text-align:center'>请在微信浏览器中打开!<p>";
//                die;
//
//            }
//        }

        //delFile2(TEMP_PATH . "/" . getAdmStoId());

        $stoid=I('stoid');
        $sn = I('sn');
        $rm=M('store_module')->where('template_sn',$sn)->where('store_id',$stoid)->find();
        $title=$rm['page_title'];
        $descr=$rm['page_describe'];
        /*--文件路径--*/
        $p="./public/template/feature/".$stoid.'/'.$sn.".html";
        $bk=$rm['bkcolor'];

        if(!file_exists(ROOT_PATH."/public/template/feature/".$stoid.'/'.$sn.".html")){
            echo "<p style='width: 100%; margin: 0 auto;max-width: 720px; font-size: 18px;'>未找到模板文件!<p>";
            return;
        }


        $user = session('user');
        $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
        $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
        $this->assign('rank_switch',$rank_switch);
        $this->assign('mz_switch',$mz_switch);
        if (!empty($rank_switch)){
            $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
            $card_field=$user['card_field'];
            if($rand_end>0){
                $card_field=$rand_end>time()?$user['card_field']:0;
            }
            $this->assign('rank_field',$user['card_field']);

            //----读取等级卡标签---
            $all_card=get_plus_price_arr($stoid);
            if($all_card) {
                $this->assign('all_card',$all_card);
                foreach ($all_card as $kl => $vl) {
                    if ($vl) {
                        switch ($vl['CorrPrice']) {
                            case "Price1":
                                $new_card_dd['cardprice1'] = $vl['CardName'];
                                break;
                            case "Price2":
                                $new_card_dd['cardprice2'] = $vl['CardName'];
                                break;
                            case "Price3":
                                $new_card_dd['cardprice3'] = $vl['CardName'];
                                break;
                        }
                    }
                }
                $card_label = $new_card_dd[$card_field];

                $len = mb_strlen($card_label, "utf-8");
                if ($len > 4)
                    $card_label = mb_substr($card_label, 0, 4, "utf-8");
                $this->assign('card_label', $card_label);
            }
        }
        if (!empty($mz_switch)){
            $this->assign('mz_vip',$user['is_mzvip']);
        }

        $this->assign('p', $p);
        $this->assign('title', $title);
        $this->assign('descr', $descr);
        $this->assign('bk', $bk);
        $this->assign('isright', $rm['isright']);
        $this->assign('moddesc',$rm['page_describe']);


        if(empty($stoid))
           return $this->fetch();
        else
           return $this->fetch("",$stoid,0);
    }

    public function manatemplate()
    {

        /*--删除手机展示缓存--*/
        delFile2(TEMP_PATH."/manager_template");
        $sn = I('sn');
        $rm=M('store_module')->where('template_sn',$sn)->find();
        $title=$rm['page_title'];
        $descr=$rm['page_describe'];
        /*--文件路径--*/
        $p="./public/template/feature/".$sn.".html";
        $str=$p;
        $this->assign('str', $str);
        $this->assign('title', $title);
        $this->assign('descr', $descr);
        $this->assign('isright', $rm['isright']);

        $bk=$rm['bkcolor'];
        $this->assign('bk', $bk);

        return $this->fetch("","manager_template");

    }


    public function s_manatemplate()
    {
        if (!strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
            echo " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0\" /><p style='width: 100%; margin: 0 auto;max-width: 720px; font-size: 18px; padding-top: 10px;  text-align:center'>请在微信浏览器中打开!<p>";
            die;

        }

        /*--删除手机展示缓存--*/
        delFile2(TEMP_PATH."/manager_template");
        $sn = I('sn');
        $rm=M('store_module')->where('template_sn',$sn)->find();
        $title=$rm['page_title'];
        $descr=$rm['page_describe'];
        /*--文件路径--*/
        $p="./public/template/feature/".$sn.".html";
        $str=$p;
        $this->assign('str', $str);
        $this->assign('title', $title);
        $this->assign('descr', $descr);
        $this->assign('isright', $rm['isright']);

        $bk=$rm['bkcolor'];
        $this->assign('bk', $bk);
        return $this->fetch("manatemplate",'manager_template',0);

    }



    /*------------------------加载更多的control方法--------------------*/
    /*--商品分组,手动选择--*/
    public function getmoreid(){
       /*--第几页,限制多少条---*/
       $p=I("p/d");
       $limit=I('lim/d');
       $stoid=I('stoid/d',1);
       $colnum=I('col/d');

       $goodstit=I('isgoodstit');
       $goodsprice=I('isgoodsprice');
       $goodsnum=I('isgoodsnum');
       $goodicon=I('tgoodicon/d');
       $styleicon=I('tstyleicon/d');
       $customicon=I('customiconurl');
       $position=I('tposition/d');
	   $noboder=I('noboder/d');

        $user = session('user');
        $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
        $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
        $this->assign('rank_switch',$rank_switch);
        $this->assign('mz_switch',$mz_switch);
        if (!empty($rank_switch)){
            $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
            $card_field=$user['card_field'];
            if($rand_end>0){
                $card_field=$rand_end>time()?$user['card_field']:0;
            }
            $this->assign('rank_field',$user['card_field']);

            //----读取等级卡标签---
            $all_card=get_plus_price_arr($stoid);
            if($all_card) {
                $this->assign('all_card',$all_card);
                foreach ($all_card as $kl => $vl) {
                    if ($vl) {
                        switch ($vl['CorrPrice']) {
                            case "Price1":
                                $new_card_dd['cardprice1'] = $vl['CardName'];
                                break;
                            case "Price2":
                                $new_card_dd['cardprice2'] = $vl['CardName'];
                                break;
                            case "Price3":
                                $new_card_dd['cardprice3'] = $vl['CardName'];
                                break;
                        }
                    }
                }
                $card_label = $new_card_dd[$card_field];

                $len = mb_strlen($card_label, "utf-8");
                if ($len > 4)
                    $card_label = mb_substr($card_label, 0, 4, "utf-8");
                $this->assign('card_label', $card_label);
            }
        }
        if (!empty($mz_switch)){
            $this->assign('mz_vip',$user['is_mzvip']);
        }


	   

       /*--id集合--*/
       $idlist=I("idl");
       $arr =explode(",",$idlist);
       $mc=M("goods")->where("goods_id in($idlist) and is_on_sale=1 and store_id=".$stoid)->count('goods_id');
       /*---给数组加数据,同时剔除下架的商品---*/
       $marr=M("goods")->where("goods_id in($idlist) and store_id=".$stoid)->select();
       $arrtemp=[];
       $isshow=0;
       if($marr) {
           foreach ($arr as $k => $v) {
              foreach ($marr as $kk => $vv) {
                 if ($v == $vv['goods_id']) {
                    if($vv['is_on_sale']==1){
                        $arrtemp[] = $vv;
                    }
                    break;
                 }
              }
           }
           /*---判断是否还有更多按钮---*/
           $end=$mc;
           if($mc > $p*$limit){
               $isshow=1; $end=$p*$limit;
           }
           $fir=($p-1)*$limit;
           for($o=$fir;$o<$end;$o++){
               $narr[]= $arrtemp[$o];
           }

           $this->assign('data',$narr);
           $this->assign('colnum',$colnum);
           $this->assign('goodstit',$goodstit);
           $this->assign('goodsprice',$goodsprice);
           $this->assign('goodsnum',$goodsnum);
           $this->assign('goodicon',$goodicon);
           $this->assign('styleicon',$styleicon);
           $this->assign('customicon',$customicon);
           $this->assign('position',$position);
		   $this->assign('noboder',$noboder);

           $htm = $this->fetch("ajax_getmoreid", $stoid);
           return json(['code'=>1,'isshow'=>$isshow,'htm'=>$htm]);
       }else{
           return json(['code'=>-1,'isshow'=>$isshow]);
       }
    }

    /*---更多商品分类---*/
    public function getmorecatetype()
    {
        /*--第几页,限制多少条---*/
        $p=I("p/d");
        $limit=I('lim/d');

        $goodsclass=I('tgoodsclass/d',0);
        $stoid=I('stoid/d',1);
        $colnum=I('col/d');
        $goodstit=I('isgoodstit');
        $goodsprice=I('isgoodsprice');
        $goodsnum=I('isgoodsnum');
        $goodicon=I('tgoodicon/d');
        $styleicon=I('tstyleicon/d');
        $customicon=I('customiconurl');
        $position=I('tposition/d');
		$noboder=I('noboder/d');

        $user = session('user');
        $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
        $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
        $this->assign('rank_switch',$rank_switch);
        $this->assign('mz_switch',$mz_switch);
        if (!empty($rank_switch)){
            $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
            $card_field=$user['card_field'];
            if($rand_end>0){
                $card_field=$rand_end>time()?$user['card_field']:0;
            }
            $this->assign('rank_field',$user['card_field']);

            //----读取等级卡标签---
            $all_card=get_plus_price_arr($stoid);
            if($all_card) {
                $this->assign('all_card',$all_card);
                foreach ($all_card as $kl => $vl) {
                    if ($vl) {
                        switch ($vl['CorrPrice']) {
                            case "Price1":
                                $new_card_dd['cardprice1'] = $vl['CardName'];
                                break;
                            case "Price2":
                                $new_card_dd['cardprice2'] = $vl['CardName'];
                                break;
                            case "Price3":
                                $new_card_dd['cardprice3'] = $vl['CardName'];
                                break;
                        }
                    }
                }
                $card_label = $new_card_dd[$card_field];

                $len = mb_strlen($card_label, "utf-8");
                if ($len > 4)
                    $card_label = mb_substr($card_label, 0, 4, "utf-8");
                $this->assign('card_label', $card_label);
            }
        }
        if (!empty($mz_switch)){
            $this->assign('mz_vip',$user['is_mzvip']);
        }

        $where = " is_on_sale=1";
        switch ($goodsclass) {
            case 1://推荐
                $where .= " and is_recommend=1";
                break;
            case 2://热销
                $where .= " and is_hot=1";
                break;
            case 3://新品
                $where .= " and is_new=1";
                break;
            case 4://促销
                $where .= " and prom_type=3";
                break;
        };

        $t=time();

        $mc=M("goods")->where($where)
           ->where(' on_time<' . $t . ' and (down_time>' . $t . ' or down_time=0)')
           ->where("store_id = ".$stoid)->count("goods_id");


        /*---判断是否还有更多按钮---*/
        $isshow=0;
        if($mc>$p*$limit){ $isshow=1; }
        $fir=($p-1)*$limit;
        $str=''.$fir.','.$limit.'';


        $narr=M("goods")->where($where) ->where("store_id=".$stoid)
           ->where(' on_time<' . $t . ' and (down_time>' . $t . ' or down_time=0)')
           ->limit($str)->order("sort")->select();

        if($narr) {
            $this->assign('data', $narr);
            $this->assign('colnum',$colnum);
            $this->assign('goodstit',$goodstit);
            $this->assign('goodsprice',$goodsprice);
            $this->assign('goodsnum',$goodsnum);
            $this->assign('goodicon',$goodicon);
            $this->assign('styleicon',$styleicon);
            $this->assign('customicon',$customicon);
            $this->assign('position',$position);
			$this->assign('noboder',$noboder);

            $htm = $this->fetch("ajax_getmoreid", $stoid);
            return json(['code' => 1, 'isshow' => $isshow, 'htm' => $htm]);
        }else{
            return json(['code'=>-1,'isshow'=>$isshow]);
        }

    }

    /*--商品分组--*/
    public function getmoregroup(){
        /*--第几页,限制多少条---*/
        $p=I("p/d");
        $limit=I('lim/d');
        $stoid=I('stoid/d',1);
        $colnum=I('col/d');
        $goodstit=I('isgoodstit');
        $goodsprice=I('isgoodsprice');
        $goodsnum=I('isgoodsnum');
        $goodicon=I('tgoodicon/d');
        $styleicon=I('tstyleicon/d');
        $customicon=I('customiconurl');
        $position=I('tposition/d');
		$noboder=I('noboder/d');

        $user = session('user');
        $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格
        $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格
        $this->assign('rank_switch',$rank_switch);
        $this->assign('mz_switch',$mz_switch);
        if (!empty($rank_switch)){
            $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']);
            $card_field=$user['card_field'];
            if($rand_end>0){
                $card_field=$rand_end>time()?$user['card_field']:0;
            }
            $this->assign('rank_field',$user['card_field']);

            //----读取等级卡标签---
            $all_card=get_plus_price_arr($stoid);
            if($all_card) {
                $this->assign('all_card',$all_card);
                foreach ($all_card as $kl => $vl) {
                    if ($vl) {
                        switch ($vl['CorrPrice']) {
                            case "Price1":
                                $new_card_dd['cardprice1'] = $vl['CardName'];
                                break;
                            case "Price2":
                                $new_card_dd['cardprice2'] = $vl['CardName'];
                                break;
                            case "Price3":
                                $new_card_dd['cardprice3'] = $vl['CardName'];
                                break;
                        }
                    }
                }
                $card_label = $new_card_dd[$card_field];

                $len = mb_strlen($card_label, "utf-8");
                if ($len > 4)
                    $card_label = mb_substr($card_label, 0, 4, "utf-8");
                $this->assign('card_label', $card_label);
            }
        }
        if (!empty($mz_switch)){
            $this->assign('mz_vip',$user['is_mzvip']);
        }


        /*--id集合--*/
        $grid=I("tgrid");
        $gr=M("goods_group")->where("gpid=".$grid." and store_id=".$stoid)->find();
        $idlist=$gr['gp_goodslist'];
        $t=time();

        $arr =explode(",",$idlist);
        $mc=M("goods")->where("goods_id in(".$idlist.") and is_on_sale=1 and store_id=".$stoid)
            ->where(' on_time<' . $t . ' and (down_time>' . $t . ' or down_time=0)')
            ->count('goods_id');

        /*---给数组加数据,同时剔除下架的商品---*/
        $marr=M("goods")->where("goods_id in(".$idlist.") and store_id=".$stoid)
            ->where(' on_time<' . $t . ' and (down_time>' . $t . ' or down_time=0)')
            ->select();
        $arrtemp=[];

        $isshow=0;
        if($marr) {
            foreach ($marr as $k => $v) {
                foreach ($arr as $kk => $vv) {
                    if ($vv == $v[goods_id]) {
                        if($v[is_on_sale]==1){
                            $arrtemp[] = $v;
                        }
                        break;
                    }
                }
            }
            /*---判断是否还有更多按钮---*/
            $end=$mc;
            if($mc>$p*$limit){
                $isshow=1; $end=$p*$limit;
            }
            $fir=($p-1)*$limit;
            for($o=$fir;$o<$end;$o++){
                $narr[]= $arrtemp[$o];
            }

            $this->assign('data',$narr);
            $this->assign('colnum',$colnum);
            $this->assign('goodstit',$goodstit);
            $this->assign('goodsprice',$goodsprice);
            $this->assign('goodsnum',$goodsnum);
            $this->assign('goodicon',$goodicon);
            $this->assign('styleicon',$styleicon);
            $this->assign('customicon',$customicon);
            $this->assign('position',$position);
			$this->assign('noboder',$noboder);

            $htm = $this->fetch("ajax_getmoreid", $stoid);
            return json(['code'=>1,'isshow'=>$isshow,'htm'=>$htm]);
        }else{
            return json(['code'=>-1,'isshow'=>$isshow]);
        }

    }

   /*--导航预览--*/
    public function nav_template()
    {
        $stoid=I('stoid');
        /*--文件路径--*/
        $p="./public/template/footer/sfooter.html";
        $this->assign('p', $p);
        $this->assign('title', "导航预览");
        $this->assign('descr', "导航预览");
        $this->assign('bk', "#f8f8f8");
        if(empty($stoid))
            return $this->fetch();
        else
            return $this->fetch("",$stoid);
    }


}