You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

202 lines
8.8 KiB

<?php
namespace apps\drp\controllers;
use apps\base\controllers\BackendController;
class AdminController extends BackendController {
/**
* 店铺设置
*/
public function actionConfig(){
if(IS_POST){
$data_list = I('post.data');
if(empty($data_list)){
$this->message('错误的请求', null, 2);
}
foreach($data_list as $k=>$v){
$where = array();
$data = array();
$where['code'] = $k;
$data['value'] = $v;
$this->model->table('drp_config')->data($data)->where($where)->update();
}
$this->redirect(U('config'));
}
$config = $this->model->table('drp_config')->order('sort_order ASC')->select();
$this->assign('list', $config);
$this->display('admin_config');
}
/**
* 分销商管理
*/
public function actionShop(){
$where = "";
if(IS_POST){
$shop_name = I('post.shop_name');
$real_name = I('post.real_name');
$mobile = I('post.mobile');
$user_name = I('post.user_name');
if(!empty($shop_name)){
$where .= " AND s.shop_name like '%".$shop_name."%'";
}
if(!empty($real_name)){
$where .= " AND s.real_name like '%".$real_name."%'";
}
if(!empty($mobile)){
$where .= " AND s.mobile like '%".$mobile."%'";
}
if(!empty($user_name)){
$where .= " AND u.user_name like '%".$user_name."%'";
}
}
$filter['page'] = '{page}';
$offset = $this->pageLimit(U('shop', $filter), 10);
$sql_count = "SELECT count(*) as count FROM {pre}drp_shop s LEFT JOIN {pre}users u ON s.user_id = u.user_id WHERE 1 ".$where." ORDER BY create_time DESC";
$total = $this->model->query($sql_count);
$this->assign('page', $this->pageShow($total[0]['count']));
$sql = "SELECT s.*, u.user_name FROM {pre}drp_shop s LEFT JOIN {pre}users u ON s.user_id = u.user_id WHERE 1 ".$where." ORDER BY create_time DESC LIMIT ".$offset;
$list = $this->model->query($sql);
$this->assign('list', $list);
$this->display('admin_shop');
}
/**
* 改变分销商状态
*/
public function actionSetShop(){
$id = I('get.id', 0, 'intval');
if(empty($id)){
$this->message('请选择店铺', NULL, 2);
}
if(isset($_GET['audit'])){
$data['audit'] = I('get.audit', 1, 'intval');
}
if(isset($_GET['status'])){
$data['status'] = I('get.status', 0, 'intval');
}
if(!empty($data)){
$this->model->table('drp_shop')->data($data)->where(array('id'=>$id))->update();
}
$this->redirect(U('shop'));
}
/**
* 导出分销商
*/
public function actionExportShop(){
if(IS_POST){
$starttime = I('post.starttime', '', 'strtotime');
$endtime = I('post.endtime', '', 'strtotime');
if(empty($starttime) || empty($endtime)){
$this->message('请选择导出的开始时间和结束时间', NULL, 2);
}
if($starttime > $endtime){
$this->message('开始时间不能大于结束时间', NULL, 2);
}
$sql = "SELECT * FROM {pre}drp_shop WHERE create_time >='".$starttime."' AND create_time <= '".$endtime."' ORDER BY create_time DESC";
$list = $this->model->query($sql);
if($list){
require_once(BASE_PATH . 'libraries/PHPExcel.php');
$excel = new \PHPExcel();
//设置单元格宽度
$excel->getActiveSheet()->getDefaultColumnDimension()->setAutoSize(true);
//设置表格的宽度 手动
$excel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
$excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
$excel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
$excel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
$excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
//设置标题
$rowVal = array(
0=>'编号',
1=>'店铺名',
2=>'真实姓名',
3=>'手机号码',
4=>'开店时间',
5=>'店铺是否审核(1为已审核,0为未审核)',
6=>'店铺状态(1为开启,0为关闭)',
7=>'QQ号'
);
foreach ($rowVal as $k=>$r){
$excel->getActiveSheet()->getStyleByColumnAndRow($k,1)->getFont()->setBold(true);//字体加粗
$excel->getActiveSheet()->getStyleByColumnAndRow($k,1)->getAlignment(); //文字居中
$excel->getActiveSheet()->setCellValueByColumnAndRow($k,1,$r);
}
//设置当前的sheet索引 用于后续内容操作
$excel->setActiveSheetIndex(0);
$objActSheet = $excel->getActiveSheet();
//设置当前活动的sheet的名称
$title="分销商信息";
$objActSheet->setTitle($title);
//设置单元格内容
foreach($list as $k => $v){
$num = $k+2;
$excel->setActiveSheetIndex(0)
//Excel的第A列,uid是你查出数组的键值,下面以此类推
->setCellValue('A'.$num, $v['id'])
->setCellValue('B'.$num, $v['shop_name'])
->setCellValue('C'.$num, $v['real_name'])
->setCellValue('D'.$num, $v['mobile'])
->setCellValue('E'.$num, date("Y-m-d H:i:s",$v['create_time']))
->setCellValue('F'.$num, $v['audit'])
->setCellValue('G'.$num, $v['status'])
->setCellValue('H'.$num, $v['qq']);
}
$name = date('Y-m-d'); //设置文件名
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Transfer-Encoding:utf-8");
header("Pragma: no-cache");
header('Content-Type: application/vnd.ms-e xcel');
header('Content-Disposition: attachment;filename="'.$title.'_'.urlencode($name).'.xls"');
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$objWriter->save('php://output');
exit;
}
}
$this->redirect(U('shop'));
}
/**
* 分销排行
*/
public function actionDrpList(){
$act = I('where');
if(empty($act)){
//全部
$where = '';
}elseif($act==1){
//满一年
$where = ' and '.strtotime('-1 year').'>=s.create_time';
}elseif($act==2){
//满半年
$where = ' and '.strtotime('-6 month').'>=s.create_time';
}elseif($act==3){
//满一月
$where = ' and '.strtotime('-1 month').'>=s.create_time';
}
$filter['where'] = $act;
$offset = $this->pageLimit(U('drp_list', $filter), 10);
$sql = "SELECT count(id) as num FROM {pre}drp_shop as s LEFT JOIN {pre}users as u ON s.user_id=u.user_id WHERE s.audit=1 and s.status=1 ".$where;
$count = $this->model->query($sql);
$this->assign('page', $this->pageShow($count[0]['num']));
$sql = "SELECT d.id, IFNULL(w.nickname,u.user_name) as name, d.shop_name, d.mobile, FROM_UNIXTIME(d.create_time, '%Y-%m-%d') as time,
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
LIMIT ".$offset;
$list = $this->model->query($sql);
$this->assign('list',$list);
$this->display('admin_drp_list');
}
}