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'] = ""; else $msg['msg'] = '未知返回需求!'; unset($info, $data, $base_64); return $msg; } }