0) { //update ims_ $id = $data['id']; unset($data['id']); M('lionfish_community_head')->where( array('id' => $id ) )->save( $data ); }else{ //insert $id = M('lionfish_community_head')->add($data); } return $id; } //begin /** 根据会员id获取团长id **/ public function get_head_id_by_member_id($member_id) { $head_info = M('lionfish_community_head')->field('id')->where( array('member_id' => $member_id ) )->find(); return $head_info['id']; } /** 根据团长id获取会员id **/ public function get_agent_member_id($agent_head_id = 0) { $head_info = M('lionfish_community_head')->field('member_id')->where( array('id' => $agent_head_id) )->find(); return $head_info['member_id']; } //end public function insert_head_goods($goods_id, $head_id) { global $_W; global $_GPC; $head_goods_info = M('lionfish_community_head_goods')->where( array('goods_id' => $goods_id,'head_id' => $head_id) )->find(); if( empty($head_goods_info) ) { $data = array(); $data['head_id'] = $head_id; $data['goods_id'] = $goods_id; $data['addtime'] = time(); M('lionfish_community_head_goods')->add($data); } } //begin /** 获取商品对应团长等级对应的分佣比例情况 **/ public function get_goods_head_level_bili( $goods_id ) { $goods_common_info = M('lionfish_comshop_good_common') ->field('is_modify_head_commission,community_head_commission_modify')->where( array('goods_id' => $goods_id ) )->find(); $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select(); $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname'); $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money'); $list = array( array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, ) ); $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve'); $head_commission_info_gd = D('Home/Front')->get_goods_common_field( $goods_id , 'community_head_commission'); if( !empty($head_commission_info_gd) && $head_commission_info_gd['community_head_commission'] > 0 ) { $list = array( array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $head_commission_info_gd['community_head_commission'], ) ); } $is_head_takegoods = D('Home/Front')->get_config_by_name('is_head_takegoods'); $is_head_takegoods = isset($is_head_takegoods) && $is_head_takegoods == 1 ? 1 : 0; if( $is_head_takegoods == 1 ) { $community_head_level = array_merge($list, $community_head_level); }else{ $community_head_level = $list ; } $result = array(); if( $goods_common_info['is_modify_head_commission'] == 1 && $is_head_takegoods == 1) { $result = unserialize($goods_common_info['community_head_commission_modify']); foreach ($community_head_level as $head_level) { if (!isset($result['head_level' . $head_level['id']])) { $result['head_level' . $head_level['id']] = $head_level['commission']; } } }else{ if( !empty($community_head_level) ) { foreach( $community_head_level as $head_level) { $result['head_level'.$head_level['id']] = $head_level['commission']; } } } return $result; } //end public function show_communityhead_page() { $condition = ' '; $keyword = I('get.keyword','','trim'); if (!empty($keyword)) { $condition .= ' and ( m.username like "'.'%' . $keyword . '%'.'" or ch.community_name like "'.'%' . $keyword . '%'.'" or ch.head_name like "'.'%' . $keyword . '%'.'" or ch.head_mobile like "'.'%' . $keyword . '%'.'" or ch.address like "'.'%' . $keyword . '%'.'") '; } $start = I('get.start',''); $end = I('get.end',''); if (!empty($start) && !empty($end)) { $starttime = strtotime($start); $endtime = strtotime($end); $condition .= ' AND ch.apptime >= '.$starttime.' AND ch.apptime <= '.$endtime; } $comsiss_state = I('get.comsiss_state',''); if ($comsiss_state != '') { $condition .= ' and ch.state=' . intval($_GPC['comsiss_state']); } $sql_count = 'SELECT count(1) as count FROM ' .C('DB_PREFIX'). 'lionfish_community_head as ch ,'.C('DB_PREFIX').'member as m WHERE ch.member_id = m.member_id ' . $condition; $count_arr = M()->query($sql_count); $count = $count_arr[0]['count']; $Page = new \Think\Page($count,C('BACK_PAGE_NUM')); $show = $Page->show();// 分页显示输出 $sql = 'SELECT ch.*,m.we_openid,m.username,m.avatar FROM ' . C('DB_PREFIX') . "lionfish_community_head as ch, ".C('DB_PREFIX')."member as m \r\n WHERE ch.member_id = m.member_id " . $condition . ' order by ch.id desc '; $export = I('get.export',''); if (empty($export)) { $sql .= ' limit '.$Page->firstRow.','.$Page->listRows; } $list = M()->query($sql); $all_sell_count = M('lionfish_comshop_goods')->where( "is_all_sale=1" )->count(); foreach( $list as $key => $val ) { //commission_info $commission_info = M('lionfish_community_head_commiss')->where( array('head_id' => $val['id']) )->find(); $commission_info['commission_total'] = $commission_info['money']+ $commission_info['dongmoney'] + $commission_info['getmoney']; $val['commission_info'] = $commission_info; //普通等级 $member_info = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find(); //get_area_info($id=0) $val['province_name'] = D('seller/area')->get_area_info($val['province_id']); $val['city_name'] = D('seller/area')->get_area_info($val['city_id']); $val['area_name'] = D('seller/area')->get_area_info($val['area_id']); $val['country_name'] = D('seller/area')->get_area_info($val['country_id']); $ct_arr = M()->query("select count(hg.id) as count from ".C('DB_PREFIX')."lionfish_community_head_goods as hg , ".C('DB_PREFIX')."lionfish_comshop_good_common as gc where hg.goods_id = gc.goods_id and hg.head_id =".$val['id']); $val['goods_count'] = $ct_arr[0]['count']; $val['goods_count'] += $val['all_sell_count']; //$val['member_info'] = $member_info; $list[$key] = $val; } if ($_GPC['export'] == '1') { foreach ($list as &$row) { //$row['username'] = $val['member_info']['username']; //$row['we_openid'] = $val['member_info']['we_openid']; $row['commission_total'] = 0; $row['getmoney'] = 0; $row['fulladdress'] = $row['province_name'].$row['city_name'].$row['area_name'].$row['country_name'].$row['address']; $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']); $row['apptime'] = date('Y-m-d H:i:s', $row['apptime']); $row['state'] = $row['state'] == 1 ? '已审核':'未审核'; } unset($row); $columns = array( array('title' => 'ID', 'field' => 'member_id', 'width' => 12), array('title' => '微信用户名', 'field' => 'username', 'width' => 12), array('title' => '团长名称', 'field' => 'head_name', 'width' => 12), array('title' => '联系方式', 'field' => 'head_name', 'width' => 12), array('title' => '在售商品数量', 'field' => 'goods_count', 'width' => 24), array('title' => 'openid', 'field' => 'we_openid', 'width' => 24), array('title' => '累计佣金', 'field' => 'commission_total', 'width' => 12), array('title' => '打款佣金', 'field' => 'getmoney', 'width' => 12), array('title' => '省', 'field' => 'province_name', 'width' => 12), array('title' => '市', 'field' => 'city_name', 'width' => 12), array('title' => '区', 'field' => 'area_name', 'width' => 12), array('title' => '街道/镇', 'field' => 'country_name', 'width' => 12), array('title' => '提货地址', 'field' => 'address', 'width' => 24), array('title' => '完整提货地址', 'field' => 'fulladdress', 'width' => 24), array('title' => '注册时间', 'field' => 'addtime', 'width' => 12), array('title' => '成为团长时间', 'field' => 'apptime', 'width' => 12), array('title' => '审核状态', 'field' => 'state', 'width' => 12) ); //load_model_class('excel')->export($list, array('title' => '团长数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns)); } return array( 'empty'=>'