user_id = $_SESSION['user_id']; $this->action = ACTION_NAME; $this->con = CONTROLLER_NAME; $this->app = APP_NAME ; if($this->app == 'drp' && $this->con == 'user' && $this->action == 'index'){ }elseif($this->app == 'drp'){ $filter = 1; $this->assign('filter', $filter); } $this->checkLogin(); // 分销商信息 $this->drp = get_drp($this->user_id); // 用户信息 $info = get_user_default($this->user_id); $this->assign('drp', $this->drp); $this->assign('info', $info); } /** * 未登录验证 */ private function checkLogin() { // 是否登陆 if(!$this->user_id){ $url = urlencode(__HOST__ . $_SERVER['REQUEST_URI']); if(IS_POST) { $url = urlencode($_SERVER['HTTP_REFERER']); } ecs_header("Location: ".U('user/login/index',array('back_act'=>$url))); exit; } // 分销状态 $drp_audit_status = drp_audit_status($this->user_id); // 不是分销商 if(!$drp_audit_status){ ecs_header("Location: ".(U('drp/index/index'))); exit; } } public function actionIndex(){ $sql = "SELECT user_money FROM " .$GLOBALS['ecs']->table('users'). " WHERE user_id = '$this->user_id'"; $surplus_amount = $GLOBALS['db']->getOne($sql); //可提佣金 $totals = $this->get_drp_money(0); //累计佣金 $today_total = $this->get_drp_money(1); //今日收入 $total_amount = $this->get_drp_money(2); //总销售额 $this->assign('surplus_amount', $surplus_amount); $select_url = U('drp/index/category'); $this->assign('select_url', $select_url); $url = U('drp/shop/index',array('id'=>$this->drp['drp_id'],'u'=>$_SESSION['user_id']));//我的微店 $this->assign('url', $url); $sql="SELECT value FROM {pre}drp_config WHERE code='withdraw'"; $withdraw=$this->db->getOne($sql); $this->assign('withdraw', $this->htmlOut($withdraw)); $this->assign('totals', $totals[0]['totals']?$totals[0]['totals']:0); $this->assign('today_total', $today_total[0]['totals']?$today_total[0]['totals']:0); $this->assign('total_amount', $total_amount[0]['totals']?$total_amount[0]['totals']:0); $this->assign('page_title', '分销中心'); $category = get_child_tree(); $sql = "SELECT cat_id FROM " . $GLOBALS['ecs']->table('drp_shop') . " WHERE user_id = $this->user_id"; $res = $GLOBALS['db']->getOne($sql); $res = explode(',',$res); $sql = "select cat_id from {pre}cat_recommend where recommend_type = 3"; $recommend = $GLOBALS['db']->getAll($sql); $ress = array(); foreach ($recommend as $kk => $vv){ $ress[] = $vv['cat_id']; } foreach ($category as $k => $v){ if(in_array($category[$k]['id'],$ress)){ if(in_array($v['id'],$res)){ $category[$k]['is_drp'] = 1; }else{ $category[$k]['is_drp'] = 0; } }else{ unset($category[$k]); } } $this->assign('category', array_slice($category,0,5)); $this->assign('uid',$this->user_id); $this->display('distribution_user'); } private function get_drp_money($type){ if($type === 0){ $where = ""; }else{ if($type === 1){ $nowtime = gmtime(); $t = getdate($nowtime); $today_zero_time = mktime(0, 0, 0, $t['mon'], $t['mday'], $t['year']); $where = " AND time >= $today_zero_time"; }else{ $sql = "SELECT sum(goods_amount) as totals FROM " . $GLOBALS['ecs']->table('order_info') . " o" . " LEFT JOIN " . $GLOBALS['ecs']->table('affiliate_log') . " a ON o.order_id = a.order_id" . " WHERE a.user_id = " . $_SESSION['user_id']; return $GLOBALS['db']->query($sql); } } $sql = "SELECT sum(money) as totals FROM " . $GLOBALS['ecs']->table('affiliate_log') . " WHERE user_id = " . $_SESSION['user_id'] . "$where"; return $GLOBALS['db']->query($sql); } // 佣金明细 public function actionDrplog(){ $sql = "SELECT order_id FROM " . $GLOBALS['ecs']->table('drp_log') . " ORDER BY log_id DESC" ; $last_oid = $GLOBALS['db']->getOne($sql); $last_oid = $last_oid?$last_oid:0; $sql = "SELECT o.order_id FROM {pre}order_info " ." o". " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id". " WHERE o.user_id > 0 AND (u.parent_id > 0 AND o.is_separate = 0 OR o.is_separate > 0) ". " and o.order_id > $last_oid" ; $up_oid = $GLOBALS['db']->getAll($sql); $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); empty($affiliate) && $affiliate = array(); if($up_oid){ $separate_by = $affiliate['config']['separate_by']; $affiliate['config']['level_point_all'] = (float)$affiliate['config']['level_point_all']; $affiliate['config']['level_money_all'] = (float)$affiliate['config']['level_money_all']; if ($affiliate['config']['level_point_all']) { $affiliate['config']['level_point_all'] /= 100; } if ($affiliate['config']['level_money_all']) { $affiliate['config']['level_money_all'] /= 100; } foreach ($up_oid as $kk => $vv){ $row = $GLOBALS['db']->getRow("SELECT o.order_sn, o.parent_id, o.is_separate, (o.goods_amount - o.discount) AS goods_amount, o.user_id FROM " . $GLOBALS['ecs']->table('order_info') . " o". " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " u ON o.user_id = u.user_id". " WHERE order_id = ".$vv['order_id']); $is = $row['is_separate']; $money = round($affiliate['config']['level_money_all'] * $row['goods_amount'],2); $integral = integral_to_give(array('order_id' => $vv['order_id'], 'extension_code' => '')); $point = round($affiliate['config']['level_point_all'] * intval($integral['rank_points']), 0); $num = count($affiliate['item']); for ($i=0; $i < $num; $i++) { $affiliate['item'][$i]['level_point'] = (float)$affiliate['item'][$i]['level_point']; $affiliate['item'][$i]['level_money'] = (float)$affiliate['item'][$i]['level_money']; if ($affiliate['item'][$i]['level_point']) { $perp = ($affiliate['item'][$i]['level_point']/ 100); } if ($affiliate['item'][$i]['level_money']) { $per = ($affiliate['item'][$i]['level_money'] /100); } $setmoney = round($money * $per, 2); $setpoint = round($point * $perp, 0); $row = $GLOBALS['db']->getRow("SELECT o.parent_id as user_id,u.user_name FROM " . $GLOBALS['ecs']->table('users') . " o" . " LEFT JOIN" . $GLOBALS['ecs']->table('users') . " u ON o.parent_id = u.user_id". " WHERE o.user_id = '$row[user_id]'" ); $this->writeDrpLog($vv['order_id'], $row['user_id'], $row['user_name'], $setmoney, $setpoint, $i,$is,$separate_by); } } } $sql = "SELECT o.order_id FROM {pre}order_info as o " . " LEFT JOIN {pre}drp_log as d ON d.order_id = o.order_id AND o.is_separate != d.is_separate"; //order_info order_id不在drp——log的id 自营的 $up_oid = $GLOBALS['db']->getAll($sql); $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); empty($affiliate) && $affiliate = array(); if($up_oid){ foreach ($up_oid as $kk => $vv){ $row = $GLOBALS['db']->getRow("SELECT o.order_sn, o.parent_id, o.is_separate, (o.goods_amount - o.discount) AS goods_amount, o.user_id FROM " . $GLOBALS['ecs']->table('order_info') . " o". " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " u ON o.user_id = u.user_id". " WHERE order_id = ".$vv['order_id']); $is = $row['is_separate']; $num = count($affiliate['item']); for ($i=0; $i < $num; $i++) { $row = $GLOBALS['db']->getRow("SELECT o.parent_id as user_id,u.user_name FROM " . $GLOBALS['ecs']->table('users') . " o" . " LEFT JOIN" . $GLOBALS['ecs']->table('users') . " u ON o.parent_id = u.user_id". " WHERE o.user_id = '$row[user_id]'" ); $this->upDrpLog($vv['order_id'],$is); } } } $page = I('post.page', 1, 'intval'); $size = '10'; $status = I('status',2,'intval'); if($status == 2){ //全部 $where = ""; }else { //已分成 OR 等待处理 $where = " AND a.is_separate = " . $status . ""; } if(IS_AJAX){ $sql = "SELECT o.order_sn, a.time,a.user_id,a.time,a.money,a.point,a.separate_type,IFNULL(w.nickname,u.user_name),a.is_separate FROM " . $GLOBALS['ecs']->table('drp_log') . " a". " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " o ON o.order_id = a.order_id" . " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id". " LEFT JOIN".$GLOBALS['ecs']->table('wechat_user')." w ON w.ect_uid = u.user_id". " WHERE a.user_id = $_SESSION[user_id] AND o.pay_status = 2". " $where ". " ORDER BY o.order_id DESC"; $resall = $GLOBALS['db']->query($sql); $countall =count($resall); $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); foreach ($res as $k => $v){ $res[$k]['time'] = date("Y-m-d ",($v['time']+date('Z'))); $res[$k]['is_separate'] = ($v['is_separate'] == '1')?'已分成':'等待处理'; } die(json_encode(array('list' => $res, 'totalPage' => ceil($countall/$size)))); } $this->assign('page_title', '佣金明细'); $this->display('distribution_money'); } //分类 public function actionCategory(){ $page = I('post.page', 1, 'intval'); $size = '5'; $status = I('status')?I('status'):0;; $category = get_child_tree(); $sql = "SELECT cat_id FROM " . $GLOBALS['ecs']->table('drp_shop') . " WHERE user_id = $this->user_id"; $res = $GLOBALS['db']->getOne($sql); $res = explode(',',$res); foreach ($category as $k => $v){ if(in_array($v['id'],$res)){ $category[$k]['is_drp'] = 1; }else{ $category[$k]['is_drp'] = 0; } } if(IS_AJAX){ if($status == 0){ foreach ($category as $ke => $val){ if($val['is_drp'] == 1){ unset($category[$ke]); } } } if($status == 1){ foreach ($category as $ke => $val){ if($val['is_drp'] == 0){ unset($category[$ke]); } } } die(json_encode(array('category'=>$category,'totalPage'=>1))); } $this->assign('page_title', '全部分类'); $this->display('distribution_shop'); } //AJAX修改分类 public function actionAjaxeditcat(){ $cat_id = I('cat_id'); if(IS_POST){ $sql = "SELECT cat_id FROM " . $GLOBALS['ecs']->table('drp_shop') . " WHERE user_id = $this->user_id"; $res = $GLOBALS['db']->getOne($sql); $array = explode(',',$res); if(in_array($cat_id,$array)){ foreach ($array as $k => $v){ if($v == $cat_id){ unset($array[$k]); } } $res = implode(",",$array); }else{ $res = $res . $cat_id .","; } $data['cat_id'] = $res; $where['user_id'] = $_SESSION['user_id']; $this->model->table('drp_shop')->data($data)->where($where)->update(); echo json_encode(array('status'=>1)); } } /** * 我的名片 */ public function actionUserCard() { $uid = I('request.u'); $uid = empty($uid) ? $_SESSION['user_id'] : $uid; $info = get_drp($uid); $this->assign('info', $info); $url = 'http://'.$_SERVER['HTTP_HOST'].U('shop/index',array('id'=>$info['drp_id'],'u'=>$this->user_id)); //二维码内容 $str = ''; // 纠错级别:L、M、Q、H $errorCorrectionLevel = 'L'; // 点的大小:1到10 $matrixPointSize = 4; $file = ROOT_PATH.'data/attached/qrcode/'; $name = 'userid_'.$this->user_id.$errorCorrectionLevel . $matrixPointSize . '.png'; if(!file_exists($name)) { $filename = $file . $name; $code = \libraries\QRcode::png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 2); } $this->assign('ewm', __ROOT__.'data/attached/qrcode/'.$name); $this->assign('page_title',$info['username'].'的名片'); $this->display('distribution_card'); // $this->actionGetConfig(); /* if(is_object($this->weObj) && !empty($uid)) { //获取店铺信息 $info = get_drp($uid); //临时二维码 $path = ROOT_PATH.'data/attached/qrcode/card_'.$uid.'.png'; if(!file_exists($path) || (strtotime("-28 day")-@filectime($path))>0) { //删除过期图片 @unlink ($path); $ticket = $this->weObj->getQRCode((int)$uid, 0, 2592000); $img = $this->weObj->getQRUrl($ticket['ticket']); //保存图片到本地 $contents = \libraries\Http::doGet($img); file_put_contents($path, $contents); } $this->assign('ewm', __ROOT__.'data/attached/qrcode/card_'.$uid.'.png'); //SDK $access_token = $this->weObj->checkAuth($this->wechat['appid'],$this->wechat['appsecret']); $ticket = $this->weObj->getJsTicket($this->wechat['appid']); $time = gmtime()+8*3600; $url = "jsapi_ticket=".$ticket."&noncestr=ectouch×tamp=".$time."&url="."http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $arr = array( 'share_url' => U('user/card',array('uid'=>$uid)), 'imgUrl' => $info['headimgurl'], 'title' => $info['shop_name'], 'desc' => '新道新承诺,双盈大家乐!', 'appid' => $this->wechat['appid'], 'noncestr' => 'ectouch', //任意改动 'timestamp' => $time, 'signature' => sha1($url) ); $this->assign('info', $info); $this->assign('wx',$arr); $this->assign('page_title',$info['username'].'的名片'); $this->display('distribution_card'); }else{ $this->redirect(U('user/index')); }*/ } /* * 团队 */ public function actionTeam() { if(IS_AJAX) { $uid = I('user_id') ? I('user_id'): $this->user_id; $page = I('page', 1) - 1; $limit = " LIMIT $page,6"; $sql = "SELECT s.status, s.audit, u.user_id, IFNULL(u.user_name, w.nickname) as name, w.headimgurl, FROM_UNIXTIME(u.reg_time, '%Y-%m-%d') as time, IFNULL((select sum(log.money) as money from {pre}affiliate_log as log left join {pre}order_info as o on log.order_id=o.order_id where o.user_id=u.user_id and log.user_id=".$uid."),0) as money FROM {pre}users as u LEFT JOIN {pre}wechat_user as w ON u.user_id=w.ect_uid LEFT JOIN {pre}drp_shop as s ON u.user_id=s.user_id WHERE s.status=1 and s.audit=1 and u.parent_id='$uid' ORDER BY u.reg_time desc". $limit; $next = $this->model->query($sql); //所有记录 $list = $this->model->query($sql); die(json_encode(array('info'=>$next, 'uid'=>$uid, 'totalPage'=>ceil(count($list)/6)))); } $this->assign('page_title','我的团队'); $this->assign('next_id',I('user_id','')); $this->display('distribution_team'); } /* * 从下线获取的佣金-详情 */ public function actionTeamDetail() { $uid = I('uid',''); if(empty($uid)) { $this->redirect(U('drp/user/index')); } $sql = "SELECT u.user_id, IFNULL(u.user_name, w.nickname) as name, w.headimgurl, FROM_UNIXTIME(u.reg_time, '%Y-%m-%d') as time, IFNULL((select sum(sl.money) from {pre}affiliate_log as sl left join {pre}order_info as so on sl.order_id=so.order_id where so.user_id='$uid' and sl.user_id='$this->user_id'),0) as sum_money, IFNULL((select sum(nl.money) from {pre}affiliate_log as nl left join {pre}order_info as no on nl.order_id=no.order_id where nl.time>'".mktime(0,0,0)."' and no.user_id='$uid' and nl.user_id='$this->user_id'),0) as now_money, (select count(h.user_id) from {pre}users as h LEFT JOIN {pre}drp_shop as s on s.user_id=h.user_id where s.status=1 and s.audit=1 and parent_id='$uid' ) as next_num FROM {pre}users as u LEFT JOIN {pre}wechat_user as w ON u.user_id=w.ect_uid WHERE u.user_id='$uid'"; $this->assign('info',$this->db->getRow($sql)); $shopid = model()->table('drp_shop')->field('id')->where(array('user_id'=>$uid, 'status'=>1,'audit'=>1))->find(); $this->assign('shopid',$shopid['id']); $this->assign('page_title','团队详情'); $this->display('distribution_team_detail'); } //新手必看 public function actionNew(){ $sql = "SELECT a.title,a.content FROM " . $GLOBALS['ecs']->table('article') . " a". " LEFT JOIN " . $GLOBALS['ecs']->table('article_cat') . " o ON o.cat_id = a.cat_id" . " WHERE a.is_open = 1 and o.cat_id = 1000 order by a.add_time desc "; $drp_article = $this->db->query($sql); foreach( $drp_article as $k=>$v){ $drp_article[$k]['order'] = ($k+1); } $this->assign('drp_article', $drp_article); $this->assign('page_title', '新手必看'); $this->display('distribution_new'); } /* * 排行榜 */ public function actionRankList() { $uid = I('uid') ? I('uid'): $this->user_id; $all =$GLOBALS['cache']->get('ranklist'.$uid); if(!$all) { $sql = "SELECT d.user_id, w.nickname, w.headimgurl, u.user_name, IFNULL((select sum(money) from {pre}affiliate_log where user_id=d.user_id),0) as money FROM {pre}drp_shop as d LEFT JOIN {pre}users as u ON d.user_id=u.user_id LEFT JOIN {pre}wechat_user as w ON d.user_id=w.ect_uid LEFT JOIN {pre}affiliate_log as log ON log.user_id=d.user_id where d.audit=1 and d.status=1 GROUP BY d.user_id ORDER BY money desc "; $all = $this->model->query($sql); if ($all) { foreach ($all as $key => $val) { if ($key === 0) { $all[$key]['img'] = __TPL__ . 'img/fx-one.png'; } else if ($key === 1) { $all[$key]['img'] = __TPL__ . 'img/fx-two.png'; } else if ($key === 2) { $all[$key]['img'] = __TPL__ . 'img/fx-stree.png'; } else { $all[$key]['span'] = $key + 1; } } $GLOBALS['cache']->set('ranklist' . $uid, $all); } } if(IS_AJAX) { $page = I('page',1,'intval')-1; //总条数 $list = array_slice($all,$page*6,6); die(json_encode(array('list' => $list, 'totalPage' => ceil(count($all) / 6)))); } //用户排名 $rank = copy_array_column($all,'user_id'); $rank = array_search($uid,$rank); $rank = $rank === false ? '--' : $rank+1; $this->assign('rank',$rank); $this->assign('page_title','分销排行'); $this->display('distribution_ranklist'); } /** * 获取公众号配置 * * @param string $orgid * @return array */ private function actionGetConfig() { $orgid = $this->model->table('wechat')->field('orgid')->one(); $wxinfo = model()->table('wechat') ->field('id, token, appid, appsecret, encodingaeskey') ->where(array('orgid'=>$orgid, 'status'=>1)) ->find(); $this->wechat = $wxinfo; if (!empty($wxinfo)) { $this->weObj = new \vendor\Wechat($wxinfo); } } /** * 店铺设置 */ public function actionShopConfig() { $sql="SELECT * FROM {pre}drp_shop WHERE user_id=$this->user_id"; $drp_info=$this->db->getRow($sql); $info=array(); $info['shop_name']= $drp_info['shop_name']; $info['real_name']= $drp_info['real_name']; $info['qq']= $drp_info['qq']; if(empty($drp_info['shop_img'])){ $info['shop_img']=__TPL__.'img/user-shop.png'; }else{ $info['shop_img'] ='./data/attached/drp_logo/' . $drp_info['shop_img']; } $info['mobile']= $drp_info['mobile']; $this->assign('info',$info); if (IS_POST) { $data = I(''); if($data['mobile']){ $preg=preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $data['mobile']) ? true : false; if($preg==FALSE){ show_message('手机号码格式不正确'); } } if (empty($data['shop_name'])) { show_message('店铺名不能为空'); } if (empty($data['real_name'])) { show_message('真实姓名不能为空'); } if (empty($data['mobile'])) { show_message('手机号码不能为空'); } if (!empty($_FILES['shop_img']['name'])) { $result =$this->ectouchUpload('shop_img','drp_logo'); if ($result['error'] > 0) { show_message($result['message']); } $data['shop_img'] = $result['message']['shop_img']['savename']; } $where['user_id'] = $_SESSION['user_id']; $this->model->table('drp_shop')->data($data)->where($where)->update(); show_message('修改成功', '分销中心', U('drp/user/index'),'success'); } $this->assign('page_title','店铺设置'); $this->display('shop_config'); } /* * 分销订单列表 * */ public function actionOrder() { $sql = "SELECT order_id FROM " . $GLOBALS['ecs']->table('drp_log') . " ORDER BY log_id DESC" ; $last_oid = $GLOBALS['db']->getOne($sql); $last_oid = $last_oid?$last_oid:0; $sql = "SELECT o.order_id FROM {pre}order_info " ." o". " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id". " WHERE o.user_id > 0 AND (u.parent_id > 0 AND o.is_separate = 0 OR o.is_separate > 0) ". " and o.order_id > $last_oid" ; $up_oid = $GLOBALS['db']->getAll($sql); $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); empty($affiliate) && $affiliate = array(); if($up_oid){ $separate_by = $affiliate['config']['separate_by']; $affiliate['config']['level_point_all'] = (float)$affiliate['config']['level_point_all']; $affiliate['config']['level_money_all'] = (float)$affiliate['config']['level_money_all']; if ($affiliate['config']['level_point_all']) { $affiliate['config']['level_point_all'] /= 100; } if ($affiliate['config']['level_money_all']) { $affiliate['config']['level_money_all'] /= 100; } foreach ($up_oid as $kk => $vv){ $oid = (int)$vv['order_id']; $row = $GLOBALS['db']->getRow("SELECT o.order_sn, o.parent_id, o.is_separate, (o.goods_amount - o.discount) AS goods_amount, o.user_id FROM " . $GLOBALS['ecs']->table('order_info') . " o". " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " u ON o.user_id = u.user_id". " WHERE order_id = '$oid'"); $is = $row['is_separate']; $money = round($affiliate['config']['level_money_all'] * $row['goods_amount'],2); $integral = integral_to_give(array('order_id' => $oid, 'extension_code' => '')); $point = round($affiliate['config']['level_point_all'] * intval($integral['rank_points']), 0); $num = count($affiliate['item']); for ($i=0; $i < $num; $i++) { $affiliate['item'][$i]['level_point'] = (float)$affiliate['item'][$i]['level_point']; $affiliate['item'][$i]['level_money'] = (float)$affiliate['item'][$i]['level_money']; if ($affiliate['item'][$i]['level_point']) { $perp = ($affiliate['item'][$i]['level_point']/ 100); } if ($affiliate['item'][$i]['level_money']) { $per = ($affiliate['item'][$i]['level_money']/ 100); } $setmoney = round($money * $per, 2); $setpoint = round($point * $perp, 0); $row = $GLOBALS['db']->getRow("SELECT o.parent_id as user_id,u.user_name FROM " . $GLOBALS['ecs']->table('users') . " o" . " LEFT JOIN" . $GLOBALS['ecs']->table('users') . " u ON o.parent_id = u.user_id". " WHERE o.user_id = '$row[user_id]'" ); $this->writeDrpLog($oid, $row['user_id'], $row['user_name'], $setmoney, $setpoint, $i,$is,$separate_by); } } } $sql = "SELECT o.order_id FROM {pre}order_info as o " . " LEFT JOIN {pre}drp_log as d ON d.order_id = o.order_id AND o.is_separate != d.is_separate"; //order_info order_id不在drp——log的id 自营的 $up_oid = $GLOBALS['db']->getAll($sql); $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); empty($affiliate) && $affiliate = array(); if($up_oid){ foreach ($up_oid as $kk => $vv){ $row = $GLOBALS['db']->getRow("SELECT o.order_sn, o.parent_id, o.is_separate, (o.goods_amount - o.discount) AS goods_amount, o.user_id FROM " . $GLOBALS['ecs']->table('order_info') . " o". " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " u ON o.user_id = u.user_id". " WHERE order_id = ".$vv['order_id']); $is = $row['is_separate']; $num = count($affiliate['item']); for ($i=0; $i < $num; $i++) { $row = $GLOBALS['db']->getRow("SELECT o.parent_id as user_id,u.user_name FROM " . $GLOBALS['ecs']->table('users') . " o" . " LEFT JOIN" . $GLOBALS['ecs']->table('users') . " u ON o.parent_id = u.user_id". " WHERE o.user_id = '$row[user_id]'" ); $this->upDrpLog($vv['order_id'],$is); } } } $page = I('post.page', 1, 'intval'); $size = '5'; $status = I('status',2,'intval'); if($status == 2){ //全部 $where = ""; }else { //已分成 OR 等待处理 $where = " AND o.is_separate = " . $status . ""; } if(IS_AJAX){ $sql = "SELECT o.*, a.money, IFNULL(w.nickname,u.user_name) as user_name, a.point, a.drp_level FROM " . $GLOBALS['ecs']->table('drp_log') . " a". " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " o ON o.order_id = a.order_id" . " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id". " LEFT JOIN".$GLOBALS['ecs']->table('wechat_user')." w ON w.ect_uid = u.user_id". " WHERE a.user_id = $_SESSION[user_id] AND o.pay_status = 2". " $where ". " ORDER BY order_id DESC"; $resall = $GLOBALS['db']->query($sql); $countall =count($resall); $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); if ($res) { foreach ($res as $key => $value) { $level_per = ((float)$affiliate['item'][$value['drp_level']]['level_money'])*($affiliate['config']['level_money_all']); $level_per = $level_per/100; $goods_list = $this->getOrderGoods($value['order_id']); $total_goods_price = 0; foreach ($goods_list as $key => $val) { $goods_list[$key]['price'] = $val['goods_price']; $goods_list[$key]['subtotal'] = price_format($value['total_fee'], false); $goods_list[$key]['goods_number'] = $val['goods_number']; $goods_list[$key]['goods_thumb'] = get_image_path($val['goods_thumb']); $goods_list[$key]['url'] = U('goods/index/index',array('id'=>$val['goods_id'])); $goods_list[$key]['this_good_drpmoney'] = (round($val['goods_price']*$level_per/100,2)); $total_goods_price += $val['goods_price']; $goods_list[$key]['this_good_per'] = $level_per."%"; } foreach ($goods_list as $key => $val) { $goods_list[$key]['goods_price'] = price_format($val['goods_price'], false); } $orders[] = array( 'user_name' => $value['user_name'], 'order_sn' => $value['order_sn'], 'order_time' => date("Y-m-d H:i:s",$value['add_time']+date('Z')), 'url' => U('drp/user/order_detail', array('order_id' => $value['order_id'])), 'is_separate' => $value['is_separate'], 'goods' => $goods_list, 'goods_count' => $goods_list?count($goods_list):0, 'total_orders_drpmoney' => price_format((round($value['goods_amount']*$level_per/100,2)), false), 'this_good_per' => $level_per."%" ); } } die(json_encode(array('orders'=>$orders,'totalPage'=>ceil($countall/$size)))); } $this->assign('page_title', "分销订单"); $this->display('drp_orders'); } private function writeDrpLog($oid, $uid, $username, $money, $point,$i,$is, $separate_by) { $time = gmtime(); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('drp_log') . "( order_id, user_id, user_name, time, money, point, drp_level,is_separate, separate_type)". " VALUES ( '$oid', '$uid', '$username', '$time', '$money', '$point','$i','$is', $separate_by)"; if ($oid) { $GLOBALS['db']->query($sql); } } private function upDrpLog($oid, $is) { $time = gmtime(); $sql = "UPDATE {pre}drp_log SET `is_separate` = $is WHERE order_id = $oid "; if ($oid) { $GLOBALS['db']->query($sql); } } public function actionOrderdetail(){ $oid = (int)$_REQUEST['order_id']; $sql = "SELECT o.*, a.money, IFNULL(w.nickname,u.user_name) as user_name, a.point, a.drp_level FROM " . $GLOBALS['ecs']->table('drp_log') . " a". " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " o ON o.order_id = a.order_id" . " LEFT JOIN".$GLOBALS['ecs']->table('users')." u ON o.user_id = u.user_id". " LEFT JOIN".$GLOBALS['ecs']->table('wechat_user')." w ON w.ect_uid = u.user_id". " WHERE a.user_id = $_SESSION[user_id] AND o.order_id = $oid AND o.pay_status = 2"; $res = $GLOBALS['db']->getRow($sql); if(!$res){ ecs_header("Location: ".(U('drp/user/index'))); } $goods_list = $this->getOrderGoods($res['order_id']); $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); empty($affiliate) && $affiliate = array(); $level_per = ((float)$affiliate['item'][$res['drp_level']]['level_money'])*($affiliate['config']['level_money_all'] /= 100); foreach ($goods_list as $key => $val) { $goods_list[$key]['price'] = $val['goods_price']; $goods_list[$key]['goods_number'] = $val['goods_number']; $goods_list[$key]['goods_thumb'] = get_image_path($val['goods_thumb']); $goods_list[$key]['goods_url'] = U('goods/index/index', array('id' => $val['goods_id'])); } foreach ($goods_list as $key => $val) { $goods_list[$key]['this_good_drpmoney'] = (round($val['goods_price']*$level_per/100,2)); $goods_list[$key]['this_good_per'] = $level_per."%"; $goods_list[$key]['goods_price'] = price_format($val['goods_price'], false); } $orders = array( 'user_name' => $res['user_name'], 'order_sn' => $res['order_sn'], 'order_time' => date("Y-m-d H:i:s",($res['add_time']+date('Z'))), 'is_separate' => $res['is_separate'], 'goods' => $goods_list, 'goods_count' => $goods_list?count($goods_list):0, 'total_orders_drpmoney' => price_format((($res['goods_amount']-$res['discount'])*$level_per/100), false), 'this_good_per' => $level_per."%" ); $this->assign('order', $orders); $this->assign('page_title', '分销订单详情'); $this->display('drp_order_detail'); } private function getOrderGoods($order_id = 0){ if($order_id > 0){ $sql = "select og.rec_id,og.goods_id,og.goods_name,og.goods_attr,og.goods_number,og.goods_price, g.goods_thumb from {pre}order_goods as og join {pre}goods as g on og.goods_id = g.goods_id where og.order_id=$order_id"; $goodsArr = model()->query($sql); return $goodsArr; } } /** * html代码输出 */ private function htmlOut($str) { if (function_exists('htmlspecialchars_decode')) { $str = htmlspecialchars_decode($str); } else { $str = html_entity_decode($str); } $str = stripslashes($str); return $str; } }