588 lines
21 KiB
PHP
Executable File
588 lines
21 KiB
PHP
Executable File
<?php
|
||
namespace wstmart\admin\model;
|
||
use think\Db;
|
||
use think\Loader;
|
||
/**
|
||
* ============================================================================
|
||
* 会员业务处理
|
||
*/
|
||
class Users extends Base{
|
||
/**
|
||
* 个体认证审核列表
|
||
* @param int $isPersonal 是否是个体认证
|
||
* @return array
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getReview($isPersonal=1){
|
||
|
||
if(1 == $isPersonal){
|
||
$m = Db::name('auth_personal a');
|
||
}else{
|
||
$m = Db::name('auth_company a');
|
||
}
|
||
$where=[];
|
||
$loginName = input('post.loginName');
|
||
if($loginName) $where['u.loginName|u.userPhone'] = $loginName;
|
||
$rs = $m->join('__USERS__ u','a.userId=u.userId')
|
||
->where($where)
|
||
->field('u.loginName,u.userPhone,a.*')
|
||
->order('status ASC,createTime ASC')
|
||
->paginate(input('limit/d'))
|
||
->toArray();
|
||
return $rs;
|
||
}
|
||
/**个体认证操作
|
||
* @param int $isPersonal 是否是个体认证
|
||
* @return array
|
||
* @throws \think\Exception
|
||
* @throws \think\exception\PDOException
|
||
*/
|
||
public function authAction($isPersonal=1){
|
||
$data = input('post.');
|
||
$id = $data['id'];
|
||
if(1 == $data['status']){
|
||
unset($data['reasonsForRefusal']);
|
||
}
|
||
$field = '*';
|
||
$user_data = [];
|
||
if(1 == $isPersonal){
|
||
$field = 'userId,householdName trueName,userPhone';
|
||
$user_data['authType'] = 1;
|
||
$m = Db::name('auth_personal a');
|
||
}else{
|
||
$user_data['authType'] = 2;
|
||
$field = 'userId,trueName,userPhone';
|
||
$m = Db::name('auth_company a');
|
||
}
|
||
$where['id'] = $id;
|
||
$authInfo = $m->where($where)->field($field)->find();
|
||
if(!$authInfo){
|
||
return WSTReturn('认证不存在');
|
||
}else{
|
||
if(1 == $data['status']) {
|
||
$user_data['userPhone'] = $authInfo['userPhone'];
|
||
$user_data['trueName'] = $authInfo['trueName'];
|
||
$user_data['userName'] = $authInfo['trueName'];
|
||
}else{
|
||
$user_data['authType'] = 0;
|
||
}
|
||
Db::name('users')->where(['userId' => $authInfo['userId']])->update($user_data);
|
||
}
|
||
$data['updateTime'] = time();
|
||
$rs = $m->where($where)->update($data);
|
||
if(false !== $rs){
|
||
|
||
return WSTReturn('操作成功',1);
|
||
}
|
||
return WSTReturn('操作失败,请重试',-1);
|
||
}
|
||
/**
|
||
* 获取申请列表
|
||
*/
|
||
public function getUserUpdateList(){
|
||
$where=[];
|
||
$loginName = input('post.loginName');
|
||
if($loginName) $where['u.loginName|u.userPhone'] = $loginName;
|
||
$rs = Db::name('user_update d')
|
||
->join('__USERS__ u','d.userId=u.userId')
|
||
->join('__SHOPS__ s','d.shopId=s.shopId')
|
||
->where($where)
|
||
->field('u.loginName,u.userPhone,u.trueName,s.userName,s.phone,s.shopName,s.provinceId,s.cityId,s.countyId,s.townId,s.villageId,d.userId,d.shopId,d.id,d.applyLevel,d.confirmImg,d.shopImg,d.status,d.reasonsForRefusal,d.createTime,d.updateTime')
|
||
->order('status ASC,createTime ASC')
|
||
->paginate(input('limit/d'))
|
||
->toArray();
|
||
$m = Model('common/Position');
|
||
foreach ($rs['Rows'] as &$v) {
|
||
$m->initData(1);
|
||
$v['province'] = $m->getAreaName($v['provinceId']);
|
||
|
||
$m->initData(2);
|
||
$v['city'] = $m->getAreaName($v['cityId']);
|
||
|
||
$m->initData(3);
|
||
$v['county'] = $m->getAreaName($v['countyId']);
|
||
|
||
$m->initData(4);
|
||
$v['town'] = $m->getAreaName($v['townId']);
|
||
|
||
$m->initData(5);
|
||
$v['village'] = $m->getAreaName($v['villageId']);
|
||
}
|
||
return $rs;
|
||
}
|
||
/**
|
||
* 申请操作
|
||
*/
|
||
public function setUserUpdate(){
|
||
|
||
$data = input('post.');
|
||
$id = $data['id'];
|
||
$applyInfo = Db::name('user_update')->where(['id'=>$id])->field('userId,shopId,applyLevel')->find();
|
||
if(!$applyInfo){
|
||
return WSTReturn('此数据不存在');
|
||
}
|
||
$applyLevel = $applyInfo['applyLevel'];
|
||
if(!in_array($applyLevel,[2,3,4])) return WSTReturn('请正确输入等级!');
|
||
if(1 == $data['status']){
|
||
unset($data['reasonsForRefusal']);
|
||
//店铺位置信息
|
||
$shopInfo = Model('common/shops')->getFieldsById($applyInfo['shopId'],'provinceId,cityId,countyId,townId,villageId');
|
||
$shopInfo = $shopInfo->toArray();
|
||
//检查是否已有代理
|
||
$applyArea='';
|
||
switch ($applyLevel) {
|
||
case 2:
|
||
$applyArea = 'countyId';
|
||
break;
|
||
case 3:
|
||
$applyArea = 'townId';
|
||
break;
|
||
case 4:
|
||
$applyArea = 'villageId';
|
||
break;
|
||
}
|
||
if(Db::name('user_update')->where(['status'=>1,'applyLevel'=>$applyLevel,$applyArea=>$shopInfo[$applyArea]])->value('id')){
|
||
return WSTReturn('当前区域代理已存在');
|
||
}
|
||
$data = array_merge($data,$shopInfo);
|
||
}
|
||
Db::startTrans();
|
||
try{
|
||
$data['updateTime'] = time();
|
||
if(1 == $data['status']){
|
||
//升级会员等级,没啥用了,留着吧
|
||
$userInfo = getUserInfo(['userId'=>$applyInfo['userId']],'userLevel');
|
||
if($applyLevel > $userInfo['userLevel']){
|
||
Db::name('users')->where(['userId'=>$applyInfo['userId']])->update(['userLevel'=>$applyLevel]);
|
||
}
|
||
}
|
||
if(false !== Db::name('user_update')->where(['id'=>$id])->update($data)){
|
||
Db::commit();
|
||
return WSTReturn('操作成功',1);
|
||
}
|
||
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
}
|
||
return WSTReturn('操作失败',-1);
|
||
|
||
}
|
||
/**
|
||
* 分页
|
||
*/
|
||
public function pageQuery(){
|
||
/******************** 查询 ************************/
|
||
$where = [];
|
||
$where['u.dataFlag'] = 1;
|
||
$lName = input('loginName1');
|
||
$phone = input('loginPhone');
|
||
$email = input('loginEmail');
|
||
$uType = input('userType');
|
||
$uStatus = input('userStatus1');
|
||
$sort = input('sort');
|
||
if(!empty($lName))
|
||
$where['loginName|s.shopName'] = ['like',"%$lName%"];
|
||
if(!empty($phone))
|
||
$where['userPhone'] = ['like',"%$phone%"];
|
||
if(!empty($email))
|
||
$where['userEmail'] = ['like',"%$email%"];
|
||
if(is_numeric($uType))
|
||
$where['userType'] = ['=',"$uType"];
|
||
if(is_numeric($uStatus))
|
||
$where['userStatus'] = ['=',"$uStatus"];
|
||
$order = 'u.userId desc';
|
||
if($sort){
|
||
//$sort = str_replace('.',' ',$sort);
|
||
//$order = $sort;
|
||
}
|
||
/********************* 取数据 *************************/
|
||
$rs = $this->alias('u')->join('__SHOPS__ s','u.userId=s.userId and s.dataFlag=1','left')->join('__USER_TREES__ t','u.userId=t.uid','left')->where($where)
|
||
->field(['u.userId','u.regConfirmImg','loginName','u.userName','userType','userPhone','userEmail','userECT','userScore','u.createTime','u.productNum','u.couponsNum','u.wangNum','userStatus','lastTime','s.shopId','userMoney','u.lockMoney','t.pid'])
|
||
->order($order)
|
||
->group('u.userId')
|
||
->paginate(input('limit/d'))
|
||
->toArray();
|
||
$m = Model('Table');
|
||
foreach ($rs['Rows'] as &$v) {
|
||
if($v['pid']){
|
||
$m->setTable('users');
|
||
$v['pName'] = $m->getField(['userId'=>$v['pid']],'loginName');
|
||
}else{
|
||
$v['pName'] = '';
|
||
}
|
||
$m->setTable('user_vouchers_summary');
|
||
$sInfo = $m->getInfo(['userId'=>$v['userId']],'expectedProductNum,expectedCouponsNum');
|
||
$v['expectedProductNum'] = (float)$sInfo['expectedProductNum'];
|
||
$v['expectedCouponsNum'] = (float)$sInfo['expectedCouponsNum'];
|
||
$r = WSTUserRank($v['userScore']);
|
||
$v['rank'] = $r['rankName'];
|
||
}
|
||
return $rs;
|
||
}
|
||
public function getById($id){
|
||
return $this->get(['userId'=>$id]);
|
||
}
|
||
/**
|
||
* 新增
|
||
*/
|
||
public function add(){
|
||
$data = input('post.');
|
||
$data['createTime'] = date('Y-m-d H:i:s');
|
||
$data["loginSecret"] = rand(1000,9999);
|
||
$data['loginPwd'] = md5($data['loginPwd'].$data['loginSecret']);
|
||
WSTUnset($data,'userId,userType,userScore,userTotalScore,lastIP,lastTime,userMoney,lockMoney,dataFlag,rechargeMoney');
|
||
Db::startTrans();
|
||
try{
|
||
$result = $this->validate('Users.add')->allowField(true)->save($data);
|
||
$id = $this->userId;
|
||
if(false !== $result){
|
||
hook("adminAfterAddUser",["userId"=>$id]);
|
||
WSTUseImages(1, $id, $data['userPhoto']);
|
||
Db::commit();
|
||
return WSTReturn("新增成功", 1);
|
||
}
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('新增失败',-1);
|
||
}
|
||
}
|
||
/**
|
||
* 编辑
|
||
*/
|
||
public function edit(){
|
||
$Id = (int)input('post.userId');
|
||
$data = input('post.');
|
||
$u = $this->where('userId',$Id)->field('loginSecret')->find();
|
||
if(empty($u))return WSTReturn('无效的用户');
|
||
//判断是否需要修改密码
|
||
if(empty($data['loginPwd'])){
|
||
unset($data['loginPwd']);
|
||
}else{
|
||
//修改联盟登录密码
|
||
$password = $data['loginPwd'];
|
||
$data['loginPwd'] = md5($data['loginPwd'].$u['loginSecret']);
|
||
}
|
||
Db::startTrans();
|
||
try{
|
||
if(isset($data['userPhoto'])){
|
||
WSTUseImages(1, $Id, $data['userPhoto'], 'users', 'userPhoto');
|
||
}
|
||
|
||
WSTUnset($data,'loginName,createTime,userId,userType,userScore,userTotalScore,lastIP,lastTime,userMoney,lockMoney,dataFlag,rechargeMoney');
|
||
$result = $this->allowField(true)->save($data,['userId'=>$Id]);
|
||
if(false !== $result){
|
||
// 同步修改联盟密码
|
||
// if(!empty($password)){
|
||
// Db::table('rd_users')->where(['shop_id'=>$Id])->setField('password',md5($password));
|
||
// }
|
||
hook("adminAfterEditUser",["userId"=>$Id]);
|
||
Db::commit();
|
||
return WSTReturn("编辑成功", 1);
|
||
}
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('编辑失败',-1);
|
||
}
|
||
}
|
||
/**
|
||
* 查看会员定返数据
|
||
*/
|
||
public function viewUserDayData(){
|
||
|
||
}
|
||
/**
|
||
* 充值
|
||
*/
|
||
public function recharge(){
|
||
$userId = (int)input('post.userId');
|
||
$loginName = input('post.loginName');
|
||
$rechargeCurrency = input('post.rechargeCurrency');//充值币种,1为ECT
|
||
$rechargeType = (int)input('post.rechargeType');//1充值0扣除
|
||
$rechargeNum = (float)input('post.rechargeNum');
|
||
if($rechargeNum <=0){
|
||
return WSTReturn('请正确输入充值数量!');
|
||
}
|
||
$rechargeNames = ['0'=>'扣除','1'=>'充值'];
|
||
if(!$rechargeCurrency) return WSTReturn('请正确输入币种!');
|
||
if(!$userId) $userId = $this->where('loginName',$loginName)->value('userId');
|
||
if(!$userId) return WSTReturn('未找到此会员');
|
||
Db::startTrans();
|
||
try{
|
||
switch ($rechargeCurrency) {
|
||
case 1://购物股
|
||
Model('common/UserVouchers')->insertVouchersNotice($userId,0,$rechargeNum,0,'系统'.$rechargeNames[$rechargeType],$rechargeType);
|
||
break;
|
||
case 2://预获优惠券
|
||
Model('common/UserVouchers')->insertVouchersNotice($userId,0,0,$rechargeNum,'系统'.$rechargeNames[$rechargeType],$rechargeType);
|
||
break;
|
||
case 3://产品券
|
||
case 4://优惠券
|
||
case 5://旺旺券
|
||
$rechargeCurrency-=2;
|
||
Model('common/LogMoneys')->addMoneyLog(0,$userId,0,2,'系统'.$rechargeNames[$rechargeType],$rechargeType,$rechargeNum,'system',$rechargeCurrency);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
Db::commit();
|
||
return WSTReturn("操作成功", 1);
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('操作失败',-1);
|
||
}
|
||
// if($userId){
|
||
// $u = $this->where('userId',$userId)->field('userId,loginSecret,userECT')->find();
|
||
// }else{
|
||
// $u = $this->where('loginName',$loginName)->field('userId,loginSecret,userECT')->find();
|
||
// }
|
||
|
||
// if(empty($u))return WSTReturn('无效的用户');
|
||
// $userId = $u['userId'];
|
||
// if($rechargeType == 2){//扣除
|
||
// if($rechargeCurrency == 1){
|
||
// if($u['userECT'] < $rechargeNum ){
|
||
// return WSTReturn('余额不足以扣除!当前余额:'.$u['userECT']);
|
||
// }
|
||
// }
|
||
// }
|
||
// Db::startTrans();
|
||
// try{
|
||
// if($rechargeCurrency == 1){//ECT
|
||
// if($rechargeType == 1){//充值
|
||
// ectLog($userId,$rechargeNum,10,'',['userECT'=>['exp','userECT+'.$rechargeNum]],1);
|
||
// }else{
|
||
// ectLog($userId,$rechargeNum,10,'',['userECT'=>['exp','userECT-'.$rechargeNum]],2);
|
||
// }
|
||
// }
|
||
// Db::commit();
|
||
// return WSTReturn("操作成功", 1);
|
||
// }catch (\Exception $e) {
|
||
// Db::rollback();errLog($e);
|
||
// return WSTReturn('操作失败',-1);
|
||
// }
|
||
}
|
||
/**
|
||
* 删除
|
||
*/
|
||
public function del(){
|
||
$id = (int)input('post.id');
|
||
if($id==1){
|
||
return WSTReturn('无法删除自营店铺账号',-1);
|
||
}
|
||
Db::startTrans();
|
||
try{
|
||
$data = [];
|
||
$data['dataFlag'] = -1;
|
||
$result = $this->update($data,['userId'=>$id]);
|
||
if(false !== $result){
|
||
//删除店铺信息
|
||
model('shops')->delByUserId($id);
|
||
hook("adminAfterDelUser",["userId"=>$id]);
|
||
WSTUnuseImage('users','userPhoto',$id);
|
||
Db::commit();
|
||
return WSTReturn("删除成功", 1);
|
||
}
|
||
}catch (\Exception $e) {
|
||
Db::rollback();errLog($e);
|
||
return WSTReturn('删除失败',-1);
|
||
}
|
||
}
|
||
/**
|
||
* 是否启用
|
||
*/
|
||
public function changeUserStatus($id, $status){
|
||
Db::startTrans();
|
||
try{
|
||
|
||
$this->update(['userStatus'=>(int)$status],['userId'=>(int)$id]);
|
||
if(0 == $status){
|
||
$lockTime =(int)input('post.lockTime');
|
||
$lockReason =input('post.lockReason');
|
||
Db::name('user_lock')->insert(['userId'=>$id,'lockTime'=>$lockTime,'lockReason'=>$lockReason,'createTime'=>time()]);
|
||
$this->update(['userStatus'=>(int)$status],['userId'=>(int)$id]);
|
||
}
|
||
|
||
Db::commit();
|
||
return WSTReturn("操作成功",1);
|
||
}catch (\Exception $e) {
|
||
//dump($e);
|
||
Db::rollback();errLog($e);
|
||
}
|
||
return WSTReturn("操作失败,请刷新后再重试");
|
||
}
|
||
/**
|
||
* 根据用户名查找用户
|
||
*/
|
||
public function getByName($name){
|
||
return $this->field(['userId','loginName'])->where(['loginName'=>['like',"%$name%"]])->select();
|
||
}
|
||
/**
|
||
* 获取所有用户id
|
||
*/
|
||
public function getAllUserId()
|
||
{
|
||
return $this->where('dataFlag',1)->column('userId');
|
||
}
|
||
/**
|
||
* 重置支付密码
|
||
*/
|
||
public function resetPayPwd(){
|
||
$Id = (int)input('post.userId');
|
||
$loginSecret = $this->where('userId',$Id)->value('loginSecret');
|
||
// 重置支付密码为6个6
|
||
$payPwd = md5('666666'.$loginSecret);
|
||
$result = $this->where('userId',$Id)->setField('payPwd',$payPwd);
|
||
if(false !== $result){
|
||
return WSTReturn("重置成功", 1);
|
||
}else{
|
||
return WSTReturn($this->getError(),-1);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 根据用户账号查找用户信息
|
||
*/
|
||
public function getUserByKey(){
|
||
$key = input('key');
|
||
$user = $this->where(['loginName|userPhone|userEmail'=>['=',$key],'dataFlag'=>1])->find();
|
||
if(empty($user))return WSTReturn('找不到用户',-1);
|
||
$shop = model('shops')->where(['userId'=>$user->userId,'dataFlag'=>1])->find();
|
||
if(!empty($shop))return WSTReturn('该用户已存在关联的店铺信息',-1);
|
||
return WSTReturn('',1,['loginName'=>$user->loginName,'userId'=>$user->userId]);
|
||
}
|
||
/**
|
||
* 导出订单 --林莉
|
||
*/
|
||
public function toExport(){
|
||
$name="会员管理表";
|
||
$where = [];
|
||
$where['u.dataFlag'] = 1;
|
||
$lName = input('loginName1');
|
||
$phone = input('loginPhone');
|
||
$email = input('loginEmail');
|
||
$uType = input('userType');
|
||
$uStatus = input('userStatus1');
|
||
$sort = input('sort');
|
||
if(!empty($lName))
|
||
$where['loginName|s.shopName'] = ['like',"%$lName%"];
|
||
if(!empty($phone))
|
||
$where['userPhone'] = ['like',"%$phone%"];
|
||
if(!empty($email))
|
||
$where['userEmail'] = ['like',"%$email%"];
|
||
if(is_numeric($uType))
|
||
$where['userType'] = ['=',"$uType"];
|
||
if(is_numeric($uStatus))
|
||
$where['userStatus'] = ['=',"$uStatus"];
|
||
$order = 'u.userId desc';
|
||
/********************* 取数据 *************************/
|
||
$page = db('users')->alias('u')->join('__SHOPS__ s','u.userId=s.userId and s.dataFlag=1','left')->where($where)
|
||
->field(['u.userId','loginName','userName','userType','userPhone','userEmail','userECT','userScore','u.createTime','userStatus','lastTime','s.shopId','userMoney','u.lockMoney'])
|
||
->order($order)
|
||
->select();
|
||
foreach ($page as $key => $v) {
|
||
$r = WSTUserRank($v['userScore']);
|
||
$page[$key]['rank'] = $r['rankName'];
|
||
}
|
||
Loader::import('phpexcel.PHPExcel.IOFactory');
|
||
$objPHPExcel = new \PHPExcel();
|
||
// 设置excel文档的属性
|
||
$objPHPExcel->getProperties()->setCreator("heyuanhui")//创建人
|
||
->setLastModifiedBy("heyuanhui")//最后修改人
|
||
->setTitle($name)//标题
|
||
->setSubject($name)//题目
|
||
->setDescription($name)//描述
|
||
->setKeywords("会员")//关键字
|
||
->setCategory("Test result file");//种类
|
||
|
||
// 开始操作excel表
|
||
$objPHPExcel->setActiveSheetIndex(0);
|
||
// 设置工作薄名称
|
||
$objPHPExcel->getActiveSheet()->setTitle(iconv('gbk', 'utf-8', 'Sheet'));
|
||
// 设置默认字体和大小
|
||
$objPHPExcel->getDefaultStyle()->getFont()->setName(iconv('gbk', 'utf-8', ''));
|
||
$objPHPExcel->getDefaultStyle()->getFont()->setSize(11);
|
||
$styleArray = array(
|
||
'font' => array(
|
||
'bold' => true,
|
||
'color'=>array(
|
||
'argb' => 'ffffffff',
|
||
)
|
||
),
|
||
'borders' => array (
|
||
'outline' => array (
|
||
'style' => \PHPExcel_Style_Border::BORDER_THIN, //设置border样式
|
||
'color' => array ('argb' => 'FF000000'), //设置border颜色
|
||
)
|
||
)
|
||
);
|
||
//设置宽
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(8);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(8);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(35);
|
||
$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(25);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID);
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->getFill()->getStartColor()->setARGB('333399');
|
||
|
||
$objPHPExcel->getActiveSheet()
|
||
->setCellValue('A1', '账号')
|
||
->setCellValue('B1', '用户名')
|
||
->setCellValue('C1', '手机号码')
|
||
->setCellValue('D1', '电子邮箱')
|
||
->setCellValue('E1', '可用金额')
|
||
->setCellValue('F1', '冻结金额')
|
||
->setCellValue('G1', '积分')
|
||
->setCellValue('H1', 'ECT')
|
||
->setCellValue('I1', '等级')
|
||
->setCellValue('J1', '注册时间')
|
||
->setCellValue('K1', '状态');
|
||
$objPHPExcel->getActiveSheet()->getStyle('A1:R1')->applyFromArray($styleArray);
|
||
|
||
for ($row = 0; $row < count($page); $row++){
|
||
$i = $row+2;
|
||
$objPHPExcel->getActiveSheet()
|
||
->setCellValue('A'.$i, $page[$row]['loginName'])
|
||
->setCellValue('B'.$i, $page[$row]['userName'])
|
||
->setCellValue('C'.$i, $page[$row]['userPhone'])
|
||
->setCellValue('D'.$i, $page[$row]['userEmail'])
|
||
->setCellValue('E'.$i, $page[$row]['userMoney'])
|
||
->setCellValue('F'.$i, $page[$row]['lockMoney'])
|
||
->setCellValue('G'.$i, $page[$row]['userScore'])
|
||
->setCellValue('H'.$i, $page[$row]['userECT'])
|
||
->setCellValue('I'.$i, $page[$row]['rank'])
|
||
->setCellValue('J'.$i, $page[$row]['createTime'])
|
||
->setCellValue('K'.$i, $page[$row]['userStatus']);
|
||
}
|
||
|
||
//输出EXCEL格式
|
||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||
// 从浏览器直接输出$filename
|
||
header('Content-Type:application/csv;charset=UTF-8');
|
||
header("Pragma: public");
|
||
header("Expires: 0");
|
||
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
|
||
header("Content-Type:application/force-download");
|
||
header("Content-Type:application/vnd.ms-excel;");
|
||
header("Content-Type:application/octet-stream");
|
||
header("Content-Type:application/download");
|
||
header('Content-Disposition: attachment;filename="'.$name.'.xls"');
|
||
header("Content-Transfer-Encoding:binary");
|
||
$objWriter->save('php://output');
|
||
}
|
||
}
|