cartLogic = new \app\home\logic\CartLogic(); $nuser=array( 'Cart3_team_nosub', 'Cart3_team', ); if(session('?user')) { if (!in_array(ACTION_NAME, $nuser)) { $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); //存储用户信息 // 给用户计算会员价 登录前后不一样 }else{ $user = session('user'); $this->user = $user; $this->user_id = $user['user_id']; $this->assign('user', $user); //存储用户信息 } } // $ylpapp_list=M('store_config')->where('store_id='.getMobileStoId())->find();//app使用 // $ylpapp_list=$ylpapp_list['ylpapp_list']; $getylpres=getylapp_res(getMobileStoId(),'3'); if ($getylpres) { $this->assign('ylpres',$getylpres); } $nologin = array( 'goodsInfo','team_info','team_fun','buy_points','team_success','teamshow','every_body_team','ajax_team_list' ); if (!$this->user_id && !in_array(ACTION_NAME, $nologin)) { $this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId()))); exit; } if (!in_array(ACTION_NAME, $nologin)) { if (($this->pm_erpid && (!$user || !$user['erpvipid'] || !$user['erpvipno']) || ($this->pm_erpid && (!$user || !$user['mobile'])))) { $this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId()))); exit; } } } /** * 参团只针对参团,ajax将商品加入购物车 */ public function addcart_pt() { //删除wxd_cart中立即购买的数量 M('cart')->where('user_id',$this->user_id) ->where('store_id',getMobileStoId()) ->where('state<>0')->delete(); $this->cartLogic = new \app\home\logic\CartLogic(); $goods_id = I("goods_id/d"); // 商品id $goods_num = I("goods_num/d");// 商品数量 $goods_spec = I("goods_spec/a", array()); // 商品规格 $pick_up = I("pickup_id/d"); //获取门店id if ($this->user_id == 0) { return array('status' => -101, 'msg' => '非法操作', 'result' => ''); } //在加入购物车要判断是否满团 $teamid=I('teamid'); $team_qh=I("team_qh"); $stoid=I('stoid'); $teamact = M('teamlist')->where('id', $teamid)->where('store_id', $stoid)->find(); if($team_qh ) { $ordract = M('order')->where('pay_time>0')->where('order_status<>3') ->where('pt_prom_id', $teamid)->where('pt_listno',$team_qh) ->where('store_id', $stoid)->count(); //如果团的人数已经满 if($ordract>=$teamact['ct_num'] && $teamact['kttype']==2){ return array('status' => -101, 'msg' => '该团人数已经满团', 'result' => ''); } } //判断团的时间 $tgr=M('teamgroup')->where('listno',$team_qh)->where('team_id',$teamid)-> where('store_id',$stoid)->find(); $etime=strtotime("+".$teamact['kt_time']." hour",$tgr['buystartdate']); if($etime<=time()){ return array('status' => -101, 'msg' => '该团已经结束', 'result' => ''); } $result =null; $user_id = $this->user_id; $pickup_id=$pick_up; if ($user_id == 0) return array('status' => -101, 'msg' => '购买商品必须先登录', 'result' => ''); if ($goods_num <= 0) return array('status' => -2, 'msg' => '购买商品数量不能为0', 'result' => ''); if (empty($pickup_id)) { return array('status' => -2, 'msg' => '取货门店不能为空', 'result' => ''); } $t=time(); /*查找商品*/ $goods = M('Goods') ->where("on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='' or down_time is null)") ->where("goods_id", $goods_id)->where('is_on_sale', 1)->find(); // 找出这个商品 if (empty($goods)) return array('status' => -3, 'msg' => '购买商品不存在或者已下架', 'result' => ''); //判断库存 if (($goods_num + $goods_num) > $goods['store_count']) { return array('status' => -4, 'msg' => "库存不足", 'result' => ''); } $where = " goods_id = :goods_id"; $cart_bind['goods_id'] = $goods_id; if ($user_id > 0) { $where .= " and (user_id = :user_id) "; $cart_bind['user_id'] = $user_id; } //核查用户购买数量 $where = "user_id = :user_id and order_status in(0,1,2,4,6) and pt_status=1 and add_time>" . $teamact['start_time'] . " and add_time<" . $teamact['end_time']; $order_id_arr = M('order')->where($where)->bind(['user_id' => $user_id])->getField('order_id', true); $onlybuy=$teamact['goods_num']-$teamact['buy_num']; if ($order_id_arr) { $goods_num1 = M('order_goods')->where("prom_id={$goods['prom_id']} and prom_type={$goods['prom_type']} and order_id in (" . implode(',', $order_id_arr) . ")")->sum('goods_num'); if ($goods_num1+$goods_num > $teamact['buy_limit']) { return array('status' => -101, 'msg' => '超出活动限购数量', 'result' => ''); } } //购买数量,必须大于开团起购数 if( $goods_num<$teamact['minbuynum'] && $goods['store_count']>$teamact['buy_limit'] && $onlybuy>$teamact['buy_limit'] ){ return array('status' => -101, 'msg' => '参团起购是'.$teamact['minbuynum'].'件', 'result' => ''); } if ($goods_num > $teamact['goods_num']-$teamact['buy_num']) { return array('status' => -4, 'msg' => "此商品的活动库存不足", 'result' => ''); } $price=0; if($teamact['kttype']==3) $price = $teamact['yf_price']; //阶梯团是预付金额 else $price = $teamact['price']; //阶梯团是预付金额 mlog("<会员:" . $user_id . ">" . "查找购物车", "addcart_pt/" . $goods['store_id']); // 如果商品购物车已经存在 $data = array( 'user_id' => $this->user_id, // 用户id 'session_id' => 0, // sessionid 'goods_id' => $goods_id, // 商品id 'goods_sn' => $goods['goods_sn'], // 商品货号 'goods_name' => $goods['goods_name'], // 商品名称 'market_price' => $goods['market_price'], // 市场价 'goods_price' => $price, // 购买价 'member_goods_price' => $price, // 会员折扣价默认为购买价 'goods_num' => $goods_num, // 购买数量 'sku' => $goods['sku'], // 商品条形码 'add_time' => time(), // 加入购物车时间 'prom_type' => $goods['prom_type'], // 0 普通订单,1 限时抢购, 2 团购 ,3 促销优惠,4积分购,5优惠促销,6拼单 'prom_id' => $goods['prom_id'], // 活动id 'pick_id' => $pickup_id, 'store_id' => $goods['store_id'], 'state'=>1 ); mlog("<会员:" . $user_id . ">" . json_encode($data), "addcart_pt/" . $goods['store_id']); $insert_id = M('Cart')->add($data); upload_ylp_log('商品加入购物车'); if($insert_id) exit(json_encode(array('status' => 1, 'msg' => '成功加入购物车', 'result' =>$insert_id))); else exit(json_encode(array('status' => -1, 'msg' => '加入购物车失败', 'result' =>$insert_id))); } /** * 秒杀活动列表 */ public function team_list() { $stype = I('type/d', 1); $this->assign('type', $stype); upload_ylp_log('秒杀活动列表'); return $this->fetch("", getMobileStoId()); } /** * 秒杀活动列表 */ public function ajax_team_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_team_list_1"; } else { $where = " and f.start_time>=" . $now_time; $fname = "ajax_team_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('teamlist f', 'g.goods_id = f.goods_id', 'inner') ->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 ) and g.is_mainshow=1") ->where('f.is_show=1 and f.is_end=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('teamlist f', 'g.goods_id = f.goods_id', 'inner') ->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 )") ->where('f.is_show=1 and f.is_end=0') ->order('f.ordid') ->limit($Page->firstRow . ',' . $Page->listRows) ->select(); foreach ($list as $item) { $item['cur_num'] = $item['goods_num'] - $item['buy_num']; $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 team_fun(){ $stoid=I('stoid/d',1); //form表单提交 C('TOKEN_ON', true); $goodsLogic = new \app\home\logic\GoodsLogic(); /*---查看是否有秒杀订单超时的订单,以半小时为限---*/ clear_pind_Order($stoid); /*--更新一些订单的状态--*/ //$timer = new \app\timer\controller\Index(); //$timer->deal_jt_pt($stoid); //$timer->claer_pt_out($stoid); $goods_id = I("get.id/d", 0); $tt=time(); /*--商品--*/ $goods = M('Goods') ->where("on_time<".$tt." and (down_time>".$tt." or down_time=0 ) and is_mainshow=1") ->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(); // 商品 图册 $seckill_buy_info = M('teamlist')->where('is_end', 0)->where('is_show',1) ->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()))); } //找出正在进行的,该会员参与的团没有满团,都要查看详情 $acc=M('order')->where('pt_prom_id',$seckill_buy_info['id']) ->where('order_status=1 or order_status=0') ->where('pt_status=1') ->where('user_id',$this->user_id) ->find(); if($acc) $this->assign('ac', $acc); $this->assign('pd_info', $seckill_buy_info); if($seckill_buy_info['kttype']==3){ $ct_rylist=json_decode($seckill_buy_info['ct_rylist'],true); $this->assign('ct_rylist', $ct_rylist); $nn=count($ct_rylist)-1; $this->assign("max_num",$ct_rylist[$nn]['rynum']); } /*---设置活动是秒杀销售量---*/ //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); $name='pind'.$seckill_buy_info['id'].'-'.$stoid; $namec='pind'.$seckill_buy_info['id'].'-'.$stoid.'c'; $cval=F($namec); if(empty($cval)){ for($i=0;$i<($seckill_buy_info['goods_num']-$seckill_buy_info['buy_num']);$i++){ $redis->lPush($name,"pt".$i); } F($namec,1); } $len= $redis->lLen($name); $this->assign("len",$len); if ($seckill_buy_info['start_time'] > time()) { //活动进行中 $this->assign('isyure', 1); } $user_id = cookie('user_id'); $user=$this->user; /*------商品规格--------*/ $sp1 = $goods["goods_spec"]; $cn1 = $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']; } /*---规格筛选---*/ $filter_spec = M('goods')->where('sku', $goods['sku'])->where('store_id', $stoid)->where("is_on_sale", 1) ->field('goods_id,erpwareid,goods_name,brand_id,nation_id,cat_id,goods_spec,goods_color,goods_unitname,goods_sn,sku,shop_price, market_price,sales_sum,store_count,original_img,prom_type,goods_remark,mz_price,distr_type,cardprice1,cardprice2,cardprice3,spec_img,viplimited') ->select(); foreach ($filter_spec as $k4 => $v4) { $gidarr4[$v4['erpwareid']] = $v4['goods_id']; } //查看销售规则,采用线下规则要计算所有规格的商品在线下的库存 $mstore = tpCache('basic.sales_rules', $stoid); if ($mstore == 2) { $this->assign('is_bline', 1); } else { $this->assign('is_bline', 0); } $rank_switch = tpCache('shopping.rank_switch', $stoid);//等级价格 $mz_switch = tpCache('shopping.is_beauty', $stoid);//美妆价格 $guige = "规格"; $gorder = 1; $ary = null; foreach ($filter_spec as $k => $v) { /*-----过滤掉活动的商品-----*/ $now = time(); $wh0 = [ 'end_time' => ['>=', $now], 'start_time' => ['<=', $now], 'id' => $v['prom_id'], 'goods_id' => $v['goods_id'], 'is_end' => 0, ]; $rs = M('group_buy')->where($wh0)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $rs = M('integral_buy')->where($wh0)->where('is_show', 1)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $rs = M('flash_sale')->where($wh0)->find(); if ($rs) { unset($filter_spec[$k]); continue; } $sp = $v["goods_spec"]; $cn = $v["goods_color"]; if ($sp == "" && $cn == "") { $tgg = $guige . $gorder; $gorder++; } else if ($sp != "" && $cn == "") { $tgg = $sp; } else if ($sp == "" && $cn != "") { $tgg = $cn; } else { $tgg = $sp . "/" . $cn; } if (empty($v['spec_img'])) $filter_spec[$k]['spec_img'] = $v['original_img']; /*--该商品此卖了多少件--*/ $filter_spec[$k]['guige'] = $tgg; $filter_spec[$k]['curprice'] = $v['shop_price']; if($v['goods_id']==$goods_id){ $filter_spec[$k]['prom_type'] = 0; } if ($v['prom_type'] > 0) { //找出活动的细节 $prom = $filter_spec[$k]['flash_sale'] = get_goods_promotion($v['goods_id']); if ($prom['is_end'] != 1 && $prom['is_end'] != 4 && $prom['is_end'] != 2) { $filter_spec[$k]['curprice'] = $filter_spec[$k]['flash_sale']['price']; } else { $filter_spec[$k]['prom_type'] = 0; } } if ($v['prom_type'] == 0) { if ($user['is_mzvip'] && $v['mz_price'] > 0 && $mz_switch) { $filter_spec[$k]['curprice'] = $v['mz_price']; } if ($rank_switch) { if ($user['card_field'] && $v[$user['card_field']] >0 && strtotime($user['card_expiredate']) > time()) { $filter_spec[$k]['curprice'] = $v[$user['card_field']]; } } } /*--规格排序--*/ if ($v["goods_id"] == $goods_id) { $filter_spec[$k]['viplimited'] = $goods['viplimited']; $ary = $filter_spec[$k]; unset($filter_spec[$k]); } else { if (empty($v['viplimited'])) { $filter_spec[$k]['viplimited'] = 10000; } else { $limit = M('order')->alias('a')->join('order_goods b', 'a.order_id=b.order_id')->where(['b.goods_id' => $v['goods_id'], 'a.user_id' => $user_id, 'a.order_status' => [['=', 4], ['<', 3], 'or']])->sum('b.goods_num'); $limit += M('cart')->where(['goods_id' => $v['goods_id'], 'user_id' => $user_id])->where('state',0)->sum('goods_num'); $filter_spec[$k]['viplimited'] -= $limit; } } } /*--规格排序--*/ array_unshift($filter_spec, $ary); $this->assign('filter_spec', $filter_spec);//规格参数 if (empty($goods['viplimited'])) { $goods['viplimited'] = 10000; } else { $limit = M('order')->alias('a')->join('order_goods b', 'a.order_id=b.order_id')->where(['b.goods_id' => $goods_id, 'a.user_id' => $user_id, 'a.order_status' => [['=', 4], ['<', 3], 'or']])->sum('b.goods_num'); $limit += M('cart')->where(['goods_id' => $goods_id, 'user_id' => $user_id])->where('state',0)->sum('goods_num'); if ($limit >= $goods['viplimited']) { $goods['viplimited'] = 0; } else { $goods['viplimited'] -= $limit; } } $prom = get_goods_promotion1($goods, $seckill_buy_info, $this->user_id); $curprice = $prom['price']; if ($prom['is_end'] == 2) { $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(); 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('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('seckill_buy_info', $seckill_buy_info); upload_ylp_log('天天拼单商品详情'); } public function team_info(){ $this->team_fun(); return $this->fetch('', getMobileStoId()); } //会员一键参团,开团 public function teamshow() { $teamid = I('teamid/d'); $qh = I('qh'); $storeid = getMobileStoId(); //判断是否成团,如果pt_status=0就是未支付,就是要跳转到支付页面 $ord=M('order')->where('user_id',$this->user['user_id'])->where('pt_listno',$qh) ->where('store_id',$storeid)->where('pt_prom_id',$teamid)->where('order_status<>3') ->field('pt_status,order_id') ->find(); if($ord['pt_status']==0 && $ord){ $this->error("您已经购买了该商品,待支付中!",U('/Mobile/user/order_detail',array('stoid' => getMobileStoId(),'id'=>$ord['order_id']))); } $this->assign('ord',$ord); /*---查看是否有拼单订单超时的订单---*/ clear_pind_Order($storeid); //$timer = new \app\timer\controller\Index(); //$timer->deal_jt_pt($storeid); //$timer->claer_pt_out($storeid); //判断是否已经关注 $r = M('wx_openlist')->where("wxopenid",$this->user['openid']) ->where("store_id", getMobileStoId())->find(); $this->assign('issubscribe',$r['issubscribe']); //获取活动和商品 $pdact = M('teamlist')->where(array('store_id' => $storeid, 'id' => $teamid))->find(); if($pdact['end_time']<=time() && empty($qh)){ $this->error("此拼单活动已经过期", U('/Mobile/Goods/goodsInfo',array('stoid' => getMobileStoId(),'id'=>$pdact['goods_id']))); } if($pdact['is_end']==1){ $this->error("此拼单活动已经结束", U('/Mobile/Goods/goodsInfo',array('stoid' => getMobileStoId(),'id'=>$pdact['goods_id']))); } if($pdact['is_show']==0){ $this->error("此拼单活动未启用", U('/Mobile/Goods/goodsInfo',array('stoid' => getMobileStoId(),'id'=>$pdact['goods_id']))); } $et=0; $tgr=M("teamgroup")->where('listno',$qh) ->where('team_id',$teamid)->where('store_id',$storeid) ->find(); if($tgr['kt_end_time']error("此团已经结束", U('/Mobile/Goods/goodsInfo',array('stoid' => getMobileStoId(),'id'=>$pdact['goods_id']))); } $this->assign('tgr',$tgr); //会员团,如果满团,要计算下redis if ($pdact['kttype'] == 2 && empty($ord)) { //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); $name2 = 'pind' . $teamid . '-' .$qh. $storeid; $len = $redis->lLen($name2); if($len==null || $len<=0 ) { $neerodr = M("order")->where('store_id', $storeid) ->where('pt_listno', $qh)->where('pt_prom_id', $teamid) ->where('pt_status', 0) ->where('order_status=1 or order_status=0') ->field('add_time,order_id,user_id') ->find(); $us=M("users")->where('user_id',$neerodr['user_id'])->field('nickname')->find(); $tt0=(int)$neerodr['add_time']; $tt=strtotime("+5 minute",$tt0); $tt2=time(); $tt3=$tt-$tt2; $this->assign('needtime',$tt3); $this->assign('needtime_id',$neerodr['order_id']); $this->assign('needtime_nickname',$us['nickname']); } } if($tgr) { $et =$tgr['kt_end_time']; $this->assign('et',$et); } $gd=M('goods')->where('goods_id',$pdact['goods_id']) ->field('goods_id,goods_name,market_price,shop_price,original_img,store_count,prom_type,prom_id,distr_type')->find(); $this->assign('pdact',$pdact); $this->assign('gd',$gd); $prom=null; //当活动还没有过期的时候 if($et>time()) $prom = get_pt_promotion($gd, $pdact, $this->user_id,$qh); else { //如果订单已经过期了,要进行退款处理 //pt_auto_refund($tgr,$pdact); $prom = get_goods_promotion1($gd, $pdact, $this->user_id); } if ($prom['is_end'] == 2) { $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); //秒杀没人限购数量 } //已拼团人数 $ptedlist = M('order') ->field('is_pt_tz,pt_pay_time,user_id,add_time') ->where('store_id',$storeid) ->where('pt_listno', $qh)->where('pay_time>0')->order('is_pt_tz desc')->select(); //->field('a.*,b.head_pic,b.nickname') foreach($ptedlist as $k=>$v){ $us=M('users')->where('user_id',$v['user_id'])->field('head_pic,nickname')->find(); $ptedlist[$k]['head_pic']=$us['head_pic']; $ptedlist[$k]['nickname']=$us['nickname']; } $num = count($ptedlist); $this->assign('num', $num); $pp=null; if($num>6){ for ($i=0;$i<6;$i++){ $pp[]=$ptedlist[$i];} }else{ $pp=$ptedlist; } $this->assign('pp', $pp); $this->assign('ptedlist', $ptedlist); //如果是阶梯团 if($pdact['kttype']==3){ $jieti=json_decode($pdact['ct_rylist'],true); //最大阶梯数 $nn=count($jieti)-1; $this->assign("max_num",$jieti[$nn]['rynum']); $curpice=0; //计算价格 if($num>=$jieti[$nn]['rynum']){ $curpice=$jieti[$nn]['price']; }else { foreach ($jieti as $k => $v) { if ($num <= $v['rynum']) { $curpice = $v['price']; break; } } } $this->assign('jieti',$jieti); $this->assign('curpice',$curpice); } if($et>0) //时间差 $timedif=$et-time()>0?$et-time():0; else $timedif=$pdact['end_time']-time()>0?$pdact['end_time']-time():0; if(empty($tgr) && !empty($qh)) $timedif=0; $this->assign('timedif',$timedif); $return = M('wx_ewmlist')->where(array('store_id' => $storeid, 'scene_id' => ''))->field('ticket')->find(); if ($return) { $this->assign('share_wximg', "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $return['ticket']); } //商品图片 $imgurl = getImg($pdact['share_imgurl'],curHostURL().NOIMG); $msg = $this->img_curl_url($imgurl, 2); $shareimg = $msg['data']; $this->assign('shareimg',$shareimg); //二维码也用64位 $shareurl=curHostURL().'/index.php/mobile/team/teamshow/stoid/'.$storeid.'/teamid/'.$pdact['id'].'/qh/'.$qh; $this->assign('shareurl',$shareurl); $qc = new \app\home\controller\Index(); $shareurl=$qc->qr_code_64($shareurl); $this->assign('shareurlimg',$shareurl); //用户点击分销要用的分享要用的 $this->assign('teamshare0', 1); //大家都在团 $p_list=M('teamlist')->alias('a')->join('goods b','a.goods_id=b.goods_id') ->where('a.buy_num>0 and a.store_id='.$storeid) ->where('a.is_show=1 and a.is_end=0 and a.end_time>'.time()) ->field('a.*,b.goods_id,b.goods_name,b.market_price,b.shop_price,b.original_img') ->limit(30) ->select(); $count=count($p_list); $as_ptedlist=null; if($count>2){ $numbers = range (0,$count-1); shuffle ($numbers); $result = array_slice($numbers,0,2); $as_ptedlist[]=$p_list[$result[0]]; $as_ptedlist[]=$p_list[$result[1]]; }else{ $as_ptedlist=$p_list; } $this->assign('as_ptedlist', $as_ptedlist); return $this->fetch('', getMobileStoId()); } //支付成功,失败 public function team_success() { $ordno=I('orderno'); $stoid=I('stoid'); //支付状态 $payf=I('payfail','0'); $this->assign('payf',$payf); $p_ord=M('order')->where('store_id',$stoid)->where('order_sn',$ordno) ->field('order_amount,pt_status,pt_listno,pt_prom_id,add_time')->find(); //余额支付,就直接改订单状态 if ($p_ord['order_amount'] <=0 && empty($p_ord['pt_status'])) { update_pay_status2($ordno, 1); $p_ord=M('order')->where('store_id',$stoid)->where('order_sn',$ordno)->find(); } //当如果是微信支付的时候 $wxok=I("wxok"); if($wxok==1){ //如果订单没有及时更新状态 if($p_ord['pt_status']==0) { include_once "plugins/payment/weixin/weixin.class.php"; $wx = new \weixin(); $r = $wx->query_odr($ordno, $stoid); if ($r){ update_pay_status2($ordno, 1); $p_ord=M('order')->where('store_id',$stoid)->where('order_sn',$ordno)->find(); }else{ mlog('微信未找到订单','team_success/'.$stoid); } } } $this->assign('p_ord',$p_ord); if($p_ord){ //获取活动和商品 $pdact=M('teamlist')->where('id',$p_ord['pt_prom_id'])->find(); $gd=M('goods')->where('goods_id',$pdact['goods_id']) ->field('goods_id,goods_name,market_price,shop_price,original_img,store_count,prom_type,prom_id')->find(); $this->assign('pdact',$pdact); $this->assign('gd',$gd); //已拼团人数 $ptedlist=null; if($p_ord['pt_listno']) { $qh=$p_ord['pt_listno']; //已拼团人数 $ptedlist = M('order') ->field('is_pt_tz,pt_pay_time,user_id,add_time') ->where('store_id',$stoid) ->where('pt_listno', $qh)->where('pay_time>0')->order('is_pt_tz desc')->select(); //->field('a.*,b.head_pic,b.nickname') foreach($ptedlist as $k=>$v){ $us=M('users')->where('user_id',$v['user_id'])->field('head_pic,nickname')->find(); $ptedlist[$k]['head_pic']=$us['head_pic']; $ptedlist[$k]['nickname']=$us['nickname']; } $this->assign('num', count($ptedlist)); $this->assign('ptedlist', $ptedlist); }else{ $p_ord['head_pic']=$this->user['head_pic']; $p_ord['nickname']=$this->user['nickname']; $ptedlist[]=$p_ord;$num = 1; $this->assign('num', $num); $this->assign('ptedlist', $ptedlist); } $pp=null; if($num>6){ for ($i=0;$i<6;$i++){$pp[]=$ptedlist[$i];} }else{ $pp=$ptedlist; } $this->assign('pp',$pp); //如果是阶梯团 if($pdact['kttype']==3){ $jieti=json_decode($pdact['ct_rylist'],true); $curpice=0; $nn=count($jieti)-1; foreach ($jieti as $k => $v) { if ($num >= $v['rynum']) { $curpice = $v['price'];break; } } if($curpice==0) $curpice=$jieti[0]['price']; $this->assign('jieti',$jieti); $this->assign('curpice',$curpice); $this->assign("max_num",$jieti[$nn]['rynum']); } $et=0; $tgr=M("teamgroup")->where('listno',$p_ord['pt_listno']) ->where('team_id',$p_ord['pt_prom_id'])->where('store_id',getMobileStoId()) ->field('buystartdate,state,kt_end_time') ->find(); if($tgr) { $et = $tgr['kt_end_time']; $this->assign('et',$et); $this->assign('tgr',$tgr); $is_succ=0; if($p_ord['pt_status']==2 || $p_ord['pt_status']==4 || $p_ord['pt_status']==5 ){ $is_succ=1; } $this->assign('is_succ',$is_succ); }else{ $this->assign('is_succ',0); } //时间差 if($et>0) //时间差 $timedif=$et-time()>0?$et-time():0; else $timedif=$pdact['end_time']-time()>0?$pdact['end_time']-time():0; $this->assign('timedif',$timedif); //商品图片 $imgurl = getImg($pdact['share_imgurl'],curHostURL().NOIMG); $msg = $this->img_curl_url($imgurl, 2); $shareimg = $msg['data']; $this->assign('shareimg',$shareimg); //分享网址 //二维码也用64位 $shareurl=curHostURL().'/index.php/mobile/team/teamshow/stoid/'.$stoid.'/teamid/'.$pdact['id'].'/qh/'.$p_ord['pt_listno']; $this->assign('shareurl',$shareurl); $qc = new \app\home\controller\Index(); $shareurl=$qc->qr_code_64($shareurl); $this->assign('shareurlimg',$shareurl); } //大家都在团 $p_list=M('teamlist')->alias('a')->join('goods b','a.goods_id=b.goods_id') ->where('a.buy_num>0 and a.store_id='.$stoid) ->where('a.is_show=1 and a.is_end=0 and a.end_time>'.time()) ->field('a.*,b.goods_id,b.goods_name,b.market_price,b.shop_price,b.original_img') ->limit(30) ->select(); $count=count($p_list); $as_ptedlist=null; if($count>2){ $numbers = range (0,$count-1); shuffle ($numbers); $result = array_slice($numbers,0,2); $as_ptedlist[]=$p_list[$result[0]]; $as_ptedlist[]=$p_list[$result[1]]; }else{ $as_ptedlist=$p_list; } $this->assign('as_ptedlist', $as_ptedlist); $this->assign('teamshare0', 1); return $this->fetch('', getMobileStoId()); } // 网址图片生成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; } //查看最近24小时内,活动未结束的开单,弹出框,提示信息 public function get_buy_team(){ return -1; //随机查找一个 $rs=M("order")->alias('a')->join('(select id from wxd_teamlist where store_id='.getMobileStoId().' and end_time>'.time().' and is_end=0) b','a.pt_prom_id=b.id')->where('a.store_id',getMobileStoId())->field('user_id,order_id,add_time') ->order('RAND()')->find(); if($rs){ $user=M('users')->where('user_id',$rs['user_id'])->find(); $gd=M('order_goods')->where('order_id',$rs['order_id'])->find(); $data['head_pic']=$user['head_pic']; $data['nickname']=$user['nickname']; $data['goods_id']=$gd['goods_id'];//商品id $time=time(); $tdiff=$rs['add_time']-$time; $str=""; if($tdiff>0) { $remain = $tdiff%86400; $hours = intval($remain/3600); if($hours>0){ $str=$hours."小时前"; }else{ $remain = $tdiff%3600;$mins = intval($remain/60); if($mins>0){ $str=$mins."分钟前"; }else{ $secs = $remain%60; $str=$secs."秒前"; } } $data['add_time'] = $str; return json(['code'=>1,'data'=>$data]); }else{ return json(['code'=>-1]); } }else{ return json(['code'=>-1]); } } //天天拼单的参团购买界面 public function Cart2_team(){ if ($this->user_id == 0) $this->error('请先登录', U('Mobile/User/login', array('stoid' => getMobileStoId()))); /*--不能重复的一张表--*/ //$userd=M("users")->where('user_id',$this->user_id)->find(); $userd = $this->user; /*--清理未支付订单--*/ clear_pind_Order(getMobileStoId()); $locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money'); $this->assign('u_money', number_format($userd['user_money'] - $userd['frozen_money'] - $locking_money, 2)); $is_pt=I("is_pt"); $this->assign("is_pt", $is_pt); if($is_pt!=3) { /*---获取地区---*/ $region_list = get_region_list(); $addlist = M('user_address')->where(['user_id' => $this->user_id])->select(); foreach ($addlist as $kk => $vv) { $vv['provicename'] = $region_list[$vv['province']]['name']; $vv['cityname'] = $region_list[$vv['city']]['name']; $vv['districtname'] = $region_list[$vv['district']]['name']; $vv['twonname'] = $region_list[$vv['twon']]['name']; //$address = M('user_address')->where(['user_id'=>$this->user_id,'is_default'=>1])->find(); $addrstr = $vv['provicename'] . "-" . $vv['cityname']; if (!empty($vv['district'])) $addrstr .= "-" . $vv['districtname']; if (!empty($vv['twon'])) $addrstr = $addrstr . "-" . $vv['twonname']; $vv['addrstr'] = $addrstr; $addlist[$kk] = $vv; } $this->assign("addlist", $addlist); $address_id = I('address_id/d'); if ($address_id) { foreach ($addlist as $kk => $vv) { if ($vv['address_id'] == $address_id) { $address = $vv; } } } else { foreach ($addlist as $kk => $vv) { if ($vv['is_default'] == 1) { $address = $vv; } } } $p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select(); $this->assign('province', $p); if (empty($address)) { //header("Location: ".U('Mobile/User/add_address',array('stoid'=>getMobileStoId(),'source'=>'cart2'))); $this->assign('setadd', 1); } else { $this->assign('address', $address); $this->assign('setadd', 0); } } /*--是否是购物车--*/ $tocart = I("tocart/d", 0); $result = null; $count = M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->count(); if ($count == 0) $this->redirect('Index/index', array('stoid' => getMobileStoId())); $result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品 /*--购物车商品分组--*/ $cart_goods = $result['cartList']; $expty = 0; foreach ($cart_goods as $kp => $vp) { $exp2=0; if($vp['distr_type']!=$vp['bdistr_type']){ $exp2=$vp['distr_type']==0?$vp['bdistr_type']:$vp['distr_type']; }else{ $exp2=$vp['distr_type']; } $cart_goods[$kp]['expty']=$exp2; if ($vp['is_gift'] == 0) { //判断最后的物流方式 if ($expty != 0) { if ($expty != $exp2) { if($exp2==2 || $expty==2 ){ $expty=2; }else{ $expty=0; } } } else { $expty =$exp2; } } } $this->assign("expty", $expty); $shippingList = M('store_shipping')->alias('a')->join("shipping b", "a.shipping_id=b.shipping_id") ->field('b.shipping_id,b.shipping_code,b.shipping_name,b.shipping_desc,b.shipping_logo') ->where("a.status=1 and a.store_id=" . getMobileStoId())->cache("shippingList_" . getMobileStoId(), TPSHOP_CACHE_TIME) ->select();//物流公司 /*----------购物车商品分组---------*/ $sql = null; $sql = "select pickup_id,pickup_name from __PREFIX__pick_up where pickup_id in(select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id)"; //mlog('$tocart:'.$sql,'cart'); $plist_cart = Db::query($sql); foreach ($plist_cart as $k => $v) { $expty00 = 0; foreach ($cart_goods as $kk => $vv) { if ($vv['pick_id'] == $v['pickup_id']) { $list[] = $vv; $expty11=$vv['expty']; if($expty00==0){ $expty00=$expty11; } } } $plist_cart[$k]["goods"] = $list; $plist_cart[$k]["expty"]=$expty00; unset($list); } $this->assign('slist', $plist_cart); $this->assign('shippingList', $shippingList); // 物流公司 $this->assign('total_price', $result['total_price']); // 总计 upload_ylp_log('购物车已选商品显示'); return $this->fetch('', getMobileStoId()); } //天天拼单的参团提交 public function Cart3_team(){ if(empty($this->redis)){ //$this->redis=new \Redis(); //$this->redis->connect(redisip, 6379); $this->redis=get_redis_handle(); } $popvalue=null; $popvalue2=null; $stoid = I("stoid"); //拼单有关 $ispt=I('is_pt'); $pdid=I('pdid'); $team_qh=I('team_qh'); $pdgoodsnum=I('pdgoodsnum/d',0); $no=""; $notime=microtime_float(); if ($_REQUEST['act'] == 'submit_order') { //如果是拼单 if($ispt){ $no='r'.microtime_float().rand(10000, 99990); $name='pind'.$pdid.'-'.$stoid; if($this->redis->lLen($name)<$pdgoodsnum){ return json(array('status' => -4, 'msg' => "您晚了一步,商品已被抢光!", 'result' => '')); } //拼单队列控制 for($i=0;$i<$pdgoodsnum;$i++) { $value = $this->redis->lPop($name); $popvalue[]=$value; } //如果,$ispt是会员团的时候,要判断团的缓存 if($team_qh && $ispt=='2'){ $name2='pind'.$pdid.'-'.$team_qh.$stoid; $value = $this->redis->lPop($name2); if (empty($value)) { foreach ($popvalue as $k=>$v) $this->redis->lPush($name,$v); return array('status' => -4, 'msg' => "手慢了,您参与的团已满团!", 'result' => ''); } $popvalue2[]=$value; } //redis要加入set中,编号,类型,活动id,数量,时间,stoid $key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh; $this->redis->sAdd('redis_set_'.$stoid,$key); } } /*--物流方式--*/ $exptype = I("exptype/d"); $state = I("state/d"); if ($this->user_id == 0) { $this->backredis($no,$notime); exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态 } $address_id = I("address_id/d"); // 收货地址id $setadd = I("setadd/d"); $is_skill = I("skill"); //是否是秒杀 /*--是否是编辑地址--*/ if ($setadd == 1 && $exptype == 2 && empty($address_id)) { $consignee = I("consignee"); $mobile = I("mobile"); $province = I("province"); $city = I("city"); $district = I("district"); $twon = I("twon"); $address = I("address"); $data = ['consignee' => $consignee, 'mobile' => $mobile, 'province' => $province, 'city' => $city, 'district' => $district, 'twon' => $twon, 'address' => $address, ]; $logic = new UsersLogic(); $data = $logic->add_address($this->user_id, 0, $data); $address_id = $data['result']; } $shipping_code = I("shipping_code/a"); // 物流编号 $invoice_title = I('invoice_title/a'); // 发票 $exparr= I('exparr/a');//获取物流配送数组 $couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码 $coupon_id = I("coupon_id/a"); // 优惠券id $couponCode = I("couponCode"); // 优惠券代码 $user_note = I('user_note/a'); //买家留言 $pay_points = I("pay_points", 0); // 使用积分 $user_money = I("user_money", 0); // 使用余额 $user_money = str_replace(',', '', $user_money); $user_money = doubleval($user_money); $exptype=0; if($exparr) { foreach ($exparr as $ko => $vo) { if ($vo == 1) { $exptype = 1; break; } } } if($user_money<0) { $this->backredis($no,$notime); exit(json_encode(array('status' => -2, 'msg' => '你的余额不足', 'result' => null))); //返回结果状态 } $result = null; $result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品 $cart_goods = $result['cartList']; if (empty($cart_goods)) { $this->backredis($no,$notime); exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态 } $address = M('UserAddress')->where("address_id", $address_id)->find(); $allusrnum = $user_money; $locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money'); $userd = $this->user; $salerule = tpCache('basic.sales_rules', $stoid); $erpid = tpCache('shop_info.ERPId', $stoid); $userd['sales_rules'] = $salerule; $userd['ERPId'] = $erpid; //订单余额判断 if (!empty($allusrnum)) { $ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money; if ($ye . '' < $allusrnum) { $this->backredis($no,$notime); return array('status' => -4, 'msg' => "您的可用余额不足", 'result' => ''); } } $err_txt = ""; $prom_goods = array(); //建立优惠促销数组 foreach ($cart_goods as $k => $value) { if ($value['prom_type'] == 3 && $value['is_gift'] == 0 && $value['is_collocation'] == 0) { $prom_goods[$value['pick_id']][$value['prom_id']]['num'] += $value['goods_num']; $prom_goods[$value['pick_id']][$value['prom_id']]['price'] += $value['goods_num'] * $value['goods_price']; } if ($value['is_gift'] == 1) { $prom_goods[$value['pick_id']][$value['prom_id']]['key'] = $k; } } if (!empty($prom_goods)) { $prom_info = M('prom_goods')->where(['start_time' => ['lt', time()], 'end_time' => ['gt', time()], 'is_end' => 0])->getfield('id,name'); foreach ($prom_goods as $kk => $vv) { foreach ($vv as $key => $val) { if (!empty($prom_info[$key])) { $prom = discount($val['price'], $key, $val['num'], $this->user_id); if (empty($prom['goods_id']) && !empty($val['key'])) { unset($cart_goods[$val['key']]); } $prom_goods[$kk][$key]['int'] = $prom['int']; $prom_goods[$kk][$key]['coupon'] = $prom['coupon_id']; $prom_goods[$kk][$key]['is_past'] = $prom['is_past']; $prom_goods[$kk][$key]['gift_id'] = $prom['gift_id']; $prom_goods[$kk][$key]['price'] = $prom['price']; $prom_goods[$kk][$key]['all_price'] = $val['price']; } else { return array('status' => -4, 'msg' => "优惠活动已经结束", 'result' => ''); } } } } /*--预出库库存--*/ $gidarr=get_arr_column($cart_goods,'goods_id'); $fgid0=implode(',',$gidarr); $strq = 'select pickup_id,goods_id,sum(out_qty) as sum0 from wxd_erp_yqty where goods_id in(' . $fgid0 . ') and store_id='.$stoid.' GROUP BY pickup_id,goods_id'; $dd = Db::query($strq); $ddd = []; //---组装数组--- if ($dd){ foreach ($dd as $ku => $vu) { $ypkid=$vu['pickup_id']; $ypgid=$vu['goods_id']; $ddd[$ypkid.".".$ypgid]=$vu['sum0']; } } /*--库存判断和活动判断,商品的库存和活动不能过期--*/ foreach ($cart_goods as $k => $value) { $ginfo = $value; /*--修改获取活动的函数--*/ $prom = get_pt_promotion($ginfo, null, $this->user_id,$team_qh); if ($prom['is_end'] == 1) { $this->backredis($no,$notime); return json(array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品活动已经结束", 'result' => '')); } if ($prom['is_end'] == 2) { $this->backredis($no,$notime); return json(array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此商品已经售完", 'result' => '')); } if ($prom['is_end'] == 3) { $this->backredis($no,$notime); return json(array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '')); } if ($value['prom_type'] == 1 || $value['prom_type'] == 2 || $value['prom_type'] == 4) { if ($value['goods_num'] > $prom['buy_limit'] && $prom['onlybuy']>$prom['buy_limit'] && $value['store_count']>$prom['buy_limit']) { $this->backredis($no,$notime); return json(array('status' => -4, 'msg' => "{$ginfo['goods_name']} 此活动商品超出限购数量", 'result' => '')); } } if ($value['member_goods_price'] != $prom['price']) { $err_txt .= "{$ginfo['goods_name']}商品价格已经变化
"; } if ($value['goods_num'] > $ginfo['store_count']) { $this->backredis($no,$notime); return json(array('status' => -4, 'msg' => "库存不足", 'result' => '')); } } if ($err_txt != "") { $this->backredis($no,$notime); return json(array('status' => -1004, 'msg' => $err_txt, 'result' => '')); } /*--购物车商品分组,生成不同订单--*/ $plist = null; if ($state == 0) { $sql = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id"; $plist = Db::query($sql); foreach ($plist as $k => $v) { $count = array(); foreach ($cart_goods as $kk => $vv) { if ($v['pick_id'] == $vv['pickup_id']) { $list[] = $vv; } if (!empty($prom_goods[$v['pick_id']]) && $vv['prom_type'] == 3 && $count[$vv['prom_id']] == 0) { $plist[$k]['order']['int'] += $prom_goods[$v['pick_id']][$vv['prom_id']]['int']; $plist[$k]['order']['coupon'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon']; $plist[$k]['order'][$vv['prom_id']]['gift_id'] = $prom_goods[$vv['pick_id']][$vv['prom_id']]['gift_id']; $plist[$k]['discount'] = $prom_goods[$v['pick_id']]; $count[$vv['prom_id']] += 1; } } $plist[$k]["goods"] = $list; unset($list); } } else { $sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id"; $plist = Db::query($sql1); foreach ($plist as $k => $v) { $count = array(); foreach ($cart_goods as $kk => $vv) { if ($v['pick_id'] == $vv['pickup_id']) { $list[] = $vv; } if (!empty($prom_goods[$v['pick_id']]) && $vv['prom_type'] == 3 && $count[$vv['prom_id']] == 0) { $plist[$k]['order']['int'] += $prom_goods[$v['pick_id']][$vv['prom_id']]['int']; $plist[$k]['order']['coupon'][] = $prom_goods[$v['pick_id']][$vv['prom_id']]['coupon']; $plist[$k]['order'][$vv['prom_id']]['gift_id'] = $prom_goods[$vv['pick_id']][$vv['prom_id']]['gift_id']; $plist[$k]['discount'] = $prom_goods[$v['pick_id']]; $count[$vv['prom_id']] += 1; } } $plist[$k]["goods"] = $list; unset($list); } } /*--开始生成多单--*/ //$uerp=M('store')->where('store_id',$stoid)->find(); $pno = ""; if (count($plist) > 1) $pno = $userd['ERPId'] . date('ymdHis') . get_total_millisecond() . rand(1000, 9999); $postFee = 0;$couponFee = 0;$balance = 0;$pointsFee = 0;$payables = 0;$payables1 = 0;$goodsFee = 0;$order_prom_id = 0;$order_prom_amount = 0; //---拼单只有一个商品--- if($ispt==3) { $exptype = 1;$exparr[$plist[0]['pick_id']]=1; } //启动事务 Db::startTrans(); try { foreach ($plist as $k => $v) { /*--计算订单相关--*/ $result = calculate_price2($this->user, $v["goods"], $shipping_code[$v['pick_id']], 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, $coupon_id[$v['pick_id']], $couponCode, $stoid, $exparr[$v['pick_id']], $v['discount']); if ($result['status'] < 0) { $this->backredis($no,$notime); exit(json_encode($result)); } /*---余额使用---*/ $user_money = round($user_money - $result['result']['user_money'], 2); $postFee += $result['result']['shipping_price']; // 物流费 $couponFee += $result['result']['coupon_price'];// 优惠券 $balance += $result['result']['user_money']; // 使用用户余额 $pointsFee += $result['result']['integral_money']; // 积分支付 $payables += $result['result']['order_amount'];// 应付金额 $payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分 $goodsFee += $result['result']['goods_price'];// 商品价格 $order_prom_id .= $result['result']['order_prom_id'] . ",";// 订单优惠活动id $order_prom_amount += $result['result']['order_prom_amount'] + $result['result']['discount'];// 订单优惠活动优惠了多少钱 // 提交订单 if ($_REQUEST['act'] == 'submit_order') { $address_id = $_REQUEST['address_id']; mlog("日志" . $address_id . "是否编辑地址" . $setadd, "cart"); if (!$address_id && $exptype == 0){ $this->backredis($no,$notime); exit(json_encode(array('status' => -3, 'msg' => '请先填写收货人信息', 'result' => null))); } // 返回结果状态 if (!$shipping_code && $exptype == 0){ $this->backredis($no,$notime); exit(json_encode(array('status' => -4, 'msg' => '请选择物流信息', 'result' => null))); } // 返回结果状态 if (empty($coupon_id) && !empty($couponCode)) { $coupon_id = M('CouponList')->where("code", $couponCode)->getField('id'); } //$iii=$result['result']['user_money']; $car_price0 = array( 'postFee' => $result['result']['shipping_price'], // 物流费 'couponFee' => $result['result']['coupon_price'], // 优惠券 'balance' => $result['result']['user_money'], // 使用用户余额 'pointsFee' => $result['result']['integral_money'], // 积分支付 'payables' => $result['result']['order_amount'], // 应付金额 'payables1' => $result['result']['order_amount1'], // 应付金额 'goodsFee' => $result['result']['goods_price'],// 商品价格 'order_prom_id' => $result['result']['order_prom_id'], // 订单优惠活动id 'order_prom_amount' => $result['result']['order_prom_amount'], // 订单优惠活动优惠了多少钱 'discount_amount' => $result['result']['discount'],//优惠、搭配促销优惠的金额 ); /*--调用生成订单的函数--*/ $result = $this->cartLogic->addOrder($this->user_id, $address_id, $shipping_code[$v['pick_id']], $invoice_title[$v['pick_id']], $car_price0, $v["goods"], $coupon_id[$v['pick_id']], $user_note[$v['pick_id']], $stoid, $exparr[$v['pick_id']], $pno, $v['pick_id'], $v['order'], $this->user,$no,$ispt,$pdid,$team_qh); // 添加订单 if($result["status"] != 1) { //如果是拼单 if($ispt){ $name='pind'.$pdid.'-'.$stoid; //拼单队列控制 for($i=0;$i<$pdgoodsnum;$i++) { $this->redis->lPush($name,time().'_'.$i); } if($team_qh && $ispt=='2') { $name2 = 'pind' . $pdid . '-' . $team_qh . $stoid; for($i=0;$i<$pdgoodsnum;$i++) { $this->redis->lPush($name2,time().'_'.$i); } } $key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh; $this->redis->sRem('redis_set_'.$stoid,$key); } //如果订单失败要还原数量 exit(json_encode($result)); } if (empty($pno) && count($plist) == 1) { $pno = $result["result"]; } } } //提交订单 if ($_REQUEST['act'] == 'submit_order') { upload_ylp_log('提交订单'); if ($state == 0) { // 删除购物车中已提交订单商品 M('Cart')->where(['user_id' => $this->user_id, 'selected' => 1])->delete(); //删除购物车的cookie Cookie::delete("cn"); Db::commit(); exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables))); } else { // 删除cart表中立即购买的商品 M('Cart')->where(['user_id' => $this->user_id, 'state' => 1])->delete(); Db::commit(); if($ispt){ $key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh; $this->redis->sRem('redis_set_'.$stoid,$key); $name='pind'.$pdid.'-'.$stoid; $jsdaa['len']=$this->redis->lLen($name); $jsdaa['num']=-$pdgoodsnum; $jsdaa['order_sn']=$pno; $jsdaa['type']=0; //0是买单 1是5分钟自动补回 2是手动补回 mlog(json_encode($jsdaa),'pt_log/' . $stoid . '/' . $pdid."_1"); } exit(json_encode(array('status' => 1, 'msg' => '提交订单成功', 'result' => $pno, 'payables' => $payables))); } } }catch (\Exception $e) { // 回滚事务 Db::rollback(); if ($_REQUEST['act'] == 'submit_order') { //如果失败就补回队列 //如果是拼单 if($ispt){ $name='pind'.$pdid.'-'.$stoid; //拼单队列控制 for($i=0;$i<$pdgoodsnum;$i++) { $this->redis->lPush($name,time().'_'.$i); } if($team_qh && $ispt=='2') { $name2 = 'pind' . $pdid . '-' . $team_qh . $stoid; for($i=0;$i<$pdgoodsnum;$i++) { $this->redis->lPush($name2,time().'_'.$i); } } $key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime.'-'.$team_qh; $this->redis->sRem('redis_set_'.$stoid,$key); } } exit(json_encode(array('status' => -1, 'msg' => '提交订单失败'))); } $car_price = array( 'postFee' => round($postFee, 2), // 物流费 'couponFee' => round($couponFee, 2), // 优惠券 'balance' => round($allusrnum - $user_money, 2), // 使用用户余额 'pointsFee' => round($pointsFee, 2), // 积分支付 'payables' => round($payables, 2), // 应付金额 'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分 'goodsFee' => round($goodsFee, 2),// 商品价格 'order_prom_id' => $order_prom_id, // 订单优惠活动id 'order_prom_amount' => round($order_prom_amount, 2), // 订单优惠活动优惠了多少钱 ); $return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price); // 返回结果状态 exit(json_encode($return_arr)); } //天天拼单的参团点击界面的效果 public function Cart3_team_nosub(){ /*--物流方式--*/ $exptype = I("exptype/d"); $stoid = I("stoid"); $state = I("state/d"); if ($this->user_id == 0) exit(json_encode(array('status' => -100, 'msg' => "登录超时请重新登录!", 'result' => null))); // 返回结果状态 $address_id = I("address_id/d"); //收货地址id $setadd = I("setadd/d"); $is_skill = I("skill"); //是否是秒杀 $exparr= I('exparr/a');//获取物流配送数组 /*--是否是编辑地址--*/ if ($setadd == 1 && $exptype == 0 && empty($address_id)) { $consignee = I("consignee"); $mobile = I("mobile"); $province = I("province"); $city = I("city"); $district = I("district"); $twon = I("twon"); $address = I("address"); $data = ['consignee' => $consignee, 'mobile' => $mobile, 'province' => $province, 'city' => $city, 'district' => $district, 'twon' => $twon, 'address' => $address, ]; $logic = new UsersLogic(); $data = $logic->add_address($this->user_id, 0, $data); $address_id = $data['result']; } $shipping_code = I("shipping_code/a"); // 物流编号 $invoice_title = I('invoice_title/a'); // 发票 $couponTypeSelect = I("couponTypeSelect"); // 优惠券类型 1 下拉框选择优惠券 2 输入框输入优惠券代码 $coupon_id = I("coupon_id/a"); // 优惠券id $couponCode = I("couponCode"); // 优惠券代码 $user_note = I('user_note/a'); //买家留言 $pay_points = I("pay_points", 0); // 使用积分 $user_money = I("user_money", 0); // 使用余额 $user_money = str_replace(',', '', $user_money); $user_money = doubleval($user_money); //if(!empty($user_money)) //$user_money=number_format($user_money,2); //使用俩位 $result = null; $result = $this->cartLogic->gobuyList_cart2($this->user, $this->session_id); //获取购物车商品 $cart_goods = $result['cartList']; if (empty($cart_goods)) exit(json_encode(array('status' => -2, 'msg' => '你的购物车没有选中商品', 'result' => null))); //返回结果状态 $address = M('UserAddress')->where("address_id", $address_id)->find(); $allusrnum = $user_money; $locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money'); $userd = $this->user; $salerule = tpCache('basic.sales_rules', $stoid); $erpid = tpCache('shop_info.ERPId', $stoid); $userd['sales_rules'] = $salerule; $userd['ERPId'] = $erpid; //订单余额判断 if (!empty($allusrnum)) { $ye = $userd['user_money'] - $userd['frozen_money'] - $locking_money; if ($ye . '' < $allusrnum) { return array('status' => -4, 'msg' => "您的可用余额不足", 'result' => ''); } } /*----如果是线下库存,获取线下库存----*/ $count_arr = null; if ($userd['sales_rules'] == 2) { if ($is_skill != 1) $count_arr = getcountarr($cart_goods, $stoid); } /*--购物车商品分组,生成不同订单--*/ $plist = null; if ($state == 0) { $sql = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and selected=1 and state=0 GROUP BY pick_id"; $plist = Db::query($sql); foreach ($plist as $k => $v) { foreach ($cart_goods as $kk => $vv) { if ($v['pick_id'] == $vv['pickup_id']) { $list[] = $vv; } } $plist[$k]["goods"] = $list; unset($list); } } else { $sql1 = "select pick_id from __PREFIX__cart where user_id=" . $this->user_id . " and state=1 GROUP BY pick_id"; $plist = Db::query($sql1); foreach ($plist as $k => $v) { foreach ($cart_goods as $kk => $vv) { if ($v['pick_id'] == $vv['pickup_id']) { $list[] = $vv; } } $plist[$k]["goods"] = $list; unset($list); } } /*--开始生成多单--*/ //$uerp=M('store')->where('store_id',$stoid)->find(); $pno = ""; if (count($plist) > 1) $pno = $userd['ERPId'] . date('ymdHis') . get_total_millisecond() . rand(1000, 9999); $postFee = 0;$couponFee = 0;$balance = 0;$pointsFee = 0;$payables = 0;$payables1 = 0;$goodsFee = 0;$order_prom_id = 0;$order_prom_amount = 0; foreach ($plist as $k => $v) { /*--计算订单相关--*/ $result = calculate_price2($this->user, $v["goods"], $shipping_code[$v['pick_id']], 0, $address['province'], $address['city'], $address['district'], $pay_points, $user_money, $coupon_id[$v['pick_id']], $couponCode, $stoid, $exparr[$v['pick_id']],$v['discount']); if ($result['status'] < 0) exit(json_encode($result)); /*---余额使用---*/ $user_money = round($user_money - $result['result']['user_money'], 2); $postFee += $result['result']['shipping_price']; // 物流费 $couponFee += $result['result']['coupon_price'];// 优惠券 $balance += $result['result']['user_money']; // 使用用户余额 $pointsFee += $result['result']['integral_money']; // 积分支付 $payables += $result['result']['order_amount'];// 应付金额 $payables1 += $result['result']['order_amount1'];// 应付金额,不包含余额的那部分 $goodsFee += $result['result']['goods_price'];// 商品价格 $order_prom_id .= $result['result']['order_prom_id'] . ",";// 订单优惠活动id $order_prom_amount += $result['result']['order_prom_amount'] + $result['result']['discount'];;// 订单优惠加优惠促销活动,优惠了多少钱 } $car_price = array( 'postFee' => round($postFee, 2), // 物流费 'couponFee' => round($couponFee, 2), // 优惠券 'balance' => round($allusrnum - $user_money, 2), // 使用用户余额 'pointsFee' => round($pointsFee, 2), // 积分支付 'payables' => round($payables, 2), // 应付金额 'payables1' => round($payables1, 2), // 应付金额,不包含使用余额的那一部分 'goodsFee' => round($goodsFee, 2),// 商品价格 'order_prom_id' => $order_prom_id, // 订单优惠活动id 'order_prom_amount' => round($order_prom_amount, 2), // 订单优惠活动优惠了多少钱 ); $return_arr = array('status' => 1, 'msg' => '计算成功', 'result' => $car_price); // 返回结果状态 exit(json_encode($return_arr)); } //尾款支付 public function tail_pay() { $ord_no = I('ordsn'); //修改订单的支付方式 $order = M('order')->where("order_sn", $ord_no)->find(); if ($order['pay_status'] == 1) { return json(['code' => -1, 'msg' => '此订单,已完成支付!']); } $user = $this->user; $stoid = $order['store_id']; //主要是要判断付尾款的时间是否到期 $wda['team_id'] = $order['pt_prom_id']; $wda['listno'] = $order['pt_listno']; $uu = M("teamgroup")->where($wda)->where('store_id', $stoid)->find(); if ($uu) { $v = $order; /*----- //如果付尾款的时间也过期了 if ($uu['wk_end_time'] < time()) { $refund_type = tpCache('basic.refund_type', $stoid); //退到余额 if ($refund_type == 0) { $user_money = $v['order_amount'] + $v['user_money'] + $v['pt_tail_money']; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if ($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } } else { mlog("退款到余额失败,", 'refund/' . $stoid); } } //原路返回 else if ($refund_type == 1) { $wxmoney = 0; $usrmoney = 0; if ($v['tail_pay_type']) { $wxmoney = $v['order_amount']; $usrmoney = $v['order_amount'] + $v['pt_tail_money']; } else { $wxmoney = $v['order_amount'] + $v['pt_tail_money']; $usrmoney = $v['order_amount']; } if ($v['order_amount']) { include_once "plugins/payment/weixin/weixin.class.php"; $wx = new \weixin(); $ordno = $v['order_sn']; $total_fee = $wxmoney; $refund_fee = $total_fee; //$erpid = tpCache('shop_info.ERPId', $stoid); $path = BASE_PATH . 'public/cert/' . $stoid . '/'; try { $wx->setCong($stoid); $rs = $wx->refund($ordno, $total_fee, $refund_fee, $path); if ($rs['return_code'] == 'FAIL') { mlog("退款失败," . $rs['return_msg'], 'refund/' . $stoid); } } catch (\Exception $e) { mlog("退款签名失败," . $rs['return_msg'], 'refund/' . $stoid); } } //退到余额 if ($v['user_money']) { $user_money = $usrmoney; $sql = "update wxd_users set user_money=user_money+" . $user_money . " where user_id=" . $v['user_id']; $rs1 = Db::execute($sql); if ($rs1) { if ($user_money > 0) { $odata['user_id'] = $v['user_id']; $odata['create_time'] = time(); $odata['money'] = $user_money; $odata['remark'] = "退款"; $odata['store_id'] = $v['store_id']; $odata['order_sn'] = $v['order_sn']; $odata['status'] = 1; $odata['type'] = 1; M('withdrawals')->save($odata); } } else { mlog("退款到余额失败,", 'refund/' . $stoid); } } } return json(['code' => -1, 'msg' => '付尾款时间到期']); }----*/ if($uu['wk_end_time'] getMobileStoId())); $this->error('尾款时间已到期',$url); } } else { return json(['code' => -1, 'msg' => '未找到拼团']); } if($order['pt_tail_money']>0) { //判断余额情况 $locking_money = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money'); $u_money=$this->user['user_money']-$this->user['frozen_money']-$locking_money; if($u_money<$order['pt_tail_money']){ return json(['code' => -1, 'msg' => '余额不足']); } //购买使用余额 $dr = M('users')->where('user_id', $order['user_id'])->setDec('user_money', $order['pt_tail_money']); if ($dr) { $odata['user_id'] = $order['user_id']; $odata['create_time'] = time(); $odata['money'] = $order['pt_tail_money']; $odata['remark'] = "购买使用余额"; $odata['store_id'] = $order['store_id']; $odata['order_sn'] = $order['order_sn']; $odata['status'] = 1; $odata['type'] = 2; M('withdrawals')->save($odata); //尾款的支付更新状态 update_pt_wk($ord_no, $stoid, $order, 1); return json(['code' => 1, 'msg' => '支付成功']); } else { return json(['code' => -1, 'msg' => '支付失败']); } }else{ update_pt_wk($ord_no, $stoid, $order, 1); return json(['code' => 1, 'msg' => '支付成功']); } } //支付失败 public function team_error(){ $ordno=I('orderno'); $stoid=I('stoid'); $now=time(); $p_ord=M('order')->where('store_id',$stoid)->where('order_sn',$ordno)->find(); $this->assign('p_ord',$p_ord); //支付状态 $tuan_goods=M("teamlist")->alias("f")->join("goods g","g.goods_id = f.goods_id","left") ->where('g.store_id='.$stoid.' and f.show_time<='.$now.' and f.end_time>='.$now.' and g.is_on_sale=1 and f.is_end=0 and f.is_show=1 and g.on_time<'.$now.' and (g.down_time>'.$now.' or g.down_time=0)') ->field("g.goods_id,g.goods_name,g.original_img,g.prom_type,g.shop_price,g.market_price,f.goods_num,f.buy_num,f.title,f.price,f.kttype,f.start_time,f.end_time,f.show_time,f.buy_num,f.ct_num") ->order('f.ordid')->limit(2) ->select(); $this->assign('tuan_goods',$tuan_goods); return $this->fetch("", getMobileStoId()); } //开团列表 //开团列表 public function open_team_list(){ $teamid=I("teamid"); $type=I('team_info'); $pd_info = M('teamlist')->where('store_id', getMobileStoId()) ->where('id', $teamid)->field('kttype,title,ct_rylist,ct_num,kt_time,id')->find(); $this->assign('pd_info', $pd_info); //当type=1,表明是活动详情页的请求 if($type){ //已经开团的列表 $olist=M('order')->alias('a') ->join('teamgroup b','a.pt_listno=b.listno and a.pt_prom_id=b.team_id and a.store_id=b.store_id') ->where('a.store_id',getMobileStoId()) ->where('a.is_pt_tz',1)->where('a.pt_prom_id',$teamid) ->where('a.order_status<>3 and a.pay_status<>1 and a.pay_time>0') ->where('b.state=2') ->where('b.kt_end_time>'.time()) ->field('a.pt_listno,a.user_id,b.team_id,b.kt_end_time,a.store_id') ->select(); $num=count($olist); $olist1=null; $n=0; foreach ($olist as $k=>$v){ $n++; if($n==4){break;} //->join('users c','a.user_id=c.user_id') //->join('teamlist d','a.pt_prom_id=d.id') $usr=M("users")->where('user_id',$v['user_id'])->where('store_id',getMobileStoId()) ->field('nickname,head_pic')->find(); $v['nickname']=$usr['nickname']; $v['head_pic']=$usr['head_pic']; $v['ct_rylist']=$pd_info['ct_rylist']; $v['ct_num']=$pd_info['ct_num']; $v['kt_time']=$pd_info['kt_time']; $v['id']=$pd_info['id']; $olist1[]=$v; } $this->assign('olist', $olist1); $str=$this->fetch("ajax_open_team_list", getMobileStoId()); return json(['code'=>1,'num'=>$num,'str'=>$str]); }else { $p = I('p/d', 1); $isajax = I('isajax'); if($isajax) { //已经开团的列表 $olist = M('order')->alias('a')->join('teamgroup b', 'a.pt_listno=b.listno and a.pt_prom_id=b.team_id and a.store_id=b.store_id') //->join('users c', 'a.user_id=c.user_id') //->join('teamlist d', 'a.pt_prom_id=d.id') ->where('a.store_id',getMobileStoId()) ->where('a.is_pt_tz', 1)->where('a.pt_prom_id', $teamid) ->where('a.order_status<>3 and a.pay_status<>1 and a.pay_time>0') ->where('b.state=2') ->where('b.kt_end_time>'.time()) ->field('a.pt_listno,a.user_id,b.team_id,b.kt_end_time,a.store_id') ->page($p, 10) ->order('order_id') ->select(); if($olist){ foreach ($olist as $k=>$v){ $usr=M("users")->where('user_id',$v['user_id'])->where('store_id',getMobileStoId()) ->field('nickname,head_pic')->find(); $olist[$k]['nickname']=$usr['nickname']; $olist[$k]['head_pic']=$usr['head_pic']; $olist[$k]['ct_rylist']=$pd_info['ct_rylist']; $olist[$k]['ct_num']=$pd_info['ct_num']; $olist[$k]['kt_time']=$pd_info['kt_time']; $olist[$k]['id']=$pd_info['id']; } } $this->assign('olist', $olist); return $this->fetch("ajax_open_team_list", getMobileStoId()); } return $this->fetch("", getMobileStoId()); } } //获取redis长度 public function rd_team_len(){ //循环更新订单状态,以及库存 $odr_arr=M('order') ->where('store_id',getMobileStoId()) ->where('user_id',$this->user_id) ->where('order_amount',0) ->where('pt_status=0 and pt_prom_id>0') ->where('order_status=0 or order_status=1') ->field('order_sn')->select(); foreach ($odr_arr as $k=>$v) { update_pay_status2($v['order_sn'], 1); } $id=I("id"); $stoid=I('stoid'); //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); //判断是否成团,如果pt_status=0就是未支付,就是要跳转到支付页面 $ord=M('order')->where('user_id',$this->user['user_id']) ->where('store_id',$stoid)->where('pt_prom_id',$id) ->where('pt_status',0)->field('order_id') ->where('order_status<>3')->find(); $ordstr0=M('order')->where('user_id',$this->user['user_id']) ->where('store_id',$stoid)->where('pt_prom_id',$id) ->where('pt_status',0)->field('order_id')->fetchSql(ture) ->where('order_status<>3')->find(); mlog("1.".$ordstr0,'rd_team_len/'.$stoid); if($ord){ mlog("2.".json_encode($ord),'rd_team_len/'.$stoid); return json(array('code' => -2, 'msg' => "您已经购买了该商品,待支付中!", 'id'=>$ord['order_id'])); }else { //判断是否成团,如果pt_status=0就是未支付,就是要跳转到支付页面 $ord = M('order')->where('user_id', $this->user['user_id']) ->where('store_id', $stoid)->where('pt_prom_id', $id) ->where('pt_status', 1)->field('pt_prom_id,pt_listno') ->where('order_status<>3')->find(); $ordstr1 = M('order')->where('user_id', $this->user['user_id']) ->where('store_id', $stoid)->where('pt_prom_id', $id) ->where('pt_status', 1)->field('pt_prom_id,pt_listno')->fetchSql(ture) ->where('order_status<>3')->find(); mlog("3.".$ordstr1,'rd_team_len/'.$stoid); if ($ord) { mlog("4.".json_encode($ord),'rd_team_len/'.$stoid); return json(array('code' => -3, 'msg' => "您已经购买了该商品,待成团中!", 'id' => $ord['pt_prom_id'], 'qh' => $ord['pt_listno'])); } } $name='pind'.$id.'-'.$stoid; $len= $redis->lLen($name); if($len==null) $len=0; $d['code']=1; $d['len']=$len; return json($d); } //大家都在团 public function every_body_team(){ $stoid=getMobileStoId(); //大家都在团 $p_list=M('teamlist')->alias('a')->join('goods b','a.goods_id=b.goods_id') ->where('a.buy_num>0 and a.store_id='.$stoid) ->where('a.is_show=1 and a.is_end=0 and a.end_time>'.time()) ->field('a.*,b.goods_id,b.goods_name,b.market_price,b.shop_price,b.original_img') ->limit(30) ->select(); $count=count($p_list); $as_ptedlist=null; if($count>2){ $numbers = range (0,$count-1); shuffle ($numbers); $result = array_slice($numbers,0,2); $as_ptedlist[]=$p_list[$result[0]]; $as_ptedlist[]=$p_list[$result[1]]; }else{ $as_ptedlist=$p_list; } $this->assign('as_ptedlist', $as_ptedlist); return $this->fetch("", $stoid); } /*----相应的返回redis----*/ public function backredis($no,$notime) { if ($_REQUEST['act'] == 'submit_order') { $popvalue = null; $popvalue2 = null; $stoid = I("stoid"); //拼单有关 $ispt = I('is_pt'); $pdid = I('pdid'); $team_qh = I('team_qh'); $pdgoodsnum = I('pdgoodsnum/d', 0); //如果是拼单 if ($ispt) { $name = 'pind' . $pdid . '-' . $stoid; //拼单队列控制 for ($i = 0; $i < $pdgoodsnum; $i++) { $this->redis->lPush($name, time() . '_' . $i); } if ($team_qh && $ispt == '2') { $name2 = 'pind' . $pdid . '-' . $team_qh . $stoid; $this->redis->lPush($name2, time() . '_0' ); } $key=$no.'-6-'.$pdid.'-'.$pdgoodsnum.'-'.$notime; $this->redis->sRem('redis_set_'.$stoid,$key); } } } //取消订单,处理会员团 public function clearOrder(){ $id=I("id"); $order = M('order')->where(array('order_id'=>$id,'store_id'=>getMobileStoId())) ->find(); //检查是否未支付订单 已支付联系客服处理退款 if(empty($order)) return json(array('code'=>-1,'msg'=>'订单不存在','result'=>'')); //要计算是否满团,满团就要提示并刷新页面,团失败也要刷新页面 //如果是redis满,就要重新换个会员在等支付 $wh['store_id']=getMobileStoId(); $wh['listno']=$order['pt_listno']; $wh['team_id']=$order['pt_prom_id']; $tgr=M("teamgroup")->where($wh)->find(); //如果团是进行中 if($tgr['state']==2){ $user_id = $order['user_id']; $row = M('order')->where(array('order_id' => $id, 'user_id' => $user_id)) ->where('order_status=0 or order_status=1') ->where('pt_status', 0) ->save(array('order_status' => 3)); if ($row) { //获取记录表信息 //$log = M('account_log')->where(array('order_id'=>$order_id))->find(); //有余额支付的情况 if ($order['user_money'] > 0) { //解冻冻余额 $rs = M('Users')->where("user_id", $user_id) ->where('frozen_money>=' . $order['user_money'])->find(); if ($rs) { M('Users')->where("user_id", $user_id)->setDec('frozen_money', $order['user_money']); } } /*---优惠券冻结---*/ $quanno = $order['coupon_no']; if (!empty($quanno)) { $dada = ['CashRepNo' => $quanno, 'user_id' => $user_id]; //冻结优惠券 M('frozen_quan')->where($dada)->delete(); } /*---优惠券冻结---*/ $quanno = $order['coupon_no']; if (!empty($quanno)) { $dada = ['CashRepNo' => $quanno, 'user_id' => $user_id]; //冻结优惠券 M('frozen_quan')->where($dada)->delete(); } //查一下拼团 $stoid = $order['store_id']; if ($order['is_zsorder'] >= 2) { //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); //查找会员团,要补回人数 $v = $order; if ($v['is_zsorder'] == 3) { $name2 = 'pind' . $v['pt_prom_id'] . '-' . $v['pt_listno'] . $stoid; if (!doublefind($redis, $name2, $v['order_id'])) { $redis->lPush($name2, $v['order_id'] . '_0'); } $len = $redis->lLen($name2); //如果这个团,全部补回,那这个单就没有意思了,要delete掉 $teamnum = M('teamlist')->field('ct_num') ->where('id', $v['pt_prom_id'])->find(); if ($len == $teamnum['ct_num']) { //$redis->delete($name2); del_redis($redis,$name2); //更新团 $da['state'] = 1; $map['team_id'] = $v['pt_prom_id']; $map['listno'] = $v['pt_listno']; $map['store_id'] = $stoid; mlog("取消订单:".$v['pt_listno'].'-'.$v['order_id'],"clearOrder/".$stoid); M('teamgroup')->where($map)->save($da); } } //补回购买的数量 $hh = M('order_goods')->where('order_id', $id) ->where('prom_type', 6)->where('store_id', $stoid) ->field('order_id,goods_num,prom_id,rec_id')->select(); if ($hh) { //增加队列 foreach ($hh as $k => $v) { $name0 = 'pind' . $v['prom_id'] . '-' . $stoid; if (!doublefind($redis, $name2, $v['rec_id'])) { for ($i = 0; $i < $v['goods_num']; $i++) { $redis->lPush($name0, $v['rec_id'] . "_" . $i); } } } } //修改订单是状态 M('order')->where('order_id', $id)->save(['pt_status' => 3]); } $du['msg']='退回成功1'; $du['code']=1; return json($du); }else{ //$redis = new \Redis(); //$redis->connect(redisip, 6379); $redis=get_redis_handle(); $name2 = 'pind' . $order['pt_prom_id'] . '-' . $order['pt_listno'] . getMobileStoId(); $len = $redis->lLen($name2); if ($len == null || $len <= 0) { $neerodr = M("order")->where('store_id', getMobileStoId()) ->where('pt_listno', $order['pt_listno'])->where('pt_prom_id', $order['pt_prom_id']) ->where('pt_status', 0)->field('add_time') ->where('order_status=1 or order_status=0') ->field('add_time,order_id,user_id') ->find(); $us=M("users")->where('user_id',$neerodr['user_id'])->field('nickname')->find(); $tt = strtotime("+5 minute", (int)$neerodr['add_time']); $tt3 = $tt -time(); $du['needtime']=$tt3; $du['needtime_id']=$neerodr['order_id']; $du['nickname']=$us['nickname']; $du['code']=2; return json($du); }else{ $du['msg']='退回成功2'; $du['code']=1; return json($du); } } }else { //拼团失败 if($tgr['state']==1){ $du['msg']='拼团失败'; $du['code']=3; return json($du); }else{ $du['msg']='拼团成功'; $du['code']=3; return json($du); } } } //开团和参团在点击前都要判断 public function check_team_num(){ try { //循环更新订单状态,以及库存 $odr_arr = M('order') ->where('store_id', getMobileStoId()) ->where('user_id', $this->user_id) ->where('order_amount', 0) ->where('pt_status=0 and pt_prom_id>0') ->where('order_status=0 or order_status=1') ->field('order_sn')->select(); foreach ($odr_arr as $k => $v) { update_pay_status2($v['order_sn'], 1); } $team_qh = I("qh"); $pdid = I("team_id"); $stoid = getMobileStoId(); $ispt = I("ispt"); //判断是否成团,如果pt_status=0就是未支付,就是要跳转到支付页面 $ord = M('order')->where('user_id', $this->user['user_id']) ->where('store_id', $stoid)->where('pt_prom_id', $pdid) ->where('pt_status', 0)->field('order_id') ->where('order_status<>3')->find(); if ($ord) { return json(array('code' => -2, 'msg' => "您已经购买了该商品,待支付中!", 'id' => $ord['order_id'])); } else { //判断是否成团,如果pt_status=0就是未支付,就是要跳转到支付页面 $ord = M('order')->where('user_id', $this->user['user_id']) ->where('store_id', $stoid)->where('pt_prom_id', $pdid) ->where('pt_status', 1)->field('pt_prom_id,pt_listno') ->where('order_status<>3')->find(); if ($ord) { return json(array('code' => -3, 'msg' => "您已经购买了该商品,待成团中!", 'id' => $ord['pt_prom_id'], 'qh' => $ord['pt_listno'])); } } if (empty($this->redis)) { //$this->redis=new \Redis(); //$this->redis->connect(redisip, 6379); $this->redis = get_redis_handle(); } $name = 'pind' . $pdid . '-' . $stoid; $len0 = $this->redis->lLen($name); if ($len0 == 0 || $len0 == null) { return json(array('code' => -1, 'msg' => "您晚了一步,商品已被抢光!", 'result' => '')); } //如果,$ispt是会员团的时候,要判断团的缓存 if ($team_qh && $ispt == '2') { $name2 = 'pind' . $pdid . '-' . $team_qh . $stoid; $len1 = $this->redis->lLen($name2); if ($len1 == 0 || $len1 == null) { return json(array('code' => -4, 'msg' => "手慢了,您参与的团已满团!", 'result' => '')); } } $da['code'] = 1; $da['len0'] = $len0; $da['len1'] = $len1; return json($da); }catch (\Exception $e){ mlog("cuowu:".$e->getMessage(),"check_team_num/".getMobileStoId()); return json(array('code' => -9001, 'msg' => $e->getMessage(), 'result' => '')); } } }