assign('distribut_sharetitle', $distribut['distribut_sharetitle']); //分销标题 $this->assign('distribut_shareremark', $distribut['distribut_shareremark']);//分销备注 $this->assign('distribut_name', $distribut['name']);//分销备注 if (session('?user')) { $user = session('user'); $user = M('users')->where("user_id",$user['user_id'])->where("store_id", $sid)->find(); /*---当会员不是分销商且 可以直接成为分销商不用购买---*/ if ($distribut && $distribut['switch']==1 && $distribut['condition']==0){ if ($user['is_distribut']!= 1 && !empty($user['mobile']) && !empty($user['erpvipid'])){ $ty= M('store_distribut')->where('store_id',$sid)->field('distribut_num')->find(); $count1=M("users")->where('store_id',getMobileStoId())->where('is_distribut',1)->count(); //是否有购买 $is_out=M("store_module_endtime") ->where('store_id',getMobileStoId()) ->where('type',2)->find(); if($is_out){ if($ty['distribut_num']>$count1) { M('users')->where('store_id', $sid)->where('user_id', $user['user_id']) ->save(['is_distribut' => 1, 'be_distribut_time' => time(), 'be_dis_condition' => "直接成为分销商"]); //M('store_distribut')->where('store_id',$sid)->setDec('distribut_num'); $user['is_distribut']=1; } }else{ //看体验人数是否到了 $yy=M('distri_price')->where('type',0)->where('money',0)->find(); $allnum=$yy['user_num']; if($allnum>$count1){ M('users')->where('store_id', $sid)->where('user_id', $user['user_id']) ->save(['is_distribut' => 1, 'be_distribut_time' => time(), 'be_dis_condition' => "直接成为分销商"]); //M('store_distribut')->where('store_id',$sid)->setDec('distribut_num'); $user['is_distribut']=1; } } } } session('user', $user); //覆盖session 中的 user $this->user = $user; $this->user_id = $user['user_id']; $this->assign('user', $user); //存储用户信息 }else{ $uid=Cookie::get('user_id'); if($uid){ $user = M('users')->where("user_id", $uid)->where("store_id", $sid)->find(); /***当会员不是分销商且 可以直接成为分销商不用购买***/ if ($user['is_distribut']!= 1 && !empty($user['mobile']) && !empty($user['erpvipid'])){ $ty= M('store_distribut')->where('store_id',$sid)->field('distribut_num')->find(); $count1=M("users")->where('store_id',getMobileStoId())->where('is_distribut',1)->count(); //是否有购买 $is_out=M("store_module_endtime") ->where('store_id',getMobileStoId()) ->where('type',2)->find(); if($is_out){ if($ty['distribut_num']>$count1) { M('users')->where('store_id', $sid)->where('user_id', $user['user_id']) ->save(['is_distribut' => 1, 'be_distribut_time' => time(), 'be_dis_condition' => "直接成为分销商"]); //M('store_distribut')->where('store_id',$sid)->setDec('distribut_num'); $user['is_distribut']=1; } }else{ //看体验人数是否到了 $yy=M('distri_price')->where('type',0)->where('money',0)->find(); $allnum=$yy['user_num']; if($allnum>$count1){ M('users')->where('store_id', $sid)->where('user_id', $user['user_id']) ->save(['is_distribut' => 1, 'be_distribut_time' => time(), 'be_dis_condition' => "直接成为分销商"]); //M('store_distribut')->where('store_id',$sid)->setDec('distribut_num'); $user['is_distribut']=1; } } } session('user', $user); //覆盖session 中的 user $this->user = $user; $this->user_id = $user['user_id']; $this->assign('user', $user); //存储用户信息 } } $nologin = array( 'login','pop_login','do_login','logout','verify','set_pwd','finished', 'verifyHandle','reg','send_sms_reg_code','find_pwd','check_validate_code', 'forget_pwd','check_captcha','check_username','send_validate_code', ); if(!$this->user_id && !in_array(ACTION_NAME,$nologin)){ header("location:" . U('Mobile/User/login', array('stoid' => getMobileStoId()))); exit; } if (!in_array(ACTION_NAME, $nologin)) { if (($this->pm_erpid && (!$user || !$user['erpvipid'])) || (empty($this->pm_erpid) && !$user || !$user['mobile'])) { $this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId()))); exit; } } // $order_count = M('order')->where("user_id", $this->user_id)->count(); // 我的订单数 // $goods_collect_count = M('goods_collect')->where("user_id", $this->user_id)->count(); // 我的商品收藏 // $comment_count = M('comment')->where("user_id", $this->user_id)->count();// 我的评论数 // $this->assign('order_count',$order_count); // $this->assign('goods_collect_count',$goods_collect_count); // $this->assign('comment_count',$comment_count); } /** * 分销用户中心首页 */ public function index(){ $user = $user_info = M('users')->where('user_id',$this->user_id)->find(); if(!$user){ $this->redirect(U('mobile/User/login', array('stoid' => getMobileStoId()))); exit; } //我的余额 $current_money=$user['user_money']; $locking_money=M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money'); $lcmon=$user['frozen_money']; $liudong_money=number_format($current_money-$locking_money-$lcmon,2); //流动资金 $this->assign('liudong_money',$liudong_money); //累计获得佣金 //$money['achieve_money'] = Db::name('rebate_log')->where(['user_id'=>$this->user_id,'status'=>3])->sum('money'); $time=time(); $dy=date('Y-m-d'); $start=$dy.' 00:00:00'; $end=$dy.' 23:59:59'; $start = strtotime($start); $end = strtotime($end); $money['today_money'] = Db::name('rebate_log')->where("user_id=$this->user_id and status=3 and confirm_time>=".$start." and confirm_time<=".$end)->sum('money'); //今日收入 // 销售额 和 我的奖励 $result = DB::query("select sum(goods_price) as goods_price, sum(money) as money from __PREFIX__rebate_log where user_id = {$this->user_id} and status>0 and status<4"); $result = $result[0]; $result['goods_price'] = $result['goods_price'] ? $result['goods_price'] : 0; $result['money'] = $result['money'] ? $result['money'] : 0; // $lower_count[1] = M('users')->where("first_leader", $this->user_id)->count(); // $lower_count[2] = M('users')->where("second_leader", $this->user_id)->count(); // $lower_count[3] = M('users')->where("third_leader", $this->user_id)->count(); // 我的下线 订单数 /*---- $result2 = DB::query("select status,count(1) as c , sum(goods_price) as goods_price from `__PREFIX__rebate_log` where user_id = :user_id group by status",['user_id'=>$this->user_id]); $level_order = convert_arr_key($result2, 'status'); for($i = 0; $i <= 5; $i++) { $level_order[$i]['c'] = $level_order[$i]['c'] ? $level_order[$i]['c'] : 0; $level_order[$i]['goods_price'] = $level_order[$i]['goods_price'] ? $level_order[$i]['goods_price'] : 0; } $withdrawals_money = M('withdrawals')->where(['user_id'=>$this->user_id,'status'=>1])->sum('money');--*/ //print_r($level_order); $this->assign('user_id',$this->user_id); //$this->assign('level_order',$level_order); // 下线订单 //$this->assign('lower_count',$lower_count); // 下线人数 $this->assign('sales_volume',$result['goods_price']); // 销售额 //$this->assign('reward',$result['money']);// 奖励 //$this->assign('withdrawals_money',$withdrawals_money);// 已提现财富 $this->assign('money',$money); upload_ylp_log('分销用户中心'); return $this->fetch('',getMobileStoId()); } /** * 下线列表 */ public function lower_list(){ $level = I('get.level',1); $q = I('post.q','','trim'); $condition = array(1=>'first_leader',2=>'second_leader',3=>'third_leader'); $where = "{$condition[$level]} = {$this->user_id}"; $bind = array(); if($q){ $where .= " and (nickname like :q1 or user_id = :q2 or mobile = :q3)"; $bind['q1'] = "%$q%"; $bind['q2'] = $q; $bind['q3'] = $q; } $count = M('users')->where($where)->bind($bind)->count(); $page = new Page($count,10); $list = M('users')->where($where)->bind($bind)->limit("{$page->firstRow},{$page->listRows}")->order('user_id desc')->select(); $this->assign('count', $count);// 总人数 $this->assign('page', $page->show());// 赋值分页输出 $this->assign('list',$list); // 下线 if($_GET['is_ajax']) { return $this->fetch('ajax_lower_list',getMobileStoId()); exit; } upload_ylp_log('下线列表'); return $this->fetch('',getMobileStoId()); } /** * 下线订单列表 */ public function order_list(){ $status = I('get.status',0); $where = ['user_id'=>$this->user_id,'status'=>['in',$status]]; $count = M('rebate_log')->where($where)->count(); $page = new Page($count,10); $list = M('rebate_log')->where($where)->order('id desc')->limit("{$page->firstRow},{$page->listRows}")->select(); foreach ($list as $k=>$v){ $jsonarr=null; if($v['commission_json']) $jsonarr=json_decode($v['commission_json'],true); $ordid=$v['order_id']; $goodlist=M('order_goods')->alias('a')->join('goods b','a.goods_id=b.goods_id','left')->where('a.order_id='.$ordid)->field('a.goods_num,b.goods_name,b.original_img,b.goods_id,a.goods_price,b.goods_spec,b.goods_color,b.commission,a.prom_type,b.shop_price')->select(); foreach($goodlist as $kk=>$vv){ $promt=$vv['prom_type']; $goods_id=$vv['goods_id']; //给积分购的 if(doubleval($vv['goods_price'])<=0) $goodlist[$kk]['goods_price']=$vv['shop_price']; //如果是还没有记录 if(empty($jsonarr)){ $now0 = $v['create_time']; switch ($promt) { case "1": $where0 = [ 'end_time' => ['>=', $now0], 'start_time' => ['<=', $now0], 'goods_id' => $goods_id, ]; $ry = M('flash_sale')->where($where0)->find(); if ($ry) { $goodlist[$kk]['commission'] = $ry['commission']; } break; case "2": $where0 = [ 'end_time' => ['>=', $now0], 'start_time' => ['<=', $now0], 'goods_id' => $goods_id, ]; $ry = M('group_buy')->where($where0)->find(); if ($ry) { $goodlist[$kk]['commission'] = $ry['commission']; } break; case "4": $where0 = [ 'end_time' => ['>=', $now0], 'start_time' => ['<=', $now0], 'goods_id' => $goods_id, ]; $ry = M('integral_buy')->where($where0)->find(); if ($ry) { $goodlist[$kk]['commission'] = $ry['commission']; } break; } }else{ //分销模式 if($v['dis_moshi']==1){ $goodlist[$kk]['commission']=0; foreach ($jsonarr as $k1=>$v1) { switch ($v['level']) { case 1:$goodlist[$kk]['commission'] = $v1['fir']; break; case 2:$goodlist[$kk]['commission'] = $v1['sec']; break; case 3:$goodlist[$kk]['commission'] = $v1['thi']; break; } } }else{ $goodlist[$kk]['commission']=0; foreach ($jsonarr as $k1=>$v1){ if($goods_id==$v1['goods_id']){ $goodlist[$kk]['commission']=$v1['commission']/$vv['goods_num']; break; } } } } } $list[$k]['goods']=$goodlist; } $user_id_list = get_arr_column($list, 'buy_user_id'); if(!empty($user_id_list)) $userList = M('users')->where("user_id", "in", implode(',', $user_id_list))->getField('user_id,nickname,mobile,head_pic'); $p=I("p/d",1); if($count<=$p*10){ $this->assign('mshow',0); }else{ $this->assign('mshow',1); } $this->assign('count', $count);// 总人数 $this->assign('page', $page->show());// 赋值分页输出 $this->assign('userList',$userList); // $this->assign('list',$list); // 下线 if($_GET['is_ajax']) { return $this->fetch('ajax_order_list',getMobileStoId()); exit; } upload_ylp_log('下线订单列表'); return $this->fetch('',getMobileStoId()); } /** * 验证码验证 * $id 验证码标示 */ private function verifyHandle($id) { $verify = new Verify(); if (!$verify->check(I('post.verify_code'), $id ? $id : 'user_login')) { $this->error("验证码错误"); } } /** * 验证码获取 */ public function verify() { //验证码类型 $type = I('get.type') ? I('get.type') : 'user_login'; $config = array( 'fontSize' => 40, 'length' => 4, 'useCurve' => true, 'useNoise' => false, ); $Verify = new Verify($config); $Verify->entry($type); } /* *个人推广二维码 */ public function qr_code(){ //$ShareLink = urlencode("http://{$_SERVER[HTTP_HOST]}/Mobile/Index/index/stoid/".getMobileStoId()."/first_leader/{$this->user_id}"); //默认分享链接 $url=curHostURL()."/Mobile/Distribut/myshop/stoid/".getMobileStoId()."/user/{$this->user_id}/first_leader/{$this->user_id}"; $msg=base64EncodeImage($this->user['head_pic'],3); if($msg['status']=='success') { $this->assign('imgsrc', $msg['data']); } $ShareLink = urlencode($url); //默认分享链接 if($this->user['is_distribut'] == 1) $this->assign('ShareLink',$ShareLink); upload_ylp_log('个人推广二维码'); return $this->fetch('',getMobileStoId()); } /** * 分类列表显示 */ public function categoryList(){ $zmsql="select zm from __PREFIX__brand where store_id=".getMobileStoId()." group by zm"; $brand_zm=DB::query($zmsql); // var_dump($brand_zm); foreach ($brand_zm as $val) { $zmsql1="select id,name,logo from __PREFIX__brand where store_id=".getMobileStoId()." and zm='".$val['zm']."'";// $brand_zm1=DB::query($zmsql1); $arr[]=['zm'=>$val['zm'],'tmenu'=>$brand_zm1]; } // var_dump($brand_zm); // die(); $this->assign('brand_list',$arr); $this->assign('brand_zm',$brand_zm); $ad=M('ad')->where('store_id',getMobileStoId())->where('pid=400') ->cache("categoryList_ad_".getMobileStoId(),TPSHOP_CACHE_TIME)->find(); $this->assign('ad',$ad); $nationlist=M('nation')->where('store_id='.getMobileStoId())->select(); $this->assign('nation_list',$nationlist); upload_ylp_log('分类列表显示'); return $this->fetch("",getMobileStoId()); } /** * 商品列表页 */ public function goodsList(){ $filter_param = array(); // 帅选数组 $id = I('id/d',0); // 当前分类id $brand_id = I('brand_id/d',0); $nation_id = I('nation_id/d',0); $spec = I('spec',0); // 规格 $attr = I('attr',''); // 属性 $sort = I('sort','goods_id'); // 排序 $sort_asc = I('sort_asc','desc'); // 排序 $price = I('price',''); // 价钱 $start_price = trim(I('start_price','0')); // 输入框价钱 $end_price = trim(I('end_price','0')); // 输入框价钱 if($start_price && $end_price) $price = $start_price.'-'.$end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入筛选条件中 $nation_id && ($filter_param['nation_id'] =$nation_id); //加入筛选条件中 $spec && ($filter_param['spec'] = $spec); //加入筛选条件中 $attr && ($filter_param['attr'] = $attr); //加入筛选条件中 $price && ($filter_param['price'] = $price); //加入筛选条件中 $goodsLogic = new \app\home\logic\DistributLogic(); // 前台商品操作逻辑类 // 分类菜单显示 $goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类 //($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆 //$cateArr = $goodsLogic->get_goods_cate($goodsCate); // 帅选 品牌 规格 属性 价格 $filter_goods_id=null; if(!empty($id)) { $cat_id_arr = getCatGrandson($id); /*--商品修改。store_id筛选条件--*/ $filter_goods_id = M('goods')->where('store_id', getMobileStoId())->where("is_on_sale=1")->where("cat_id", "in", implode(',', $cat_id_arr))->getField("goods_id", true); }else{ $filter_goods_id = M('goods')->where('store_id', getMobileStoId())->where("is_on_sale=1")->getField("goods_id", true); } // 过滤帅选的结果集里面找商品 if($brand_id || $price || $nation_id )// 品牌或者价格 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id,$price,$nation_id); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_1); // 获取多个帅选条件的结果 的交集 } if($spec)// 规格 { $goods_id_2 = $goodsLogic->getGoodsIdBySpec($spec); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_2); // 获取多个帅选条件的结果 的交集 } if($attr)// 属性 { $goods_id_3 = $goodsLogic->getGoodsIdByAttr($attr); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_3); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel =I('sel'); if($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel,$cat_id_arr); $filter_goods_id = array_intersect($filter_goods_id,$goods_id_4); } $filter_menu = $goodsLogic->get_filter_menu($filter_param,'goodsList'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($filter_goods_id,$filter_param,'goodsList'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选品牌 $filter_spec = $goodsLogic->get_filter_spec($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选规格 $filter_attr = $goodsLogic->get_filter_attr($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选属性 $count = count($filter_goods_id); $page = new Page($count,2); if($count > 0) { $goods_list = M('goods')->where("goods_id","in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow.','.$page->listRows)->select(); $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if($filter_goods_id2) $goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2)) ->cache("goods_list_goods_images_".getMobileStoId())->select(); } $goods_category = M('goods_category')->where('is_show=1') ->cache("good_list_goods_category_".getMobileStoId())->getField('id,name,parent_id,level'); // 键值分类数组 $this->assign('goods_list',$goods_list); $this->assign('goods_category',$goods_category); $this->assign('goods_images',$goods_images); // 相册图片 $this->assign('filter_menu',$filter_menu); // 帅选菜单 $this->assign('filter_spec',$filter_spec); // 帅选规格 $this->assign('filter_attr',$filter_attr); // 帅选属性 $this->assign('filter_brand',$filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_price',$filter_price);// 帅选的价格期间 $this->assign('goodsCate',$goodsCate); //$this->assign('cateArr',$cateArr); $this->assign('filter_param',$filter_param); // 帅选条件 $this->assign('cat_id',$id); $this->assign('page',$page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON',false); upload_ylp_log('分销商品列表'); if(input('is_ajax')) return $this->fetch('ajaxGoodsList',getMobileStoId()); //return $this->fetch(); else // return $this->fetch('',getMobileStoId()); return $this->fetch(); } /** * 商品列表页 ajax 翻页请求 搜索 */ public function ajaxGoodsList() { $where =''; $cat_id = I("id",0); // 所选择的商品分类id if($cat_id > 0) { $grandson_ids = getCatGrandson($cat_id); $where .= " WHERE cat_id in(". implode(',', $grandson_ids).") "; // 初始化搜索条件 } /*--商品修改,store_id筛选条件--*/ $where.=' and store_id='.getMobileStoId(); $result = DB::query("select count(1) as count from __PREFIX__goods $where "); $count = $result[0]['count']; $page = new AjaxPage($count,10); $order = " order by goods_id desc"; // 排序 $limit = " limit ".$page->firstRow.','.$page->listRows; $list = DB::query("select * from __PREFIX__goods $where $order $limit"); $this->assign('lists',$list); $html = $this->fetch('ajaxGoodsList',getMobileStoId()); //return $this->fetch('ajax_goods_list'); upload_ylp_log('分销商品分页列表'); exit($html); } /** * 商品详情页 */ public function goodsInfo(){ C('TOKEN_ON',true); $goodsLogic = new \app\home\logic\DistributLogic(); $goods_id = I("get.id"); $goods = M('Goods')->where("goods_id", $goods_id)->where('is_on_sale',1)->find(); if(empty($goods)){ $this->tp404('此商品不存在或者已下架'); } 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']; } $goods_images_list = M('GoodsImages')->where("goods_id", $goods_id)->select(); // 商品 图册 // $goods_attribute = M('GoodsAttribute')->getField('attr_id,attr_name'); // 查询属性 // $goods_attr_list = M('GoodsAttr')->where("goods_id", $goods_id)->select(); // 查询商品属性表 //$filter_spec = $goodsLogic->get_spec($goods_id); $filter_spec=M('goods')->where('sku',$goods['sku'])->where("is_on_sale",1)->select(); // $spec_goods_price = M('spec_goods_price')->where("goods_id", $goods_id)->getField("key,price,store_count"); // 规格 对应 价格 库存表 M('Goods')->where("goods_id=$goods_id")->save(array('click_count'=>$goods['click_count']+1 )); //统计点击数 $commentStatistics = $goodsLogic->commentStatistics($goods_id);// 获取某个商品的评论统计 // $this->assign('spec_goods_price', json_encode($spec_goods_price,true)); // 规格 对应 价格 库存表 $goods['sale_num'] = M('order_goods')->where(['goods_id'=>$goods_id,'is_send'=>1])->count(); //商品促销 if($goods['prom_type'] == 1) { $prom_goods = M('prom_goods')->where(['id'=>$goods['prom_id'],'is_close'=>0])->find(); $this->assign('prom_goods',$prom_goods);// 商品促销 $goods['flash_sale'] = get_goods_promotion($goods['goods_id']); $flash_sale = M('flash_sale')->where("id", $goods['prom_id'])->find(); $this->assign('flash_sale',$flash_sale); $goods['discount'] = round($goods['flash_sale']['price']/$goods['shop_price'],2)*10; }else{ $goods['discount'] = round($goods['shop_price']/$goods['market_price'],2)*10; } //当前用户收藏 $user_id = cookie('user_id'); //$collect = M('goods_collect')->where("goods_id=$goods_id and user_id=$user_id")->count(); $collect = M('goods_collect')->where(array("goods_id"=>$goods_id ,"user_id"=>$user_id))->count(); $goods_collect_count = M('goods_collect')->where(array("goods_id"=>$goods_id))->count(); //商品收藏数 $this->assign('collect',$collect); $this->assign('commentStatistics',$commentStatistics);//评论概览 // $this->assign('goods_attribute',$goods_attribute);//属性值 // $this->assign('goods_attr_list',$goods_attr_list);//属性列表 $this->assign('filter_spec',$filter_spec);//规格参数 $this->assign('goods_images_list',$goods_images_list);//商品缩略图 $this->assign('goods',$goods); $this->assign('goods_collect_count',$goods_collect_count); //商品收藏人数 upload_ylp_log('分销商品详情'); return $this->fetch('',getMobileStoId()); } /** * 商品详情页 */ public function detail(){ // form表单提交 C('TOKEN_ON',true); $goods_id = I("get.id/d"); $goods = M('Goods')->where("goods_id", $goods_id)->find(); $this->assign('goods',$goods); upload_ylp_log('分销商品详情'); return $this->fetch('',getMobileStoId()); } /* * 商品评论 */ public function comment(){ $goods_id = I("goods_id/d",0); $this->assign('goods_id',$goods_id); upload_ylp_log('分销商品评论'); return $this->fetch('',getMobileStoId()); } /* * ajax获取商品评论 */ public function ajaxComment(){ $goods_id = I("goods_id/d",0); $commentType = I('commentType','1'); // 1 全部 2好评 3 中评 4差评 if($commentType==5){ $where = "goods_id = :goods_id and parent_id = 0 and img !='' "; }else{ $typeArr = array('1'=>'0,1,2,3,4,5','2'=>'4,5','3'=>'3','4'=>'0,1,2'); $where = "goods_id = :goods_id and parent_id = 0 and ceil((deliver_rank + goods_rank + service_rank) / 3) in($typeArr[$commentType])"; } $where.=' and store_id='.getMobileStoId(); $count = M('Comment')->where($where)->bind(['goods_id'=>$goods_id])->count(); $page_count = 5; $page = new AjaxPage($count,$page_count); $list = M('Comment') ->alias('c') ->join('__USERS__ u','u.user_id = c.user_id','LEFT') ->where($where) ->bind(['goods_id'=>$goods_id]) ->order("add_time desc") ->limit($page->firstRow.','.$page->listRows) ->select(); $replyList = M('Comment')->where(['goods_id'=>$goods_id,'parent_id'=>['>',0]])->order("add_time desc")->select(); foreach($list as $k => $v){ $list[$k]['img'] = unserialize($v['img']); // 晒单图片 } $this->assign('goods_id',$goods_id);//商品id $this->assign('commentlist',$list);// 商品评论 $this->assign('commentType',$commentType);// 1 全部 2好评 3 中评 4差评 5晒图 $this->assign('replyList',$replyList); // 管理员回复 $this->assign('count', $count);//总条数 $this->assign('page_count', $page_count);//页数 $this->assign('current_count', $page_count*I('p'));//当前条 $this->assign('p', I('p'));//页数 upload_ylp_log('ajax获取商品评论'); return $this->fetch('',getMobileStoId()); } /* * 获取商品规格 */ public function goodsAttr(){ $goods_id = I("get.goods_id/d",0); $goods_attribute = M('GoodsAttribute')->getField('attr_id,attr_name'); // 查询属性 $goods_attr_list = M('GoodsAttr')->where("goods_id", $goods_id)->select(); // 查询商品属性表 $this->assign('goods_attr_list',$goods_attr_list); $this->assign('goods_attribute',$goods_attribute); upload_ylp_log('获取商品规格'); return $this->fetch('',getMobileStoId()); } /** * 积分商城 */ public function integralMall() { $rank= I('get.rank'); //以兑换量(购买量)排序 if($rank == 'num'){ $ranktype = 'sales_sum'; $order = 'desc'; } //以需要积分排序 if($rank == 'integral'){ $ranktype = 'exchange_integral'; $order = 'desc'; } $point_rate = tpCache('shopping.point_rate',getMobileStoId()); $goods_where = array( 'is_on_sale' => 1, //是否上架 ); //积分兑换筛选 $exchange_integral_where_array = array(array('gt',0)); // 分类id if (!empty($cat_id)) { $goods_where['cat_id'] = array('in', getCatGrandson($cat_id)); } //我能兑换 $user_id = cookie('user_id'); if (!empty($user_id)) { //获取用户积分 $user_pay_points = intval(M('users')->where(array('user_id' => $user_id))->getField('pay_points')); if ($user_pay_points !== false) { array_push($exchange_integral_where_array, array('lt', $user_pay_points)); } } $goods_where['exchange_integral'] = $exchange_integral_where_array; //拼装条件 $goods_list_count = M('goods')->where($goods_where)->count(); //总页数 $page = new Page($goods_list_count, 15); $goods_list = M('goods')->where($goods_where)->order($ranktype ,$order)->limit($page->firstRow . ',' . $page->listRows)->select(); $goods_category = M('goods_category')->where(array('level' => 1))->select(); $this->assign('goods_list', $goods_list); $this->assign('page', $page->show()); $this->assign('goods_list_count',$goods_list_count); $this->assign('goods_category', $goods_category);//商品1级分类 $this->assign('point_rate', $point_rate);//兑换率 $this->assign('totalPages',$page->totalPages);//总页数 if(IS_AJAX){ return $this->fetch('ajaxIntegralMall',getMobileStoId()); //获取更多 } upload_ylp_log('积分商城'); return $this->fetch('',getMobileStoId()); } /** * 我的小店 */ public function myshop(){ $stoid=I('stoid/d'); $time=time(); // $filter_param = array(); // 帅选数组 // $id = I('get.id/d',0); // 当前分类id // $brand_id = I('brand_id',0); // $nation_id = I('nation_id',0); // $price = I('price',''); // 价钱 $sort = I('sort','on_time'); // 排序 $sort_asc = I('sort_asc','desc'); // 排序 // $start_price = trim(I('start_price','0')); // 输入框价钱 // $end_price = trim(I('end_price','0')); // 输入框价钱 // if($start_price && $end_price) $price = $start_price.'-'.$end_price; // 如果输入框有价钱 则使用输入框的价钱 // $id && $filter_param['id'] = $id; //加入帅选条件中 // $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 // $price && ($filter_param['price'] = $price); //加入帅选条件中 // $nation_id && ($filter_param['nation_id'] = $nation_id); //加入帅选条件中 $key = urldecode(trim(I('key',''))); // 关键字搜索 // $key && ($filter_param['key'] = $key); //加入帅选条件中 // $qtype = I('qtype',''); // if($qtype){ // //$where = array('is_on_sale' => 1); // $filter_param['qtype'] = $qtype; // $where[$qtype] = 1; // } if($key) $where['keywords|goods_sn|goods_name|sku'] = array('like','%'.$key.'%'); $where['store_id']=$stoid; $where['is_on_sale']=1; $type=I('type/d',1); if($type==2){ $where['is_new']=1; } $first_leader=I("first_leader"); $userid=$first_leader; if(empty($userid)){ $userid=$this->user_id; }else{ $luser=M('users')->where('user_id',$first_leader)->find(); $this->assign('luser',$luser); } $goodsarr=[]; /*--个人上架商品--*/ $disgoods=M("distribut_usergoods")->where("store_id",getMobileStoId()) ->where("user_id",$userid)->where("isup",1)->getField('good_id',true); $goodsarr= array_merge($goodsarr, $disgoods); /*--数组合并--*/ /*--主营商品--*/ $zhugoods=M('goods')->where("dis_type=0")->where("store_id",getMobileStoId())->getField('goods_id',true); $goodsarr= array_merge($goodsarr, $zhugoods); /*--数组合并--*/ /*--筛选的商品集合--*/ $filter_goods_id=$goodsarr; if($goodsarr) { $ms=tpCache('distribut.pattern',$stoid); $where1='on_time<'.$time.' and down_time>'.$time.' or down_time=0 or down_time is null or down_time=""'; $where2="1=1"; if($ms==0) $where2.=' and commission>0'; if($ms==1) $where2.=' and (fir_rate+sec_rate+thi_rate>0)'; /*--全部商品--*/ $allcount = M("goods")->where("is_on_sale", 1)->where($where1)->where($where2)->where('goods_id', "in", $goodsarr)->count(); $this->assign('allcount', $allcount); /*--新品品--*/ $newcount = M("goods")->where("is_on_sale", 1)->where($where1)->where($where2)->where('goods_id', "in", $goodsarr)->where('is_new=1')->count(); $this->assign('newcount', $newcount); // $goodsLogic = new \app\home\logic\DistributLogic(); // 前台商品操作逻辑类 // 过滤帅选的结果集里面找商品 // if ($brand_id || $nation_id)// 品牌或者国别 // { // $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id, $nation_id); // 根据 品牌 或者 价格范围 查找所有商品id // $filter_goods_id = array_intersect($filter_goods_id, $goods_id_1); // 获取多个帅选条件的结果 的交集 // } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 // $sel = I('sel'); // if ($sel) { // $goods_id_4 = $goodsLogic->get_filter_selected($sel); // $filter_goods_id = array_intersect($filter_goods_id, $goods_id_4); // } //$filter_menu = $goodsLogic->get_filter_menu($filter_param, 'search'); // 获取显示的帅选菜单 /*--如果有价格条件--*/ // $where1=""; // if($price) { // $pricearr = explode('-', $price); // $where1=" having final_price>=".$pricearr[0]." and final_price<=".$pricearr[1]; // } /*--算出总数--*/ $cm = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id)) ->where($where2) ->where($where)->where($where1)->getField("goods_id", true); $cm=implode(',',$cm); if (empty($cm)) $cm=0; $str="select a.goods_name,a.goods_id,a.original_img, a.sales_sum,a.commission,a.is_new,a.mz_price,a.prom_type,a.prom_id,a.cardprice1,a.cardprice2,a.cardprice3,CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'') or (a.prom_type=6 and b.id<>'') then b.prom_price else a.shop_price end as decimal(9,2)) as final_price,b.prom_integral from __PREFIX__goods a left join (select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist where is_end=0 and (s_time<=" . $time . " or (warm_uptime<=" . $time . " and warm_uptime<>0)) and e_time>=" . $time . " and store_id=" . $stoid . ") as b on locate(CONCAT(',',a.goods_id,','), b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) where a.goods_id in(".$cm.") order by ".$sort." ".$sort_asc; $arr=Db::query($str); $count = count($arr); //$pricearr=get_arr_column($arr,'final_price'); //$filter_price = $goodsLogic->get_filter_price2($pricearr, $filter_param, 'search',1); // 帅选的价格期间 //$filter_nation = $goodsLogic->get_filter_nation($filter_goods_id, $filter_param, 'search'); // 帅选的价格期间 //$filter_brand = $goodsLogic->get_filter_brand($filter_goods_id, $filter_param, 'search', 1); // 获取指定分类下的帅选品牌 /*--计算分页--*/ $end=I('p/d',1)*10; // $mshow=0; if ($count > 0) { $fir=I('p/d',1)*10-10; if($count<$end) $end=$count; for($i=$fir;$i<$end;$i++){ $arr[$i]['final_price']= number_format($arr[$i]['final_price'],2); $goods_list[]=$arr[$i]; } } if ($count > I('p/d', 1) * 10) { $this->assign('mshow', 1); } else { $this->assign('mshow', 0); } $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格 if ($rank_switch){ //$this->assign('rank_field',session('user')['card_field']); $user=session('user'); $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']); $card_field=$rand_end>time()?$user['card_field']:0; $this->assign('rank_field',$card_field); } $this->assign('mz_vip',session('user')['is_mzvip']); $this->assign('stoid', getMobileStoId()); $this->assign('goods_list', $goods_list); //$this->assign('goods_category', $goods_category); //$this->assign('goods_images', $goods_images); // 相册图片 // $this->assign('filter_menu', $filter_menu); // 帅选菜单 // $this->assign('filter_brand', $filter_brand);// 列表页帅选属性 - 商品品牌 // $this->assign('filter_price', $filter_price);// 帅选的价格期间 // $this->assign('filter_nation', $filter_price);// 帅选的价格期间 // $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('key',$key); //$this->assign('page', $page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON', false); upload_ylp_log('我的小店'); if (input('is_ajax')) return $this->fetch('ajaxGoodsList', getMobileStoId()); else return $this->fetch('', getMobileStoId()); } } /** * 我的分销商品 */ public function search(){ $filter_param = array(); // 帅选数组 $id = I('get.id/d',0); // 当前分类id $brand_id = I('brand_id',0); $sort = I('sort','is_new'); // 排序 $sort_asc = I('sort_asc','desc'); // 排序 $price = I('price',''); // 价钱 $start_price = trim(I('start_price','0')); // 输入框价钱 $end_price = trim(I('end_price','0')); // 输入框价钱 if($start_price && $end_price) $price = $start_price.'-'.$end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $q = urldecode(trim(I('q',''))); // 关键字搜索 $q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中 $qtype = I('qtype',''); if($qtype){ //$where = array('is_on_sale' => 1); $filter_param['qtype'] = $qtype; $where[$qtype] = 1; } if($q) $where['goods_name'] = array('like','%'.$q.'%'); $where['store_id']=getMobileStoId(); $where['is_on_sale']=1; $goodsLogic = new \app\home\logic\DistributLogic(); // 前台商品操作逻辑类 $filter_goods_id = M('goods')->where($where)->getField("goods_id",true); // 过滤帅选的结果集里面找商品 if($brand_id || $price)// 品牌或者价格 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id,$price); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_1); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel = I('sel'); if($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel); $filter_goods_id = array_intersect($filter_goods_id,$goods_id_4); } $filter_menu = $goodsLogic->get_filter_menu($filter_param,'search'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($filter_goods_id,$filter_param,'search'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id,$filter_param,'search',1); // 获取指定分类下的帅选品牌 $count = count($filter_goods_id); $page = new Page($count,10); if($count > 0) { $goods_list = M('goods')->where("goods_id", "in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->alias('a') ->join('wxd_distribut_usergoods w',"a.goods_id = w.good_id and a.store_id = w.store_id and user_id=".$this->user_id,'LEFT')->where("a.dis_type=0 OR w.isup=1")->limit($page->firstRow.','.$page->listRows)->select(); $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if($filter_goods_id2) $goods_images = M('goods_images') ->where("goods_id", "in", implode(',', $filter_goods_id2))->select(); } $goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 if($count>I('p/d',0)*10){ $this->assign('mshow', 1); }else{ $this->assign('mshow', 0); } $this->assign('stoid',getMobileStoId()); $this->assign('goods_list',$goods_list); $this->assign('goods_category',$goods_category); $this->assign('goods_images',$goods_images); // 相册图片 $this->assign('filter_menu',$filter_menu); // 帅选菜单 $this->assign('filter_brand',$filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_price',$filter_price);// 帅选的价格期间 $this->assign('filter_param',$filter_param); // 帅选条件 $this->assign('page',$page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON',false); upload_ylp_log('我的分销商品'); if(input('is_ajax')) return $this->fetch('ajaxGoodsList',getMobileStoId()); else return $this->fetch('',getMobileStoId()); } /** * 分销商品搜索列表页 */ public function searchdistribution(){ $uid = Cookie::get('user_id'); $this->assign('uid', $uid); $stoid=I('stoid/d'); $filter_param = array(); // 帅选数组 $id = I('get.id/d',0); // 当前分类id $brand_id = I('brand_id',0); $nation_id = I('nation_id',0); $price = I('price',''); // 价钱 $sort = I('sort','on_time'); // 排序 $sort_asc = I('sort_asc','desc'); // 排序 $start_price = trim(I('start_price','0')); // 输入框价钱 $end_price = trim(I('end_price','0')); // 输入框价钱 if($start_price && $end_price) $price = $start_price.'-'.$end_price; // 如果输入框有价钱 则使用输入框的价钱 $id && $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 $nation_id && ($filter_param['nation_id'] = $nation_id); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $q = urldecode(trim(I('q',''))); // 关键字搜索 $q && ($_GET['q'] = $filter_param['q'] = $q); //加入帅选条件中 $qtype = I('qtype',''); $time = time(); $pattern=tpCache('distribut.pattern',$stoid); $this->assign('pattern',$pattern); if($qtype){ $filter_param['qtype'] = $qtype; $where[$qtype] = 1; } if($q) $where['keywords|goods_sn|goods_name'] = array('like','%'.$q.'%'); $where['store_id']=getMobileStoId(); $where['is_on_sale']= 1; $where['dis_type']= 1; $where['on_time']=['<',$time]; if($sort=='select') $sort='on_time'; if ($sort=='dis_type') { $sort='on_time';$where['dis_type']=0; }else{ if($pattern==0) $where['commission']=['>',0]; if($pattern==1) $where['fir_rate|sec_rate|thi_rate']=['>',0]; } $goodsLogic = new \app\home\logic\DistributLogic(); // 前台商品操作逻辑类 $filter_goods_id = M('goods')->where($where)->where('down_time>'.$time.' or down_time=0 or down_time is null')->getField("goods_id",true); // 过滤帅选的结果集里面找商品 if($brand_id || $nation_id)// 品牌或者国别 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice2($brand_id,$nation_id); // 根据 品牌 或者 国别 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_1); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel = I('sel'); if($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel); $filter_goods_id = array_intersect($filter_goods_id,$goods_id_4); } $is_up=I('up',0); $filter_param['up']=$is_up; $distribut_goods=M('distribut_usergoods')->where(['store_id'=>$stoid,'user_id'=>$this->user_id,'isup'=>1])->getField('good_id',true); if(!empty($is_up)){ if (I('sort') !='dis_type') $filter_goods_id = array_intersect($filter_goods_id,$distribut_goods); // 获取多个帅选条件的结果 的交集 }else{ $filter_goods_id = array_diff($filter_goods_id,$distribut_goods); } $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id,$filter_param,'searchdistribution',1); // 获取指定分类下的帅选品牌 $filter_nation = $goodsLogic->get_filter_nation($filter_goods_id,$filter_param,'searchdistribution',1); // 获取指定分类下的帅选品牌 $this->assign('filter_param', $filter_param); // 帅选条件 $this->assign('filter_brand',$filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_nation',$filter_nation);// 列表页帅选属性 - 商品国别 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); $this->assign('stoid', getMobileStoId()); $this->assign('up',$is_up); $upmaxnum=tpCache('shop_info.distribut_goodsqty',$stoid); $isupnum=count($distribut_goods); $canupnum=$upmaxnum-$isupnum; $this->assign('canupnum',$canupnum); $this->assign('isupnum',$isupnum); if (input('is_ajax')) { /*--如果有价格条件--*/ $where = ""; if ($price) { $pricearr = explode('-', $price); $where = " having fcommission>=" . $pricearr[0] . " and fcommission<=" . $pricearr[1]; } if (empty($filter_goods_id)) { $filter_goods_id = [-1]; } $str = "select a.prom_type,a.mz_price,a.cardprice1,a.cardprice2,a.cardprice3,a.prom_id,a.prom_type,a.goods_name,a.goods_id,a.original_img,a.sales_sum,a.dis_type,a.fir_rate,a.sec_rate,a.thi_rate,CAST(case when (a.prom_type=1 or a.prom_type=2 or a.prom_type=4) and b.id<>'' then b.commission else a.commission end as decimal(9,2)) as fcommission,CAST(case when (a.prom_type>0 and a.prom_type<3 and b.id<>'') or (a.prom_type=4 and b.is_show=1 and b.id<>'') or (a.prom_type=6 and b.id<>'') then b.prom_price else a.shop_price end as decimal(9,2)) as final_price,b.prom_integral,c.isup from __PREFIX__goods a left join (select id,commission,is_show,prom_price,type,expression,prom_integral,goods_listid,good_object,prom_type from __PREFIX__activitylist where is_end=0 and (s_time<=" . $time . " or warm_uptime<=" . $time . ") and e_time>=" . $time . " and store_id=" . $stoid . ") as b on locate(CONCAT(',',a.goods_id,','),b.goods_listid)>0 and (b.good_object=1 or b.prom_type<>3) left join (select good_id,isup,store_id from __PREFIX__distribut_usergoods where user_id=" . $this->user_id ." ) c on a.goods_id=c.good_id and a.store_id=c.store_id where a.goods_id in(" . implode(',', $filter_goods_id) . ") and on_time<".$time." and (a.down_time>".$time." or a.down_time=0 or a.down_time is null or a.down_time='' ) order by " . $sort . " " . $sort_asc; //mlog($str,'searchdistribution/'.$stoid); $arr = Db::query($str); $count = count($arr); // $pricearr = get_arr_column($arr, 'fcommission'); $pricearr0 = get_arr_column($arr, 'final_price'); //$filter_menu = $goodsLogic->get_filter_menu($filter_param,'searchdistribution'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($pricearr0,$filter_param,'searchdistribution'); // 帅选的价格期间 $end = I('p/d', 1) * 10; // $mshow = 0; if ($count > 0) { $fir = I('p/d', 1) * 10 - 10; if ($count < $end) $end = $count; for ($i = $fir; $i < $end; $i++) { $prom_type=$arr[$i]['prom_type']; if($pattern==1) { if ($prom_type == 1) { $fb=M('flash_sale')->where('id',$arr[$i]['prom_id']) ->where('is_end',0)->where('edit_time>'.time())->find(); $arr[$i]['fir_rate']=$fb['fir_rate']; $arr[$i]['sec_rate']=$fb['sec_rate']; $arr[$i]['thi_rate']=$fb['thi_rate']; } if ($prom_type == 2) { $fb=M('group_buy')->where('id',$arr[$i]['prom_id']) ->where('is_end',0)->where('edit_time>'.time())->find(); $arr[$i]['fir_rate']=$fb['fir_rate']; $arr[$i]['sec_rate']=$fb['sec_rate']; $arr[$i]['thi_rate']=$fb['thi_rate']; } if ($prom_type == 4) { $fb=M('integral_buy')->where('id',$arr[$i]['prom_id'])->where('is_show',1) ->where('is_end',0)->where('edit_time>'.time())->find(); $arr[$i]['fir_rate']=$fb['fir_rate']; $arr[$i]['sec_rate']=$fb['sec_rate']; $arr[$i]['thi_rate']=$fb['thi_rate']; } } $arr[$i]['final_price'] = number_format($arr[$i]['final_price'], 2); $goods_list[] = $arr[$i]; } } //$goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 if ($count > I('p/d', 1) * 10) { $this->assign('mshow', 1); } else { $this->assign('mshow', 0); } $this->assign('user_id', $this->user_id); $this->assign('goods_list', $goods_list); //$this->assign('goods_category',$goods_category); //$this->assign('goods_images',$goods_images); // 相册图片 //$this->assign('filter_menu',$filter_menu); // 帅选菜单 if($filter_price) $this->assign('filter_price', json_encode($filter_price));// 帅选的价格期间 $rank_switch = tpCache('shopping.rank_switch',$stoid);//等级价格 $mz_switch = tpCache('shopping.is_beauty',$stoid);//美妆价格 if ($rank_switch){ //$this->assign('rank_field',session('user')['card_field']); $user=session('user'); $rand_end= empty($user['card_expiredate'])?0:strtotime($user['card_expiredate']); $card_field=$rand_end>time()?$user['card_field']:0; $this->assign('rank_field',$card_field); } if ($mz_switch){ $this->assign('mz_vip',session('user')['is_mzvip']); } //$this->assign('page',$page);// 赋值分页输出 C('TOKEN_ON', false); upload_ylp_log('分销商品列表'); return $this->fetch('ajaxdistribution', $stoid); } return $this->fetch('',$stoid); } /** * 商品搜索列表页 */ public function ajaxSearch() { return $this->fetch('',getMobileStoId()); } /** * 品牌街 */ public function brandstreet() { $getnum = 9; //取出数量 $goods=M('goods')->where(array('is_recommend'=>1,'is_on_sale'=>1)) ->page(1,$getnum)->cache("brandstreet_".getMobileStoId(),TPSHOP_CACHE_TIME)->select(); //推荐商品 for($i=0;$i<($getnum/3);$i++){ //3条记录为一组 $recommend_goods[] = array_slice($goods,$i*3,3); } $where = array( 'is_hot' => 1, //1为推荐品牌 ); $count = M('brand')->where($where)->count(); // 查询满足要求的总记录数 $Page = new Page($count,20); $show = $Page->show();// 分页显示输出 $brand_list = M('brand')->where($where)->limit($Page->firstRow.','.$Page->listRows)->order('sort desc')->select(); $this->assign('Page',$show); //赋值分页输出 $this->assign('recommend_goods',$recommend_goods); //品牌列表 $this->assign('brand_list',$brand_list); //推荐商品 upload_ylp_log('品牌街'); if(I('is_ajax')){ return $this->fetch('ajaxBrandstreet',getMobileStoId()); } return $this->fetch('',getMobileStoId()); } /** * 商品列表—分销商上下架 增加 20170321 */ public function goodsList_distribution() { $filter_param = array(); // 帅选数组 $id = I('id/d',0); // 当前分类id $brand_id = I('brand_id/d',0); $spec = I('spec',0); // 规格 $attr = I('attr',''); // 属性 $sort = I('sort','is_new'); // 排序 $sort_asc = I('sort_asc','desc'); // 排序 $price = I('price',''); // 价钱 $start_price = trim(I('start_price','0')); // 输入框价钱 $end_price = trim(I('end_price','0')); // 输入框价钱 if($start_price && $end_price) $price = $start_price.'-'.$end_price; // 如果输入框有价钱 则使用输入框的价钱 $filter_param['id'] = $id; //加入帅选条件中 $brand_id && ($filter_param['brand_id'] = $brand_id); //加入帅选条件中 $spec && ($filter_param['spec'] = $spec); //加入帅选条件中 $attr && ($filter_param['attr'] = $attr); //加入帅选条件中 $price && ($filter_param['price'] = $price); //加入帅选条件中 $goodsLogic = new \app\home\logic\DistributLogic(); // 前台商品操作逻辑类 // 分类菜单显示 $goodsCate = M('GoodsCategory')->where("id", $id)->find();// 当前分类 //($goodsCate['level'] == 1) && header('Location:'.U('Home/Channel/index',array('cat_id'=>$id))); //一级分类跳转至大分类馆 $cateArr = $goodsLogic->get_goods_cate($goodsCate); // 帅选 品牌 规格 属性 价格 $cat_id_arr = getCatGrandson ($id); $filter_goods_id = M('goods')->where("is_on_sale=1")->where("cat_id", "in" ,implode(',', $cat_id_arr))->getField("goods_id",true); // 过滤帅选的结果集里面找商品 if($brand_id || $price)// 品牌或者价格 { $goods_id_1 = $goodsLogic->getGoodsIdByBrandPrice($brand_id,$price); // 根据 品牌 或者 价格范围 查找所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_1); // 获取多个帅选条件的结果 的交集 } if($spec)// 规格 { $goods_id_2 = $goodsLogic->getGoodsIdBySpec($spec); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_2); // 获取多个帅选条件的结果 的交集 } if($attr)// 属性 { $goods_id_3 = $goodsLogic->getGoodsIdByAttr($attr); // 根据 规格 查找当所有商品id $filter_goods_id = array_intersect($filter_goods_id,$goods_id_3); // 获取多个帅选条件的结果 的交集 } //筛选网站自营,入驻商家,货到付款,仅看有货,促销商品 $sel =I('sel'); if($sel) { $goods_id_4 = $goodsLogic->get_filter_selected($sel,$cat_id_arr); $filter_goods_id = array_intersect($filter_goods_id,$goods_id_4); } $filter_menu = $goodsLogic->get_filter_menu($filter_param,'goodsList'); // 获取显示的帅选菜单 $filter_price = $goodsLogic->get_filter_price($filter_goods_id,$filter_param,'goodsList'); // 帅选的价格期间 $filter_brand = $goodsLogic->get_filter_brand($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选品牌 $filter_spec = $goodsLogic->get_filter_spec($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选规格 $filter_attr = $goodsLogic->get_filter_attr($filter_goods_id,$filter_param,'goodsList',1); // 获取指定分类下的帅选属性 $count = count($filter_goods_id); $page = new Page($count,2); if($count > 0) { $goods_list = M('goods')->where("goods_id","in", implode(',', $filter_goods_id))->order("$sort $sort_asc")->limit($page->firstRow.','.$page->listRows)->select(); $filter_goods_id2 = get_arr_column($goods_list, 'goods_id'); if($filter_goods_id2) $goods_images = M('goods_images')->where("goods_id", "in", implode(',', $filter_goods_id2))->select(); } $goods_category = M('goods_category')->where('is_show=1')->getField('id,name,parent_id,level'); // 键值分类数组 $this->assign('goods_list',$goods_list); $this->assign('goods_category',$goods_category); $this->assign('goods_images',$goods_images); // 相册图片 $this->assign('filter_menu',$filter_menu); // 帅选菜单 $this->assign('filter_spec',$filter_spec); // 帅选规格 $this->assign('filter_attr',$filter_attr); // 帅选属性 $this->assign('filter_brand',$filter_brand);// 列表页帅选属性 - 商品品牌 $this->assign('filter_price',$filter_price);// 帅选的价格期间 $this->assign('goodsCate',$goodsCate); $this->assign('cateArr',$cateArr); $this->assign('filter_param',$filter_param); // 帅选条件 $this->assign('cat_id',$id); $this->assign('page',$page);// 赋值分页输出 $this->assign('sort_asc', $sort_asc == 'asc' ? 'desc' : 'asc'); C('TOKEN_ON',false); if(input('is_ajax')) return $this->fetch('ajaxGoodsList'); else return $this->fetch(); } public function ajax_distribution_addapi() { $store_id = I('stoid'); $user_id = I('user_id'); $type = I('type/d'); $time = time(); $data = array(); $data['user_id'] = $user_id; $data['store_id'] = $store_id; if ($type == 0){ $goods = json_decode(I('goods'),true); foreach ($goods as $k => $v){ $data['good_id'] = $v; $add=M('distribut_usergoods')->where($data)->find(); if (!empty($add)){ $dataup['add_time'] = $time; $dataup['isup'] = 1; M('distribut_usergoods')->where($data)->update($dataup); }else{ $data['add_time'] = $time; $data['isup'] = 1; M('distribut_usergoods')->insert($data); } } }else{ $dis_goods=M('distribut_usergoods')->where(['user_id'=>$user_id,'store_id'=>$store_id])->getField("good_id",true); $goods = M('goods')->where(['commission' => ['>',0],'dis_type' => 1,'store_id' =>$store_id,'is_on_sale' =>1,'on_time'=>['<',$time],'goods_id'=>['not in',$dis_goods]]) ->where('down_time>'.$time.' or down_time=0 or down_time is null')->getField("goods_id",true); M('distribut_usergoods')->where(['user_id'=>$user_id,'store_id'=>$store_id])->save(['isup'=>1,'add_time'=>$time]); foreach ($goods as $k => $v){ $data['good_id'] = $v; $data['add_time'] = $time; $data['isup'] = 1; M('distribut_usergoods')->insert($data); } } $data=['msg'=>"上架成功"]; return json($data); } public function ajax_distribution_delapi() { $store_id = I('stoid'); $user_id = I('user_id'); $type = I('type/d'); $time = time(); $data = array(); $data['user_id'] = $user_id; $data['store_id'] = $store_id; if ($type == 0){ $goods = json_decode(I('goods'),true); foreach ($goods as $k => $v){ $data['good_id'] = $v; $datadel['del_time'] = $time; $datadel['isup'] = 0; M('distribut_usergoods')->where($data)->update($datadel); } }else{ M('distribut_usergoods')->where(['user_id'=>$user_id,'store_id'=>$store_id])->save(['isup'=>0,'del_time'=>$time]); } $data=['msg'=>"下架成功"]; return json($data); } //排行榜 public function ranking_list(){ $sort = I('get.sort', '0'); $p= I('get.p/d', 1); $pagenum=10; $where['a.store_id'] =getMobileStoId(); $where['a.is_distribut'] = 1; $linenum=0; $place="无"; $lists=null; if($sort=="0"){ $sort="distribut_money"; $where['a.distribut_money'] =array('neq',0); $count = M('users')->alias('a')->where($where)->count('user_id'); //总用户量 $Page = $pager = new AjaxPage($count,$pagenum); $show = $Page->show(); //如果大于0 if ($count) { $lists = M('users')->alias('a')->field('a.user_id,a.head_pic,a.nickname,a.distribut_money,a.underling_number') ->where($where)->order("a.distribut_money desc,a.user_id desc")->limit($Page->firstRow.','.$Page->listRows)->select(); //获排行列表 if ($p==1) { $getdistribut_money = $this->user['distribut_money']; if ($getdistribut_money) { $cur_num = "SELECT b.* FROM (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r,(SELECT user_id FROM wxd_users a where a.store_id=" . getMobileStoId() . " and a.is_distribut=1 order by a.distribut_money desc,a.user_id desc) AS t) AS b WHERE b.user_id=" . $this->user['user_id']; $place_res = DB::query($cur_num); if ($place_res) { $place = $place_res[0]['rownum']; } } if ($place>1) { //查询 $sql2 = "SELECT min(distribut_money) as mindistribut_money FROM wxd_users a where a.store_id=" . getMobileStoId() . " and a.is_distribut=1 and a.distribut_money>" . $getdistribut_money . ""; $sql2_res = DB::query($sql2); if ($sql2_res) { $need = $sql2_res[0]['mindistribut_money'] - $getdistribut_money; } } } } }else{ $sort="underling_number"; $count = M('users')->alias('a')->where($where)->count('user_id'); //总用户量 $Page = $pager = new AjaxPage($count,$pagenum); $show = $Page->show(); if ($count) { $lists=M('users')->alias('a')->field('a.user_id,IFNULL(b.c,0)+IFNULL(c.c,0)+1 as underling_number,a.head_pic,a.nickname,a.distribut_money') ->join('(select third_leader,COUNT(1) as c from wxd_users where store_id='.getMobileStoId().' and is_distribut=1 group by third_leader ) b',' a.user_id=b.third_leader','left') ->join('(select first_leader,COUNT(1) as c from wxd_users where store_id='.getMobileStoId().' and is_distribut=1 group by first_leader ) c',' a.user_id=c.first_leader','left') ->where($where) ->order("underling_number desc,a.user_id desc") ->limit($Page->firstRow.','.$Page->listRows)->select(); //获排行列表 if ($p==1) { $sql_userorder = "SELECT a.user_id,IFNULL(b.c,0)+IFNULL(c.c,0)+1 as underling_number FROM wxd_users a LEFT JOIN (select first_leader,COUNT(1) as c from wxd_users where store_id=" . getMobileStoId() . " and is_distribut=1 group by first_leader ) b ON a.user_id=b.first_leader LEFT JOIN (select second_leader,COUNT(1) as c from wxd_users where store_id=" . getMobileStoId() . " and is_distribut=1 group by second_leader ) c ON a.user_id=c.second_leader WHERE a.store_id=" . getMobileStoId() . " AND a.is_distribut = 1 ORDER BY underling_number desc,a.user_id desc"; $cur_num = "SELECT b.* FROM (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r,(" . $sql_userorder . ") AS t) AS b WHERE b.user_id=" . $this->user['user_id']; $place_res = DB::query($cur_num); if ($place_res) { $place = $place_res[0]['rownum']; $getunderling_number = $place_res[0]['underling_number']; $linenum = $getunderling_number; } if ($place>1) { //查询 $sql2 = "SELECT a.user_id,min(IFNULL(b.c,0)+IFNULL(c.c,0)+1) as minunderling_number FROM wxd_users a LEFT JOIN (select first_leader,COUNT(1) as c from wxd_users where store_id=" . getMobileStoId() . " and is_distribut=1 group by first_leader ) b ON a.user_id=b.first_leader LEFT JOIN (select second_leader,COUNT(1) as c from wxd_users where store_id=" . getMobileStoId() . " and is_distribut=1 group by second_leader ) c ON a.user_id=c.second_leader WHERE a.store_id=" . getMobileStoId() . " AND a.is_distribut = 1 and (IFNULL(b.c,0)+IFNULL(c.c,0)+1)>" . $getunderling_number . ""; $sql2_res = DB::query($sql2); if ($sql2_res) { $need = $sql2_res[0]['minunderling_number'] - $getunderling_number; } } } } } $this->assign('need', $need);//还需要 if($count>$p*$pagenum){ $this->assign('mshow', 1); }else{ $this->assign('mshow', 0); } $this->assign('lists', $lists); $this->assign('place', $place); $this->assign('linenum', $linenum); if(I('is_ajax')){ return $this->fetch('ajax_rankings',getMobileStoId()); } return $this->fetch('',getMobileStoId()); } //新手必看 public function rule(){ $stoid=getMobileStoId(); $content=tpCache('distribut.distri_rule',$stoid); $this->assign('content', $content); return $this->fetch('',getMobileStoId()); } //我的团队 public function team(){ $user =$this->user; if($user['is_distribut'] != 1) { $this->error('您还不是分销商'); } $level = I('get.level',1); $where=" is_distribut=1 and store_id=".getMobileStoId(); $lev1=tpCache('distribut.first_name',getMobileStoId()); $lev2=tpCache('distribut.second_name',getMobileStoId()); $lev3=tpCache('distribut.third_name',getMobileStoId()); $this->assign('lev1', $lev1); $this->assign('lev2', $lev2); $this->assign('lev3', $lev3); switch ($level) { case "1": $where .= " and user_id=" . $this->user_id; break; case "2": $where .= " and first_leader=" . $this->user_id; break; case "3": $where .= " and second_leader=" . $this->user_id; break; } $count = M('users')->where($where)->count(); $page = new \think\Page($count, 10); $lists = M('users') ->field('nickname,user_id,distribut_money,reg_time,head_pic') ->where($where) ->limit("{$page->firstRow},{$page->listRows}") ->order('user_id desc') ->select(); foreach ($lists as &$user_v) { if ($user_v['nickname'] === null) { $user_v['nickname'] = '匿名'; } } $this->assign('count',$count); // 总人数 $this->assign('lists', $lists);// 下线 if($count>I('p/d',1)*10){ $this->assign('mshow', 1); }else{ $this->assign('mshow', 0); } if(I('is_ajax')){ return $this->fetch('ajax_team',getMobileStoId()); } return $this->fetch('',getMobileStoId()); } //佣金明细 public function commission(){ if ($this->user['is_distribut'] != 1) { $this->error('您还不是分销商'); } $status = I('status',''); //日志状态 $order = I('sort_asc','desc'); //排序 $sort = I('sort','create_time'); //排序条件 $key= I('key'); //搜索条件 $where ='a.user_id='.$this->user_id; $where.= ' and a.store_id='.getMobileStoId(); if ($status != '') { $where.= ' and a.status='.$status; } if ($key != '') { $where.= " and (a.nickname like '%".$key."%' or b.mobile like '%".$key."%')"; } $count = Db::name('rebate_log')->alias('a')->join('users b','a.buy_user_id=b.user_id')->where($where)->count(); $page = new \think\Page($count,10); $list = Db::name('rebate_log')->alias('a')->join('users b','a.buy_user_id=b.user_id')->where($where)->order($sort, $order) ->limit($page->firstRow, $page->listRows) ->select(); if($count>I('p/d',1)*10){ $this->assign('mshow', 1); }else{ $this->assign('mshow', 0); } $this->assign('count',$count); // 总人数 $this->assign('lists', $list);// 下线 if(I('is_ajax')){ return $this->fetch('ajax_commission',getMobileStoId()); } return $this->fetch('',getMobileStoId()); } //佣金明细 public function commissionsear(){ $status = I('status',''); //日志状态 $order = I('sort_asc','desc'); //排序 $sort = I('sort','create_time'); //排序条件 $key= I('key'); //搜索条件 $where ='a.user_id='.$this->user_id; $where.= ' and a.store_id='.getMobileStoId(); if ($status != '') { $where.= ' and a.status='.$status; } if ($key != '') { $where.= " and (a.nickname like '%".$key."%' or b.mobile like '%".$key."%')"; } $count = Db::name('rebate_log')->alias('a')->join('users b','a.buy_user_id=b.user_id')->where($where)->count(); $page = new \think\Page($count,10); $list = Db::name('rebate_log')->alias('a')->join('users b','a.buy_user_id=b.user_id')->where($where)->order($sort, $order) ->limit($page->firstRow, $page->listRows) ->select(); if($count>I('p/d',1)*10){ $this->assign('mshow', 1); }else{ $this->assign('mshow', 0); } $this->assign('count',$count); // 总人数 $this->assign('lists', $list);// 下线 return $this->fetch('ajax_commission_sear',getMobileStoId()); } }