Activity.php 32.1 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
<?php
/**
 * tpshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 当燃   2016-05-10
 */

namespace app\mobile\controller;

use think\Db;
use think\Page;
use think\Cookie;
use think\Cache;

class Activity extends MobileBase
{
    public $user_id = 0;
    public $user = array();

    /**
     * 析构流函数
     */
    public function __construct()
    {
        parent::__construct();
        $this->cartLogic = new \app\home\logic\CartLogic();
        if (session('?user')) {
            $user = session('user');
            $user = M('users')->where("user_id", $user['user_id'])->find();
            session('user', $user);  //覆盖session 中的 user
            $this->user = $user;
            $this->user_id = $user['user_id'];
            $this->assign('user', $user); //存储用户信息
            // 给用户计算会员价 登录前后不一样
//            if($user){
//                $user["discount"] = (empty($user["discount"])) ? 1 : $user["discount"];
//                DB::execute("update `__PREFIX__cart` set member_goods_price = goods_price * {$user["discount"]} where (user_id ={$user["user_id"]} or session_id = '{$this->session_id}') and prom_type = 0");
//            }


        }
        $getylpres = getylapp_res(getMobileStoId(), '3');
        if ($getylpres) {
            $this->assign('ylpres', $getylpres);
        }
    }

    public function index()
    {
        return $this->fetch('', getMobileStoId());
    }

    /**
     * 商品详情页
     */
    public function group_fun()
    {

        $stoid = getMobileStoId();
        //form表单提交
        C('TOKEN_ON', true);
        $goodsLogic = new \app\home\logic\GoodsLogic();
        $goods_id = I("get.id/d", 0);
        //$goods = M('Goods')->where("goods_id", $goods_id)->find();
        /*--商品--*/
        $tt = time();
        $goods = M('Goods')
            ->where("goods_id", $goods_id)
            ->where("on_time<" . $tt . " and (down_time>" . $tt . " or down_time=0)")
            ->where('is_on_sale', 1)->find();
        if (empty($goods)) {
            $this->error("此商品已经下架",
                U('Mobile/index/index', array('stoid' => $stoid)));
        }

        /*-----聊天-----*/
        $is_chat = tpCache("basic.is_chat", $stoid);
        $rs_server = M('storage_recharge_detail')
            ->where('store_id', $stoid)->where('admin_id<>0')
            ->where('end_time>' . $tt)
            ->find();
        $this->assign('is_chat', $is_chat && $rs_server);


        //$goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册
        $goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册

        $goods_videos = M('goods_videos')->where("goods_id", $goods_id)
            ->order('video_sort asc')->select(); // 视频
        if ($goods_videos[0])
            $this->assign("goods_videos", $goods_videos);

        $group_buy_info = M('GroupBuy')->where('is_end', 0)->where(['goods_id' => $goods_id, 'start_time' => ['<=', time()], 'end_time' => ['>=', time()]])->find(); // 找出这个商品
        if (empty($group_buy_info)) {
            $this->error("此商品没有团购活动",
                U('Mobile/Goods/goodsInfo', array('id' => $goods_id, 'stoid' => $stoid)));
        }

        $this->buy_page_assign($goods['distr_type']);

        /*---查看是否有秒杀订单超时的订单,以半小时为限---*/
        clear_flash_Order($stoid);

        /*---设置活动是团购销售量---*/
        //$redis = new \Redis();
        //$redis->connect(redisip, 6379);
        $redis = get_redis_handle();
        //$name='grb'.$group_buy_info['id'].'-'.$stoid;
        //$namec='grb'.$group_buy_info['id'].'-'.$stoid.'c';
        $name = get_redis_name($group_buy_info['id'], 2, $stoid);
        $namec = $name . ":c";
        $cval = F($namec);

        if (empty($cval)) {
            for ($i = 0; $i < ($group_buy_info['goods_num'] - $group_buy_info['buy_num']); $i++) {
                $redis->lPush($name, "g" . $i);
            }
            F($namec, 1);
            $len = $redis->lLen($name);
            mlog('shu-' . $len, "group_fun/" . $stoid . "/" . $group_buy_info['id']);
        }
        $len = $redis->lLen($name);
        $this->assign("len", $len);
        $this->assign('stoid', $stoid);


        /*------商品规格--------*/
        $sp1 = trim($goods["goods_spec"]);
        $cn1 = trim($goods["goods_color"]);
        $guige1 = "规格";
        $gorder1 = 1;
        $tgg1 = "";
        if ($sp1 == "" && $cn1 == "") {
            $tgg1 = $guige1 . $gorder1;
            $gorder1++;
        } else if ($sp1 != "" && $cn1 == "") {
            $tgg1 = $sp1;
        } else if ($sp1 == "" && $cn1 != "") {
            $tgg1 = $cn1;
        } else {
            $tgg1 = $sp1 . "/" . $cn1;
        }
        $goods['guige'] = $tgg1;

        if ($goods['brand_id']) {
            $brnad = M('brand')->where("id", $goods['brand_id'])->find();
            $goods['brand_name'] = $brnad['name'];
        }
        if ($goods['nation_id']) {
            $nation = M('nation')->where("id", $goods['nation_id'])->find();
            $goods['nation_name'] = $nation['name'];
        }
        if ($goods['cat_id']) {
            $cat = M('goods_category')->where("id", $goods['cat_id'])->find();
            $goods['cat_name'] = $cat['name'];
        }


        /*----选择门店-----*/
//        $res1 = M("storage_category")->where('store_id', $stoid)->cache("storage_category_" . $stoid, TPSHOP_CACHE_TIME)->select();
//        foreach ($res1 as $k1 => $v1) {
//            $result = M("pick_up")->where("category_id", $v1['cat_id'])->where('isstop<>1')->select();
//            if (empty($result)) {
//                unset($res1[$k1]);
//            } else {
//                $res1[$k1]['list'] = $result;
//            }
//        }
//        $this->assign('store', $res1); //选取门店
//        $this->assign('storejs', json_encode($res1)); //选取门店

        //$prom=get_goods_promotion($goods_id,$this->user_id);
        $prom = get_goods_promotion1($goods, $group_buy_info, $this->user_id);


        $curprice = $goods['shop_price'];
        if ($prom['is_end'] == 2) {
            //$this->error("活动商品已经销售完",
            //U('Mobile/Goods/goodsInfo',array('id'=>$goods_id,'stoid'=>getMobileStoId())));
            $this->assign('prom_num', 0);  //活动设置数量
            $this->assign('onlybuy', 0);  //活动商品还可以买多少件
            $this->assign('limit_num', 0);  //团购每人限购数量
            $this->assign('goods_num', $prom['goods_num']);  //活动设置数量
            $this->assign('onlybuynum', 0);  //活动已经购买数量

        } else if ($prom['is_end'] != 1 && $prom['is_end'] != 4) {
            $curprice = $prom['price'];
            $goods['prom_type'] = $prom['prom_type'];
            $goods['prom_id'] = $prom['prom_id'];

            $this->assign('goods_num', $prom['goods_num']);  //活动设置数量
            $this->assign('onlybuynum', $prom['onlybuy']);  //活动已经购买数量
            $this->assign('limit_num', $prom['buy_limit']);  //团购每人限购数量
        } else {
            //$this->error("此商品没有团购活动",
            //U('Mobile/Goods/goodsInfo',array('id'=>$goods_id,'stoid'=>getMobileStoId())));
            $this->assign('goods_num', 0);  //活动设置数量
            $this->assign('onlybuynum', 0);  //活动已经购买数量
            $this->assign('limit_num', 0);  //团购每人限购数量
        }
        $t = time();
        $prom_order = M("prom_order")
            ->where("store_id", getMobileStoId())
            ->where("start_time<=" . $t)
            ->where("end_time>=" . $t)
            ->where("is_close=0")
            ->where('is_end', 0)
            ->order(" id desc")->limit(5)->select();

        M('Goods')->where("goods_id", $goods_id)->save(array('click_count' => $goods['click_count'] + 1)); // 统计点击数
        $commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计
        $goods_collect_count = M('goods_collect')->where(array("goods_id" => $goods_id))->count(); //商品收藏数
        $this->assign('group_buy_info', $group_buy_info);
        $this->assign('commentStatistics', $commentStatistics);

        $this->assign('goods_images_list', $goods_images_list);
        $this->assign('goods', $goods);
        $this->assign('curprice', $curprice);
        $this->assign('goods_collect_count', $goods_collect_count); //商品收藏人数
        $this->assign('prom_order', $prom_order); //订单活动

        //商品图片
        $imgurl = getImg($goods['original_img'], curHostURL() . NOIMG);
        $msg = $this->img_curl_url($imgurl, 2);
        $shareimg = $msg['data'];
        $this->assign('shareimg', $shareimg);


        //二维码也用64位
        $shareurl = curHostURL() . '/index.php/mobile/goods/goodsInfo/stoid/' . $stoid . '/id/' . $goods_id . "/first_leader/" . $this->user_id;
        $this->assign('shareurl', $shareurl);
        $qc = new \app\home\controller\Index();
        $shareurl = $qc->qr_code_64($shareurl);
        $this->assign('shareurlimg', $shareurl);


        upload_ylp_log('商品详情');
    }


    public function group()
    {
        $this->group_fun();
        return $this->fetch('', getMobileStoId());
    }


    /**
     * 团购活动列表
     */
    public function group_list()
    {
        $istype = I('get.type');
        //以最新新品排序
        if ($istype == 'new') {
            $orderby = 'a.start_time desc';
        } else {
            $orderby = 'a.ordid asc,a.id desc';
        }
        $count = M('GroupBuy')->where('is_end', 0)
            ->where(time() . " >= start_time and " . time() . " <= end_time and store_id=" . getMobileStoId())->count();// 查询满足要求的总记录数
        $pagesize = 10;  //每页显示数
        $Page = new Page($count, $pagesize); // 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();  // 分页显示输出
        $this->assign('page', $show);    // 赋值分页输出

        $p = I("p/d", 1);
        if ($count <= $p * 10) {
            $this->assign('mshow', 0);
        } else {
            $this->assign('mshow', 1);
        }

        $tt = time();

        /*--->where('goods_num>buy_num')--*/
        $list = M('GroupBuy')->alias('a')->join('goods b', 'a.goods_id=b.goods_id', 'left')
            ->where("a.store_id=" . getMobileStoId())
            ->where('a.is_end', 0)
            ->where(time() . " >= a.start_time and " . time() . " <= a.end_time")
            ->where("b.on_time<" . $tt . " and (b.down_time>" . $tt . " or b.down_time=0)")
            ->order($orderby)->limit($Page->firstRow . ',' . $Page->listRows)->field('a.*,b.market_price')->select();   // 找出这个商品
        foreach ($list as $k => $v) {
            $rs = M('goods')->where(array('store_id' => getMobileStoId(), 'goods_id' => $v['goods_id']))->find();
            if ($rs) {
                $list[$k]["original_img"] = $rs['original_img'];
            }


        }
        $this->assign('list', $list);
        if (I('is_ajax')) {
            return $this->fetch('ajax_group_list', getMobileStoId());      //输出分页
        }
        upload_ylp_log('团购活动列表');
        return $this->fetch('', getMobileStoId());
    }


    /**
     * 秒杀活动列表
     */
    public function seckill_list()
    {
        $stype = I('type/d', 1);
        $this->assign('type', $stype);
        upload_ylp_log('秒杀活动列表');
        return $this->fetch("", getMobileStoId());
    }

    /**
     * 秒杀活动列表
     */
    public function ajax_seckill_list()
    {

        $stype = I('type/d', 1);
        $now_time = time();  //当前时间
        $where = " and f.is_end=0";
        /*---当开始时间大于当前时间,就是活动已经开始---*/
        if ($stype == 1) {
            $where = " and f.start_time<" . $now_time;
            $fname = "ajax_seckill_list_1";
        } else {
            $where = " and f.start_time>=" . $now_time;
            $fname = "ajax_seckill_list_2";
        }
        //秒杀商品
        $id = getMobileStoId();
        if (is_int($now_time / 7200)) {      //双整点时间,如:10:00, 12:00
            $start_time = $now_time;
        } else {
            $start_time = floor($now_time / 7200) * 7200; //取得前一个双整点时间
        }
        $end_time = $start_time + 7200;   //结束时间

        $tt = time();
        /*--and f.goods_num>f.buy_num--*/
        $count = DB::name('goods')
            ->alias('g')
            ->join('flash_sale f', 'g.goods_id = f.goods_id', 'inner')->where('is_end', 0)
            ->where("  g.store_id=" . $id . " and g.is_on_sale=1   and f.show_time<" . $now_time . " and f.end_time>" . $now_time . $where)
            ->where("g.on_time<" . $tt . " and (g.down_time>" . $tt . " or g.down_time=0 )")
            ->count();

        //dump("  g.store_id=".$id." and g.is_on_sale=1  and f.goods_num>f.buy_num and f.show_time<".$now_time." and end_time>".$now_time);exit;
        $pagesize = 10;//C('PAGESIZE');  //每页显示数
        $Page = new Page($count, $pagesize); // 实例化分页类 传入总记录数和每页显示的记录数

        $show = $Page->show();  // 分页显示输出
        $this->assign('page', $show);    // 赋值分页输出
        //mlog($Page->firstRow.','.$Page->listRows,"seckill");
        /*and f.goods_num>f.buy_num*/
        $list = DB::name('goods')
            ->alias('g')
            ->join('flash_sale f', 'g.goods_id = f.goods_id', 'inner')->where('is_end', 0)
            ->where(" g.store_id=" . $id . " and g.is_on_sale=1   and f.show_time<" . $now_time . " and f.end_time>" . $now_time . $where)
            ->where("g.on_time<" . $tt . " and (g.down_time>" . $tt . " or g.down_time=0)")
            ->order('f.ordid asc,f.id desc')
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        foreach ($list as $item) {
            $item['cur_num'] = $item['goods_num'] - $item['buy_num'];
            $item['ybuy_num'] = $item['buy_num'] + $item['virtual'];

            if($stype==1){
                $item['buyper'] =100-round(($item['virtual']+$item['buy_num'])/ ($item['goods_num']+$item['virtual'])*100,2);
            }else{
                $item['buyper'] =100;
            }

            $list1[] = $item;
        }

        $this->assign('list', $list1);

        $p = I("p/d", 1);

        if ($count <= $p * 10) {
            $this->assign('mshow', 0);
        } else {
            $this->assign('mshow', 1);
        }
        upload_ylp_log('秒杀活动列表');
        return $this->fetch($fname, getMobileStoId());
    }

    /**
     * 活动商品列表
     */
    public function discount_list()
    {
        $prom_id = I('id');    //活动ID
        $where = array(     //条件
            'prom_type' => 3,
            'prom_id' => $prom_id,
        );
        $pagesize = C('PAGESIZE');  //每页显示数
        $count = M('goods')->where($where)->count(); // 查询满足要求的总记录数
        $Page = new Page($count, $pagesize); //分页类

        $tt = time();
        $prom_list = M('goods')
            ->where("on_time<" . $tt . " and (down_time>" . $tt . " or down_time=0 or down_time='' or down_time is null)")
            ->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select(); //活动对应的商品
        $this->assign('prom_list', $prom_list);
        if (I('is_ajax')) {
            return $this->fetch('ajax_discount_list', getMobileStoId());
        }
        upload_ylp_log('促销优惠活动列表');
        return $this->fetch('', getMobileStoId());
    }

    /**
     * 商品活动页面
     * $author lxl
     * $time 2017-1
     */
    public function promote_goods()
    {
        $now_time = time();
        $where = " start_time <= $now_time and end_time >= $now_time and is_close=0 ";
        $count = M('prom_goods')->where($where)->count();  // 查询满足要求的总记录数
        $pagesize = C('PAGESIZE');  //每页显示数
        $Page = new Page($count, $pagesize); //分页类
        $tt = time();

        $promote = M('prom_goods')->field('id,name,start_time,end_time,prom_img')
            ->where("on_time<" . $tt . " and (down_time>" . $tt . " or down_time=0 or down_time='' or down_time is null)")
            ->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();    //查询活动列表
        $this->assign('promote', $promote);
        if (I('is_ajax')) {
            return $this->fetch('ajax_promote_goods', getMobileStoId());
        }
        upload_ylp_log('促销优惠活动详情');
        return $this->fetch('', getMobileStoId());
    }

    /**
     * 秒杀商品详情
     * * $author lxl
     * $time 2017-1
     */
    public function seckill_fun()
    {

        $stoid = I("stoid/d");
        //form表单提交
        C('TOKEN_ON', true);
        $goodsLogic = new \app\home\logic\GoodsLogic();
        $goods_id = I("get.id/d", 0);
        $tt = time();
        /*--商品--*/
        $goods = M('Goods')
            ->where("on_time<" . $tt . " and (down_time>" . $tt . " or down_time=0)")
            ->where("goods_id", $goods_id)->where('is_on_sale', 1)->find();

        if (empty($goods)) {
            $this->error("此商品已经下架", U('Mobile/index/index', array('stoid' => getMobileStoId())));
        }

        $is_chat = tpCache("basic.is_chat", $stoid);
        $rs_server = M('storage_recharge_detail')
            ->where('store_id', $stoid)->where('admin_id<>0')
            ->where('end_time>' . $tt)
            ->find();
        $this->assign('is_chat', $is_chat && $rs_server);

        $goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->order('ismain desc')->select(); // 商品 图册

        $goods_videos = M('goods_videos')->where("goods_id", $goods_id)
            ->order('video_sort asc')->select(); // 商品 图册
        if ($goods_videos[0])
            $this->assign("goods_videos", $goods_videos);

        $seckill_buy_info = M('flash_sale')->where('is_end', 0)->where(['goods_id' => $goods_id, 'show_time' => ['<=', time()], 'end_time' => ['>=', time()]])->find(); // 找出这个商品
        if (empty($seckill_buy_info)) {
            $this->error("此商品没有秒杀活动",
                U('Mobile/Goods/goodsInfo', array('id' => $goods_id, 'stoid' => getMobileStoId())));
        }

        $this->buy_page_assign($goods['distr_type']);

        /*---查看是否有秒杀订单超时的订单,以半小时为限---*/
        clear_flash_Order($stoid);

        /*---设置活动是秒杀销售量---*/
        //$redis = new \Redis();
        //$redis->connect(redisip, 6379);
        $redis = get_redis_handle();
        //$name='ms'.$seckill_buy_info['id'].'-'.$stoid;
        //$namec='ms'.$seckill_buy_info['id'].'-'.$stoid.'c';
        $name = get_redis_name($seckill_buy_info['id'], 1, $stoid);
        $namec = $name . ":c";

        $cval = F($namec);
        $len = 0;
        if (empty($cval)) {
            for ($i = 0; $i < ($seckill_buy_info['goods_num'] - $seckill_buy_info['buy_num']); $i++) {
                $redis->lPush($name, "m" . $i);
            }
            F($namec, 1);
            $len = $redis->lLen($name);
            mlog('shu-' . $len, "seckill_fun/" . $stoid . "/" . $seckill_buy_info['id']);
        }

        $len = $redis->lLen($name);
        $this->assign("len", $len);
        $this->assign('stoid', $stoid);


        if ($seckill_buy_info['start_time'] > time()) {  //活动进行中
            $this->assign('isyure', 1);
        }
        $user_id = cookie('user_id');
        /*------商品规格--------*/
        $sp1 = trim($goods["goods_spec"]);
        $cn1 = trim($goods["goods_color"]);
        $guige1 = "规格";
        $gorder1 = 1;
        $tgg1 = "";
        if ($sp1 == "" && $cn1 == "") {
            $tgg1 = $guige1 . $gorder1;
            $gorder1++;
        } else if ($sp1 != "" && $cn1 == "") {
            $tgg1 = $sp1;
        } else if ($sp1 == "" && $cn1 != "") {
            $tgg1 = $cn1;
        } else {
            $tgg1 = $sp1 . "/" . $cn1;
        }
        $goods['guige'] = $tgg1;

        if ($goods['brand_id']) {
            $brnad = M('brand')->where("id", $goods['brand_id'])->find();
            $goods['brand_name'] = $brnad['name'];
        }
        if ($goods['nation_id']) {
            $nation = M('nation')->where("id", $goods['nation_id'])->find();
            $goods['nation_name'] = $nation['name'];
        }
        if ($goods['cat_id']) {
            $cat = M('goods_category')->where("id", $goods['cat_id'])->find();
            $goods['cat_name'] = $cat['name'];
        }

        /*----选择门店-----*/
//        $res1 = M("storage_category")->where('store_id', $stoid)->cache("storage_category_" . $stoid, TPSHOP_CACHE_TIME)->select();
//        foreach ($res1 as $k1 => $v1) {
//            $result = M("pick_up")->where("category_id", $v1['cat_id'])->where('isstop<>1')->select();
//            if (empty($result)) {
//                unset($res1[$k1]);
//            } else {
//                $res1[$k1]['list'] = $result;
//            }
//        }
//        $this->assign('store', $res1); //选取门店
//        $this->assign('storejs', json_encode($res1)); //选取门店

        //$prom=get_goods_promotion($goods_id,$this->user_id);
        $prom = get_goods_promotion1($goods, $seckill_buy_info, $this->user_id);
        $curprice = $prom['price'];

        if ($prom['is_end'] == 2) {
            //$this->error("活动商品已经销售完",
            //U('Mobile/Goods/goodsInfo',array('id'=>$goods_id,'stoid'=>getMobileStoId())));
            $this->assign('prom_num', 0);  //活动设置数量
            $this->assign('onlybuy', 0);  //活动商品还可以买多少件
            $this->assign('limit_num', 0);  //秒杀没人限购数量
        } else if ($prom['is_end'] != 1 && $prom['is_end'] != 4) {
            $curprice = $prom['price'];
            $goods['prom_type'] = $prom['prom_type'];
            $goods['prom_id'] = $prom['prom_id'];

            $this->assign('prom_num', $prom['goods_num']);  //活动设置数量
            $this->assign('onlybuy', $prom['onlybuy']);  //活动商品还可以买多少件
            $this->assign('limit_num', $prom['buy_limit']);  //秒杀没人限购数量
        } else {
            //$this->error("此商品秒杀活动的数量已经售完",
            //U('Mobile/Goods/goodsInfo',array('id'=>$goods_id,'stoid'=>getMobileStoId())));
            $this->assign('prom_num', 0);  //活动设置数量
            $this->assign('onlybuy', 0);  //活动商品还可以买多少件
            $this->assign('limit_num', 0);  //秒杀没人限购数量
        }

        $t = time();

        $prom_order = M("prom_order")
            ->where("store_id", getMobileStoId())
            ->where("start_time<=" . $t)
            ->where("end_time>=" . $t)
            ->where("is_close=0")
            ->where('is_end', 0)
            ->order(" id desc")->limit(5)->select();

        M('Goods')->where("goods_id", $goods_id)->save(array('click_count' => $goods['click_count'] + 1)); // 统计点击数
        $commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计
        $goods_collect_count = M('goods_collect')->where(array("goods_id" => $goods_id))->count(); //商品收藏数
//        $this->assign('group_buy_info',$group_buy_info);
        $this->assign('commentStatistics', $commentStatistics);

        $this->assign('goods_images_list', $goods_images_list);
        $this->assign('goods', $goods);
        $this->assign('curprice', $curprice);
        $this->assign('goods_collect_count', $goods_collect_count); //商品收藏人数
        $this->assign('prom_order', $prom_order); //订单活动

        $this->assign('seckill_buy_info', $seckill_buy_info);
        upload_ylp_log('秒杀商品详情');
        $this->assign('act', $seckill_buy_info);
        $this->buy_page_assign($goods['distr_type']);

        //商品图片
        $imgurl = getImg($goods['original_img'], curHostURL() . NOIMG);
        $msg = $this->img_curl_url($imgurl, 2);
        $shareimg = $msg['data'];
        $this->assign('shareimg', $shareimg);


        //二维码也用64位
        $shareurl = curHostURL() . '/index.php/mobile/goods/goodsInfo/stoid/' . $stoid . '/id/' . $goods_id . "/first_leader/" . $this->user_id;
        $this->assign('shareurl', $shareurl);
        $qc = new \app\home\controller\Index();
        $shareurl = $qc->qr_code_64($shareurl);
        $this->assign('shareurlimg', $shareurl);
    }

    public function seckill_info()
    {
        $this->seckill_fun();
        return $this->fetch('', getMobileStoId());
    }

    /*--获取门店排行--20171017--*/
    public function getStorageList()
    {
        $dis = I('distr_type/d');
        $lx = I('lx');
        $ly = I('ly');
        if ($lx != 0 || $ly != 0) {
            session('ulx' . $this->user_id, $lx);
            session('uly' . $this->user_id, $ly);
        }

        $stoid = I('stoid');
        $mindate = [];
        //----------用户的的默认门店------------
        $user_def_sto=mb_get_user_sto($dis,$lx,$ly);

        /*--剔除不显示门店分类底下的门店--*/
        $res0 = M("storage_category")->where('store_id', $stoid)->where('is_show', 0)->field("cat_id")->select();
        $res0 = get_arr_column($res0, 'cat_id');
        $wh = "1=1";
        if (!empty($res0))
            $wh = "category_id not in(" . implode(',', $res0) . ")";

        if ($dis == 0) {
            $where1 = "1=1";
        } else {
            $where1 = "distr_type in(0," . $dis . ")";
        }

        if($lx || $ly){
            $result0 = M("pick_up")->where('store_id', $stoid)->where('isstop=0')->where($wh)->where($where1)
                ->field('*,st_distance (POINT (lat,lon),POINT('.$ly.','.$lx.')) * 111195 AS distance')
                ->order('distance asc,pickup_id asc')
                ->select();
        }else{
            $result0 = M("pick_up")->where('store_id', $stoid)->where('isstop=0')->where($wh)->where($where1)
                ->field("*,'null' AS distance")
                ->order('distance asc,pickup_id asc')
                ->select();
        }

        $count = count($result0);

        if ($count == 0) {
            return json(['code' => -3, 'msg' => '未找到门店', 'is_bline' => 0]);
        }

        //---计算默认一开始的5个门店---
        $def_list=[];
        foreach ($result0 as $k5=>$v5){
            if($k5>4) break;
            $def_list[]=$v5;
        }

        $res1 = M("storage_category")->where('store_id', $stoid)->field("cat_id")->select();
        /*--当数量小于5--*/
        if ($count <= 5 || empty($res1)) {
            return json(['code' => 1, 'msg' => 'ok', 'mini' => $result0,'sto_data' => $result0, 'type' => 1,'user_def_sto'=>$user_def_sto]);
        } else {
            /*----选择门店-----*/
            $res1 = M("storage_category")->where('store_id', $stoid)->where('is_show', 1)
                ->order('sort asc')->cache("storage_category_" . $stoid, TPSHOP_CACHE_TIME)->select();

            foreach ($res1 as $k1 => $v1) {
                $result = [];
                foreach ($result0 as $k => $v) {
                    if ($v1['cat_id'] == $v['category_id']) { $result[] = $v; }
                }
                if (empty($result)) {
                    unset($res1[$k1]);
                } else {
                    $res1[$k1]['list'] = $result;
                }
            }
            return json(['code' => 1, 'msg' => 'ok', 'is_bline' => 0, 'sto_data' => $res1,'def_list'=>$def_list,
                'min' => $def_list[0],'user_def_sto'=>$user_def_sto]);
        }
    }

    //获取当前时间
    public function get_now_time()
    {
        $now = time();
        $dd['code'] = 1;
        $dd['msg'] = $now;
        return json($dd);
    }

    //获取redis长度
    public function rdlen()
    {
        ///index.php/mobile/Activity/rdlen/id
        $id = I("id");
        $stoid = I('stoid');
        //$redis = new \Redis();
        //$redis->connect(redisip, 6379);
        $redis = get_redis_handle();
        //$name='ms'.$id.'-'.$stoid;
        $name = get_redis_name($id, 1, $stoid);

        $len = $redis->lLen($name);
        if ($len == null) $len = 0;

        $d['code'] = 1;
        $d['len'] = $len;
        return json($d);
    }

    //获取团购redis长度
    public function g_rdlen()
    {
        ///index.php/mobile/Activity/g_rdlen/id
        $id = I("id");
        $stoid = I('stoid');
        //$redis = new \Redis();
        //$redis->connect(redisip, 6379);
        $redis = get_redis_handle();
        //$name='grb'.$id.'-'.$stoid;
        $name = get_redis_name($id, 2, $stoid);

        $len = $redis->lLen($name);
        if ($len == null) $len = 0;
        $d['code'] = 1;
        $d['len'] = $len;
        return json($d);
    }

    //  网址图片生成BASE64
    function img_curl_url($url, $type = 0, $timeout = 30)
    {

        $msg = ['code' => 2100, 'status' => 'error', 'msg' => '未知错误!'];
        $imgs = ['image/jpeg' => 'jpeg',
            'image/jpg' => 'jpg',
            'image/gif' => 'gif',
            'image/png' => 'png',
            'text/html' => 'html',
            'text/plain' => 'txt',
            'image/pjpeg' => 'jpg',
            'image/x-png' => 'png',
            'image/x-icon' => 'ico'
        ];
        if (!stristr($url, 'http')) {
            $msg['code'] = 2101;
            $msg['msg'] = 'url地址不正确!';
            return $msg;
        }
        $dir = pathinfo($url);
        //var_dump($dir);
        $host = $dir['dirname'];
        $refer = $host . '/';
        $ch = curl_init($url);
        //不验证https
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        curl_setopt($ch, CURLOPT_REFERER, $refer); //伪造来源地址
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//返回变量内容还是直接输出字符串,0输出,1返回内容
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);//在启用CURLOPT_RETURNTRANSFER的时候,返回原生的(Raw)输出
        curl_setopt($ch, CURLOPT_HEADER, 0); //是否输出HEADER头信息 0否1是
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); //超时时间
        $data = curl_exec($ch);
        //$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
        //$httpContentType = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
        $info = curl_getinfo($ch);
        curl_close($ch);
        $httpCode = intval($info['http_code']);
        $httpContentType = $info['content_type'];
        $httpSizeDownload = intval($info['size_download']);

        if ($httpCode != '200') {
            $msg['code'] = 2102;
            $msg['msg'] = 'url返回内容不正确!';
            return $msg;
        }
        if ($type > 0 && !isset($imgs[$httpContentType])) {
            $msg['code'] = 2103;
            $msg['msg'] = 'url资源类型未知!';
            return $msg;
        }
        if ($httpSizeDownload < 1) {
            $msg['code'] = 2104;
            $msg['msg'] = '内容大小不正确!';
            return $msg;
        }
        $msg['code'] = 200;
        $msg['status'] = 'success';
        $msg['msg'] = '资源获取成功';
        if ($type == 0 or $httpContentType == 'text/html') $msg['data'] = $data;
        $base_64 = base64_encode($data);
        if ($type == 1) $msg['data'] = $base_64;
        elseif ($type == 2) $msg['data'] = "data:{$httpContentType};base64,{$base_64}";
        elseif ($type == 3) $msg['data'] = "<img src='data:{$httpContentType};base64,{$base_64}' />";
        else $msg['msg'] = '未知返回需求!';
        unset($info, $data, $base_64);
        return $msg;
    }
}