<?php
/*
* 软件未经授权许可不得使用!
* 作者:辰芮
* 官网:www.chenrui.com
* 邮件: kefu@chenrui.com
*/
class MemberAction extends CommonAction{
protected function _initialize() {
if(!$_SESSION[C('USER_AUTH_KEY')])//session失效
{
redirect(U('Public/login'));
}
parent::_initialize();
$this->assign('header_status',true);
}
//会员中心
public function index(){
//宝贝收藏
$favorite_count=M('ProductFavorite')->where(array('u_id'=>$this->uid))->count()+0;
$this->assign('favorite_count',$favorite_count);
//待***0
$nopay_count=M('Order')->where(array('user_id'=>$this->uid,'status'=>0))->count()+0;
$this->assign('nopay_count',$nopay_count);
//待发货1
$nosend_count=M('Order')->where(array('user_id'=>$this->uid,'status'=>1))->count()+0;
$this->assign('nosend_count',$nosend_count);
//待收货2
$noreceive_count=M('Order')->where(array('user_id'=>$this->uid,'status'=>2))->count()+0;
$this->assign('noreceive_count',$noreceive_count);
//退货换货6
$return_count=M('Order')->where(array('user_id'=>$this->uid,'status'=>6))->count()+0;
$this->assign('return_count',$return_count);
//最新公告
$news_list=M('Article')->where(array('cate_id'=>1))->order('w_time desc')->limit(6)->select();
$this->assign('news_list',$news_list);
$this->assign('header_title','会员中心');
$this->assign('cur','my');
$this->display();
}
public function fenqipc(){
$this->assign('header_title','我的分期');
import('ORG.Util.Page'); // 导入分页类
$map['user_id'] = $this->uid;
if($_REQUEST['type']=='pay')
{
$map['is_pay'] = 1;
}
else if($_REQUEST['type']==' nopay')
{
$map['is_pay'] = 0;
}
$this->assign('type', $_REQUEST['type']);
$count = M('order_fenqi')->where($map)->count(); // 查询满足要求的总记录数
$Page = new Page($count, 20); // 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show(); // 分页显示输出
$list = M('order_fenqi')->where($map)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('list', $list); // 赋值数据集
$this->assign('page', $show); // 赋值分页输出
// $map_m['user_id'] = $this->uid;
// $map_m['money'] = array('lt', 0);
// $total_out = D('MoneyLogs')->where($map_m)->sum('money');
// $total_out = -$total_out;
// $map_m['money'] = array('gt', 0);
// $total_in = D('MoneyLogs')->where($map_m)->sum('money');
// $this->assign('total_in', $total_in);
//$this->assign('total_out', $total_out);
$this->display();
}
//我的分期
public function fenqi(){
$this->assign('header_title','我的分期');
$map['user_id'] = $this->uid;
if($_REQUEST['type']=='pay')
{
$map['is_pay'] = 1;
}
else if($_REQUEST['type']==' nopay')
{
$map['is_pay'] = 0;
}
$this->assign('type', $_REQUEST['type']);
$this->_list(M('order_fenqi'), $map,'id');
unset($map['is_pay']);
$search_map['type']=$_REQUEST['type'];
$this ->createSearchLink($search_map);
if($this->isAjax())
{
$tpls = $this->fetch('fenqi_list');
$this->ajaxListHtml($tpls, $this->count, $this->has_more);//ajax返回
}
$map_m['user_id'] = $this->uid;
$map_m['is_pay'] =1;
$total_pay = D('order_fenqi')->where($map_m)->sum('money');
$map_m['is_pay'] = 0;
$total_nopay = D('order_fenqi')->where($map_m)->sum('money');
$this->assign('total_pay', $total_pay);
$this->assign('total_nopay', $total_nopay);
$this->display();
}
//编辑资料
public function edit(){
if($this->isPost()){
//保存数据,不需要做判断
foreach($_POST['data'] as $key=>$vv){
$data[$key]=$vv;
}
//$this->checkUserMobileCode($data['mobile_code']);
//图片进行序列化
$image_url='';
if($this->_post('image_path')){
$image_url=$this->_post('image_path');
//更新图片状态
$this->UpdateImage($this->_post('image_path'));
$data['photo']=$image_url[0];
}
if($data){
$res=M('Users')->where(array('user_id'=>$this->uid))->save($data);
if($res){
$this->success('个人资料修改成功',U('Member/index'));
}else{
$this->error('个人资料修改失败');
}
}else{
$this->error('您没有修改资料任何信息');
}
}
$this->assign('header_title','绑定资料');
$this->display();
}
//会员余额支付
public function pay() {
$logs_id = (int) $this->_get('logs_id');
if (empty($logs_id)) {
$this->error('没有有效的支付');
}
M()->startTrans();
if (!$detail = D('Paymentlogs')->find($logs_id)) {
M()->rollback();
$this->error('没有有效的支付');
}
if ($detail['code'] != 'money') {
M()->rollback();
$this->error('没有有效的支付');
}
$member = D('Users')->find($this->uid);
if ($detail['is_paid']) {
M()->rollback();
$this->error('没有有效的支付');
}
if ($member['money'] < $detail['need_pay']) {
M()->rollback();
// $this->error('很抱歉您的账户余额不足', U('Member/purse'));
$this->error('很抱歉您的账户余额不足', U('Member/index'));
}
D('Payment')->logsPaid($logs_id);
M()->commit();
$this->success('支付成功!', U('Member/moneylogs'));
}
//修改会员密码
public function upatepass(){
if($this->isPost()){
//保存数据,不需要做判断
foreach($_POST['data'] as $key=>$vv){
$data[$key]=$vv;
}
//$this->checkUserMobileCode($data['mobile_code']);
//修改登录密码
if($this->member['password']!=''){
if($data['user_ol_pass']==''){
$this->error('请输入原始密码');
}
}
if($data['user_new_pass']==''){
$this->error('请输入新密码');
}
if($data['user_new_password']==''){
$this->error('请输入新确认密码');
}
if($this->member['password']!=''){
if(check_password($data['user_ol_pass'],$this->member['password'])==false){
$this->error('原始密码错误!');
}
}
if($data['user_new_pass']!=$data['user_new_password']){
$this->error('两次新密码输入不一致');
}
if(M('users')->where(array('user_id'=>$this->uid))->save(array('password'=>user_md5($data['user_new_password'])))){
$this->success('修改成功',U('Member/index'));
}else{
$this->error('修改失败');
}
}
$this->assign('header_title','修改密码');
$this->display();
}
//财务记录
public function moneylogs(){
$this->assign('header_title','财务记录');
$map['user_id'] = $this->uid;
if($_REQUEST['type']=='in')
{
$map['money'] = array('gt', 0);
}
else if($_REQUEST['type']=='out')
{
$map['money'] = array('lt', 0);
}
$this->assign('type', $_REQUEST['type']);
$this->_list(M('MoneyLogs'), $map,'log_id');
unset($map['money']);
$search_map['type']=$_REQUEST['type'];
$this ->createSearchLink($search_map);
if($this->isAjax())
{
$tpls = $this->fetch('moneylogs_list');
$this->ajaxListHtml($tpls, $this->count, $this->has_more);//ajax返回
}
$map_m['user_id'] = $this->uid;
$map_m['money'] = array('lt', 0);
$total_out = D('MoneyLogs')->where($map_m)->sum('money');
$total_out = -$total_out;
$map_m['money'] = array('gt', 0);
$total_in = D('MoneyLogs')->where($map_m)->sum('money');
$this->assign('total_in', $total_in);
$this->assign('total_out', $total_out);
$this->display();
}
public function moneylogspc(){
$this->assign('header_title','财务记录');
import('ORG.Util.Page'); // 导入分页类
$map['user_id'] = $this->uid;
if($_REQUEST['type']=='in')
{
$map['money'] = array('gt', 0);
}
else if($_REQUEST['type']=='out')
{
$map['money'] = array('lt', 0);
}
$this->assign('type', $_REQUEST['type']);
$count = M('MoneyLogs')->where($map)->count(); // 查询满足要求的总记录数
$Page = new Page($count, 20); // 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show(); // 分页显示输出
$list = M('MoneyLogs')->where($map)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
$this->assign('list', $list); // 赋值数据集
$this->assign('page', $show); // 赋值分页输出
// $map_m['user_id'] = $this->uid;
// $map_m['money'] = array('lt', 0);
// $total_out = D('MoneyLogs')->where($map_m)->sum('money');
// $total_out = -$total_out;
// $map_m['money'] = array('gt', 0);
// $total_in = D('MoneyLogs')->where($map_m)->sum('money');
// $this->assign('total_in', $total_in);
//$this->assign('total_out', $total_out);
$this->display();
}
//积分记录
public function scorelogs(){
$this->assign('header_title','积分记录');
$map['user_id'] = $this->uid;
if($_REQUEST['type']=='in')
{
$map['money'] = array('gt', 0);
}
else if($_REQUEST['type']=='out')
{
$map['money'] = array('lt', 0);
}
$this->_list(M('ScoreLogs'), $map,'log_id');
unset($map['money']);
$map['type']=$_REQUEST['type'];
$this ->createSearchLink($map);
if($this->isAjax())
{
$tpls = $this->fetch('scorelogs_list');
$this->ajaxListHtml($tpls, $this->count, $this->has_more);//ajax返回
}
$this->assign('type', $_REQUEST['type']);
$map_m['user_id'] = $this->uid;
$map_m['money'] = array('lt', 0);
$total_out = D('ScoreLogs')->where($map_m)->sum('money');
$total_out = -$total_out;
$map_m['money'] = array('gt', 0);
$total_in = D('ScoreLogs')->where($map_m)->sum('money');
$this->assign('total_in', $total_in);
$this->assign('total_out', $total_out);
$this->display();
}
//我的***
public function purse(){
$this->bank_count=M('UserBank')->where(array('user_id'=>$this->uid))->count()+0;
$withdraw_logs=M('Withdraw')->where(array('user_id'=>$this->uid))->order('w_time desc')->select();
$this->assign('withdraw_logs',$withdraw_logs);
$this->assign('header_title','我的***');
$this->display();
}
//银行卡信息
public function user_bank(){
$user_bank = M('UserBank')->where(array('user_id'=>$this->uid))->order('is_default desc')->select();
$this->assign('user_bank', $user_bank);
$this->assign('header_title','我的银行卡');
$this->display();
}
//银行卡信息添加
public function bank_add(){
if( $this->isPost())
{
if(!$this->_post('banktype')){
$this->error('请选择要添加的银行类型');
}
if(!$this->_post('bankname')){
$this->error('请填写开户行');
}
if(!$this->_post('bankcard')){
$this->error('请填写银行卡号');
}
if(!$this->_post('bankuser')){
$this->error('请填写开户名');
}
if(!$this->_post('bankaddress')){
$this->error('请填写开户行地址');
}
$data['user_id'] = $this->uid;
$data['banktype'] = $this->_post('banktype');
$data['bankname'] = $this->_post('bankname');
$data['bankcard'] = $this->_post('bankcard');
$data['bankuser'] = $this->_post('bankuser');
$data['bankaddress'] = $this->_post('bankaddress');
$isExist = M('UserBank')->where( array('user_id'=>$this->uid,'bank_type'=>$data['bank_type'],'bankcard'=>$data['bankcard'] ) )->find();
if( $isExist )
{
$this->error('银行卡号已添加');
}
$rs = M('UserBank')->add($data);
if( $rs )
{
if($this->_post('is_default')=='on'){
M('UserBank')->where(array('user_id'=>$this->uid,'is_default'=>1))->save(array('is_default'=>0));
M('UserBank')->where(array('user_id'=>$this->uid,'id'=>$rs))->save(array('is_default'=>1));
}
$this->success('操作成功', U('Member/user_bank'));
}
else
{
$this->error('操作失败');
}
}
$this->assign('banks',json_encode(C('BANK_LIST_ARR')));
$this->assign('header_title','添加银行卡');
$this->display();
}
//银行卡信息添加
public function bank_edit(){
if($this->isPost()){
$data=$_POST['data'];
$data['is_default']=$data['is_default']=="on"?1:0;
$res=M('UserBank')->where(array('id'=>$data['id']))->save($data);
if($res){
//默认地址唯一
$b_map['user_id']=$this->uid;
$b_map['id']=array('neq',$data['id']);
$before_def=M('UserBank')->where($b_map)->find();
if($data['is_default']==1 && $before_def!=''){
M('UserBank')->where(array('id'=>$before_def['id']))->save(array('is_default'=>0));
}
$this->success('编辑成功',U('Member/user_bank'));
}else{
$this->error('编辑失败');
}
}else{
if($id=$_GET['id']){
$info=M('UserBank')->where(array('id'=>$id))->find();
$this->assign('info',$info);
$this->assign('banks',json_encode(C('BANK_LIST_ARR')));
$this->assign('header_title','编辑银行卡');
$this->display();
}else{
$this->error('网络异常,请稍后重试');
}
}
}
public function bank_delete(){
if($id=$_GET['id']){
M('UserBank')->where(array('id'=>$id))->delete();
$this->success('删除成功',U('Member/user_bank'));
}else{
$this->error('删除失败');
}
}
//帐号充值
public function recharge(){
if($this->isPost()){
if(!$this->_POST('type') || $this->_POST('type')=='请选择'){
$this->error('请选择充值方式');
}
$payment = D('Payment')->checkPayment($this->_POST('type'));
if (empty($payment)) {
$this->error('该支付方式不存在');
}
if(!$this->_post('number') && $this->_post('number')<=0){
$this->error('请填写充值金额');
}
$verify = $this->_post('verify','strtoupper,md5');
if(strtolower($verify) != strtolower(session('verify'))){
session('verify',null);
$this->error('验证码不正确!');
}
//插入充值记录
$data['user_id']=$this->uid;
$data['CurrencyType']='money';
$data['order_no']=returnOrderNo('M');
$data['number']=$this->_post('number');
$data['w_time']=NOW_TIME;
$data['type']=$this->_POST('type');
$data['remark']='在线充值';
$data['status']=0;
$log_id=M('BankRechargeLog')->add($data);
if($log_id){
$code=$this->_POST('type');
$logs = D('Paymentlogs')->getLogsByOrderId('money', $log_id);
if (empty($logs)) {
$logs = array(
'type' => 'money',
'user_id' => $this->uid,
'order_id' => $log_id,
'order_no' => $data['order_no'],
'code' => $code,
'need_pay' => $this->_post('number'),
'create_time' => NOW_TIME,
'create_ip' => get_client_ip(),
'is_paid' => 0
);
$logs['log_id'] = D('Paymentlogs')->add($logs);
} else {
$logs['need_pay'] = $this->_post('number');
$logs['code'] = $code;
D('Paymentlogs')->where(array('id'=>$logs['log_id']))->save($logs);
}
$this->assign('logs',$logs);
$this->assign('table',D('Payment')->getCode($logs));
$this->display('Order/payment');die;
}else{
$this->error('充值失败');die;
}
}else{
$this->assign('payment', D('Payment')->getPayments(true));
$this->assign('header_title','余额充值');
$this->display();
}
}
//提现
public function withdraw(){
if($this->isPost()){
$data=$_POST['data'];
if(!$data['bankcard']){
$this->error('请填写提现账号');
}
if(!$data['bankuser']){
$this->error('请填写账户名');
}
if(!$data['money']){
$this->error('请填写提现金额');
}
if(!$data['verify']){
$this->error('请填写验证码');
}
$verify = md5(strtoupper($data['verify']));
if(strtolower($verify) != strtolower(session('verify'))){
session('verify',null);
$this->error('验证码不正确!');
}
$data['user_id']=$this->uid;
$data['w_time']=NOW_TIME;
$fee=0;
if($this->_CONFIG['tixian']['txstatus']=='1'){
$fee=$data['money']*$this->_CONFIG['tixian']['txfree']/100;
$fee=($fee > $this->_CONFIG['tixian']['txmaxfree'])?$this->_CONFIG['tixian']['txmaxfree']:$fee;
$data['fee']=$fee;
}
$data['money_actual']=$data['money']+$fee;
if($this->member['money'] <$data['money_actual']){
$this->error('账户余额不足');
}
$res=M('Withdraw')->add($data);
if($res){
$this->success('提交成功,请耐心等待管理员审核',U('Member/purse'));
}else{
$this->error('提交失败');
}
}
$bankcards=M('UserBank')->where(array('user_id'=>$this->uid))->field('bankcard')->select();
if($bankcards!=''){
foreach ($bankcards as $v) {
$bankcard[]=$v['bankcard'];
}
$bankcard=json_encode($bankcard);
$this->assign('bankcard',$bankcard);
$this->assign('header_title','账户提现');
$this->display();
}else{
$this->error('请先绑定银行卡');
}
}
public function toshare(){
//这里做下判断
if($this->_get('uid')==''){
$tjuid= $this->uid;
$tjruname = $this->member['account'];
}else{
$tjuid= $this->_get('uid');
$tjruname=D('Users')->where(array('id'=>$this->_get('uid')))->getField('account');
}
$tg_url=$this->_CONFIG['site']['host'].'/?tjuname='.$tjruname;
if($this->_request('tgurl')){
$tg_url=urldecode($this->_request('tgurl'));
}
$user_mod=D('Users');
$erweima_path=$user_mod->where(array('user_id'=>$tjuid))->getField('erweima_path');
$erweima_path=$this->mptuiguangimg($tjuid,$tg_url);
$this->assign('erwema_url', $erweima_path);
$this->assign('tg_url', $tg_url);
$this->assign('header_title','推广名片');
$this->display();
}
public function mptuiguangimg($uid,$url){
$dir_file="./Uploads/mingpian/";
if(!is_dir($dir_file))
{
mkdir($dir_file);
}
$user_mod=D('Users');
$user_vo=$user_mod->where(array('user_id'=>$uid))->find();
if($user_vo['photo']==''){
$user_vo['photo']='./Public/images/headimg.jpg';
}
$logo_path = $this->_CONFIG['site']['logo'];
$lable_box = array('t_mobile_user_touxiang'=>$user_vo['photo'],'t_mobile_web_touxiang'=>$logo_path,'t_mobile_user_name'=>$user_vo['account'],'t_mobile_user_nick'=>$user_vo['nickname'],'t_mobile_user_turename'=>$user_vo['truename'],'t_mobile_user_erweima'=>$user_vo['weixin_img']);
//标签替换
$mingpian_path =$this->_CONFIG['diymp']['print_bg'];//名片背景图
//打上文字
$font_path = './Public/images/msyh.ttf';//字体
$temp_config_lable = explode('||,||', $this->_CONFIG['diymp']['config_lable']);
if (!is_array($temp_config_lable)){
$temp_config_lable[] = $this->_CONFIG['diymp']['config_lable'];
}
//dump($temp_config_lable);die;
/*die;*/
//需要先载入背景图片
$dst_str = imagecreatefromstring(file_get_contents($mingpian_path));
foreach ($temp_config_lable as $temp_key => $temp_lable){
if(!$temp_lable) continue;
$temp_info = explode(',', $temp_lable);
if (is_array($temp_info)){
$temp_info[1] = $lable_box[$temp_info[0]];
}
//dump($temp_info[1]);
//更加标签进行定位
if($temp_info[0]=='t_mobile_user_touxiang' && $temp_info[1]!=''){
//会员头像定位
//获取头像图片的高和宽 imagecopyresized($image_news, $user_image, 0, 0, 0, 0,新w,新h,原始w, 原始h);
$user_get_img=$this->getimagesize_type($temp_info);
imagecopyresized($user_get_img['image_news'], $user_get_img['image_path'], 0, 0, 0, 0,$temp_info[2], $temp_info[3],$user_get_img['img_w'], $user_get_img['img_h']);
imagecopymerge($dst_str, $user_get_img['image_news'], $temp_info[4], $temp_info[5], 0, 0, $temp_info[2], $temp_info[3], 100);//定位
}else if($temp_info[0]=='t_mobile_web_touxiang' && $temp_info[1]!=''){
//系统logo地位
//获取图片的高和宽
$sys_logo_get_img=$this->getimagesize_type($temp_info);
imagecopyresized($sys_logo_get_img['image_news'], $sys_logo_get_img['image_path'], 0, 0, 0, 0,$temp_info[2], $temp_info[3],$sys_logo_get_img['img_w'], $sys_logo_get_img['img_h']);
imagecopymerge($dst_str, $sys_logo_get_img['image_news'], $temp_info[4], $temp_info[5], 0, 0, $temp_info[2], $temp_info[3], 100);//定位
}else if($temp_info[0]=='t_mobile_user_erweima'){
if($temp_info[1]==''){
$fileName_wx = SysQrCode($user_vo['account'],$url);
M('Users')->where(array('user_id'=>$user_vo['user_id']))->save(array('weixin_img'=>$fileName_wx));
$temp_info[1]=$fileName_wx;
}
//会员二维码地位
$erweima_logo_get_img=$this->getimagesize_type($temp_info);
//dump($temp_info);
imagecopyresized($erweima_logo_get_img['image_news'], $erweima_logo_get_img['image_path'], 0, 0, 0, 0,$temp_info[2], $temp_info[3],$erweima_logo_get_img['img_w'], $erweima_logo_get_img['img_h']);
imagecopymerge($dst_str, $erweima_logo_get_img['image_news'], $temp_info[4], $temp_info[5], 0, 0, $temp_info[2], $temp_info[3], 100);//定位
}else{
//剩余全部为文本地位
if($temp_info[1]){
$black = imagecolorallocate($dst_str, 255, 255, 0);//字体颜色
imagefttext($dst_str, 22, 0,$temp_info[4], $temp_info[5], $black, $font_path, $temp_info[1]);
}
}
}
//die;
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($mingpian_path);
//dump($dst_w);die;
$filename_mp = $dir_file.'mingpian_'.$uid;
$user_type='.jpg';
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
$user_type='.gif';
imagegif($dst_str,$filename_mp.'.gif');
break;
case 2://JPG
header('Content-Type: image/jpeg');
$user_type='.jpg';
imagejpeg($dst_str,$filename_mp.'.jpg');
break;
case 3://PNG
header('Content-Type: image/png');
$user_type='.png';
imagepng($dst_str,$filename_mp.'.png');
break;
default:
break;
}
imagedestroy($dst_str);
if($user_get_img['image_news']) imagedestroy($user_get_img['image_news']);
if($sys_logo_get_img['image_news']) imagedestroy($sys_logo_get_img['image_news']);
if($erweima_logo_get_img['image_news']) imagedestroy($erweima_logo_get_img['image_news']);
M('Users')->where(array('user_id'=>$uid))->save(array('erweima_path'=>$filename_mp.$user_type));
return $filename_mp.$user_type;
}
//获取图片的属性
public function getimagesize_type($array){
list($img_w, $img_h,$img_t) = getimagesize($array[1]);
//改变图片大小
$image_news = imagecreatetruecolor($array[2], $array[3]);
//图片类型
$image_path='';
switch ($img_t) {
case 1://GIF
$image_path=imagecreatefromgif($array[1]);
break;
case 2://JPG
$image_path=imagecreatefromjpeg($array[1]);
break;
case 3://PNG
$image_path=imagecreatefrompng($array[1]);
break;
default:
break;
}
return array('image_news'=>$image_news,'image_path'=>$image_path,'img_w'=>$img_w,'img_h'=>$img_h);
}
}