代码拉取完成,页面将自动刷新
<?php
/**
* tpshop
* ============================================================================
* * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
* ============================================================================
* 2015-11-21
*/
namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use app\home\model\Message;
use think\Page;
use think\Request;
use think\Verify;
use think\db;
class User extends MobileBase
{
public $user_id = 0;
public $user = array();
/*
* 初始化操作
*/
public function _initialize()
{
parent::_initialize();
if (session('?user')) {
$user = session('user');
$user = M('users')->where("user_id", $user['user_id'])->find();
session('user', $user); //覆盖session 中的 user
$this->user = $user;
$this->user_id = $user['user_id'];
$this->assign('user', $user); //存储用户信息
}
$nologin = array(
'login', 'pop_login', 'do_login', 'logout', 'verify', 'set_pwd', 'finished',
'verifyHandle', 'reg', 'send_sms_reg_code', 'find_pwd', 'check_validate_code',
'forget_pwd', 'check_captcha', 'check_username', 'send_validate_code', 'express',
);
if (!$this->user_id && !in_array(ACTION_NAME, $nologin)) {
header("location:" . U('Mobile/User/login'));
exit;
}
$order_status_coment = array(
'WAITPAY' => '待付款 ', //订单查询状态 待支付
'WAITSEND' => '待发货', //订单查询状态 待发货
'WAITRECEIVE' => '待收货', //订单查询状态 待收货
'WAITCCOMMENT' => '待评价', //订单查询状态 待评价
);
$this->assign('order_status_coment', $order_status_coment);
}
/*
* 用户中心首页
*/
public function index()
{
$user_id =$this->user_id;
$logic = new UsersLogic();
$user = $logic->get_info($user_id); //当前登录用户信息
$comment_count = M('comment')->where("user_id", $user_id)->count(); // 我的评论数
$level_name = M('user_level')->where("level_id", $this->user['level'])->getField('level_name'); // 等级名称
//获取用户信息的数量
$user_message_count = D('Message')->getUserMessageCount();
$this->assign('user_message_count', $user_message_count);
$this->assign('level_name', $level_name);
$this->assign('comment_count', $comment_count);
$this->assign('user',$user['result']);
return $this->fetch();
}
public function logout()
{
session_unset();
session_destroy();
setcookie('uname','',time()-3600,'/');
setcookie('cn','',time()-3600,'/');
setcookie('user_id','',time()-3600,'/');
setcookie('PHPSESSID','',time()-3600,'/');
//$this->success("退出成功",U('Mobile/Index/index'));
header("Location:" . U('Mobile/Index/index'));
exit();
}
/*
* 账户资金
*/
public function account()
{
$user = session('user');
//获取账户资金记录
$logic = new UsersLogic();
$data = $logic->get_account_log($this->user_id, I('get.type'));
$account_log = $data['result'];
$this->assign('user', $user);
$this->assign('account_log', $account_log);
$this->assign('page', $data['show']);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_account_list');
exit;
}
return $this->fetch();
}
/**
* 优惠券
*/
public function coupon()
{
$logic = new UsersLogic();
$data = $logic->get_coupon($this->user_id, input('type'));
$coupon_list = $data['result'];
$this->assign('coupon_list', $coupon_list);
$this->assign('page', $data['show']);
if (input('is_ajax')) {
return $this->fetch('ajax_coupon_list');
exit;
}
return $this->fetch();
}
/**
* 确定订单的使用优惠券
* @author lxl
* @time 2017
*/
public function checkcoupon()
{
$type = input('type');
$now = time();
$cartLogic = new \app\home\logic\CartLogic();
// 找出这个用户的优惠券 没过期的 并且 订单金额达到 condition 优惠券指定标准的
$cartLogic->setUserId($this->user_id);
$result = $cartLogic->getUserCartList(1);//获取购物车商品
$where = '';
if(empty($type)){
$where = " c2.uid = {$this->user_id} and {$now} < c1.use_end_time and {$now} > c1.use_start_time and c1.condition <= {$result['total_price']['total_fee']} ";
}
if($type == 1){
$where = " c2.uid = {$this->user_id} and c1.use_end_time < {$now} or c1.use_start_time > {$now} or {$result['total_price']['total_fee']} < c1.condition ";
}
$coupon_list = DB::name('coupon')
->alias('c1')
->field('c1.name,c1.money,c1.condition,c1.use_end_time, c2.*')
->join('coupon_list c2','c2.cid = c1.id and c1.type in(0,1,2,3) and order_id = 0','LEFT')
->where($where)
->select();
$this->assign('coupon_list', $coupon_list); // 优惠券列表
return $this->fetch();
}
/**
* 登录
*/
public function login()
{
if ($this->user_id > 0) {
//
// header("Location: " . U('Mobile/User/index'));
}
$referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U("Mobile/User/index");
$this->assign('referurl', $referurl);
return $this->fetch();
}
/**
* 登录
*/
public function do_login()
{
$username = trim(I('post.username'));
$password = trim(I('post.password'));
//验证码验证
$verify_code = I('post.verify_code');
$verify = new Verify();
if (!$verify->check($verify_code, 'user_login')) {
$res = array('status' => 0, 'msg' => '验证码错误');
exit(json_encode($res));
}
$logic = new UsersLogic();
$res = $logic->login($username, $password);
if ($res['status'] == 1) {
$res['url'] = urldecode(I('post.referurl'));
session('user', $res['result']);
setcookie('user_id', $res['result']['user_id'], null, '/');
setcookie('is_distribut', $res['result']['is_distribut'], null, '/');
$nickname = empty($res['result']['nickname']) ? $username : $res['result']['nickname'];
setcookie('uname', urlencode($nickname), null, '/');
setcookie('cn', 0, time() - 3600, '/');
$cartLogic = new \app\home\logic\CartLogic();
$cartLogic->setUserId($res['result']['user_id']);
$cartLogic->doUserLoginHandle();// 用户登录后 需要对购物车 一些操作
// $cartLogic->login_cart_handle($this->session_id, $res['result']['user_id']); //用户登录后 需要对购物车 一些操作
}
exit(json_encode($res));
}
/**
* 注册
*/
public function reg()
{
if($this->user_id > 0) {
$this->redirect(U('Mobile/User/index'));
// $this->ajaxReturn(['status'=>1,'msg'=>'您已注册']);
}
$reg_sms_enable = tpCache('sms.regis_sms_enable');
$reg_smtp_enable = tpCache('sms.regis_smtp_enable');
if (IS_POST) {
$logic = new UsersLogic();
//验证码检验
//$this->verifyHandle('user_reg');
$username = I('post.username', '');
$password = I('post.password', '');
$password2 = I('post.password2', '');
//是否开启注册验证码机制
$code = I('post.mobile_code', '');
$scene = I('post.scene', 1);
$session_id = session_id();
//是否开启注册验证码机制
if(check_mobile($username)){
if($reg_sms_enable){
//手机功能没关闭
$check_code = $logic->check_validate_code($code, $username, 'phone', $session_id, $scene);
if($check_code['status'] != 1){
$this->ajaxReturn($check_code);
}
}
}
//是否开启注册邮箱验证码机制
if(check_email($username)){
if($reg_smtp_enable){
//邮件功能未关闭
$check_code = $logic->check_validate_code($code, $username);
if($check_code['status'] != 1){
$this->ajaxReturn($check_code);
}
}
}
$data = $logic->reg($username, $password, $password2);
if ($data['status'] != 1)
$this->ajaxReturn($data['msg']);
session('user', $data['result']);
setcookie('user_id', $data['result']['user_id'], null, '/');
setcookie('is_distribut', $data['result']['is_distribut'], null, '/');
$cartLogic = new \app\home\logic\CartLogic();
$cartLogic->setUserId($data['result']['user_id']);
$cartLogic->doUserLoginHandle();// 用户登录后 需要对购物车 一些操作
// $cartLogic->login_cart_handle($this->session_id, $data['result']['user_id']); //用户登录后 需要对购物车 一些操作
$this->ajaxReturn($data);
exit;
}
$this->assign('regis_sms_enable',$reg_sms_enable); // 注册启用短信:
$this->assign('regis_smtp_enable',$reg_smtp_enable); // 注册启用邮箱:
$sms_time_out = tpCache('sms.sms_time_out')>0 ? tpCache('sms.sms_time_out') : 120;
$this->assign('sms_time_out', $sms_time_out); // 手机短信超时时间
return $this->fetch();
}
/*
* 订单列表
*/
public function order_list()
{
$where = ' user_id=' . $this->user_id;
//条件搜索
if(I('get.type')){
$where .= C(strtoupper(I('get.type')));
}
$count = M('order')->where($where)->count();
$Page = new Page($count, 10);
$show = $Page->show();
$order_str = "order_id DESC";
$order_list = M('order')->order($order_str)->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
//获取订单商品
$model = new UsersLogic();
foreach ($order_list as $k => $v) {
$order_list[$k] = set_btn_order_status($v); // 添加属性 包括按钮显示属性 和 订单状态显示属性
//$order_list[$k]['total_fee'] = $v['goods_amount'] + $v['shipping_fee'] - $v['integral_money'] -$v['bonus'] - $v['discount']; //订单总额
$data = $model->get_order_goods($v['order_id']);
$order_list[$k]['goods_list'] = $data['result'];
}
//统计订单商品数量
foreach ($order_list as $key => $value) {
$count_goods_num = '';
foreach ($value['goods_list'] as $kk => $vv) {
$count_goods_num += $vv['goods_num'];
}
$order_list[$key]['count_goods_num'] = $count_goods_num;
}
$this->assign('order_status', C('ORDER_STATUS'));
$this->assign('shipping_status', C('SHIPPING_STATUS'));
$this->assign('pay_status', C('PAY_STATUS'));
$this->assign('page', $show);
$this->assign('lists', $order_list);
$this->assign('active', 'order_list');
$this->assign('active_status', I('get.type'));
if ($_GET['is_ajax']) {
return $this->fetch('ajax_order_list');
exit;
}
return $this->fetch();
}
/*
* 订单详情
*/
public function order_detail()
{
$id = I('get.id/d');
$map['order_id'] = $id;
$map['user_id'] = $this->user_id;
$order_info = M('order')->where($map)->find();
$order_info = set_btn_order_status($order_info); // 添加属性 包括按钮显示属性 和 订单状态显示属性
if (!$order_info) {
$this->error('没有获取到订单信息');
exit;
}
//获取订单商品
$model = new UsersLogic();
$data = $model->get_order_goods($order_info['order_id']);
$order_info['goods_list'] = $data['result'];
//$order_info['total_fee'] = $order_info['goods_price'] + $order_info['shipping_price'] - $order_info['integral_money'] -$order_info['coupon_price'] - $order_info['discount'];
$region_list = get_region_list();
$invoice_no = M('DeliveryDoc')->where("order_id", $id)->getField('invoice_no', true);
$order_info[invoice_no] = implode(' , ', $invoice_no);
//获取订单操作记录
$order_action = M('order_action')->where(array('order_id' => $id))->select();
$this->assign('order_status', C('ORDER_STATUS'));
$this->assign('shipping_status', C('SHIPPING_STATUS'));
$this->assign('pay_status', C('PAY_STATUS'));
$this->assign('region_list', $region_list);
$this->assign('order_info', $order_info);
$this->assign('order_action', $order_action);
if (I('waitreceive')) { //待收货详情
return $this->fetch('wait_receive_detail');
}
return $this->fetch();
}
public function express()
{
$order_id = I('get.order_id/d', 195);
$order_goods = M('order_goods')->where("order_id", $order_id)->select();
$delivery = M('delivery_doc')->where("order_id", $order_id)->find();
$this->assign('order_goods', $order_goods);
$this->assign('delivery', $delivery);
return $this->fetch();
}
/*
* 取消订单
*/
public function cancel_order()
{
$id = I('get.id/d');
//检查是否有积分,余额支付
$logic = new UsersLogic();
$data = $logic->cancel_order($this->user_id, $id);
return $this->ajaxReturn($data);
// if ($data['status'] < 0)
// $this->error($data['msg']);
// $this->success($data['msg']);
}
/*
* 用户地址列表
*/
public function address_list()
{
$address_lists = get_user_address_list($this->user_id);
$region_list = get_region_list();
$this->assign('region_list', $region_list);
$this->assign('lists', $address_lists);
return $this->fetch();
}
/*
* 添加地址
*/
public function add_address()
{
if (IS_POST) {
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, 0, I('post.'));
if ($data['status'] != 1)
$this->error($data['msg']);
elseif (I('post.source') == 'cart2') {
header('Location:' . U('/Mobile/Cart/cart2', array('address_id' => $data['result'])));
exit;
}
$this->success($data['msg'], U('/Mobile/User/address_list'));
exit();
}
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$this->assign('province', $p);
//return $this->fetch('edit_address');
return $this->fetch();
}
/*
* 地址编辑
*/
public function edit_address()
{
$id = I('id/d');
$address = M('user_address')->where(array('address_id' => $id, 'user_id' => $this->user_id))->find();
if (IS_POST) {
$logic = new UsersLogic();
$data = $logic->add_address($this->user_id, $id, I('post.'));
if ($_POST['source'] == 'cart2') {
header('Location:' . U('/Mobile/Cart/cart2', array('address_id' => $id)));
exit;
} else
$this->success($data['msg'], U('/Mobile/User/address_list'));
exit();
}
//获取省份
$p = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
$c = M('region')->where(array('parent_id' => $address['province'], 'level' => 2))->select();
$d = M('region')->where(array('parent_id' => $address['city'], 'level' => 3))->select();
if ($address['twon']) {
$e = M('region')->where(array('parent_id' => $address['district'], 'level' => 4))->select();
$this->assign('twon', $e);
}
$this->assign('province', $p);
$this->assign('city', $c);
$this->assign('district', $d);
$this->assign('address', $address);
return $this->fetch();
}
/*
* 设置默认收货地址
*/
public function set_default()
{
$id = I('get.id/d');
$source = I('get.source');
M('user_address')->where(array('user_id' => $this->user_id))->save(array('is_default' => 0));
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->save(array('is_default' => 1));
if ($source == 'cart2') {
header("Location:" . U('Mobile/Cart/cart2'));
exit;
} else {
header("Location:" . U('Mobile/User/address_list'));
}
}
/*
* 地址删除
*/
public function del_address()
{
$id = I('get.id/d');
$address = M('user_address')->where("address_id", $id)->find();
$row = M('user_address')->where(array('user_id' => $this->user_id, 'address_id' => $id))->delete();
// 如果删除的是默认收货地址 则要把第一个地址设置为默认收货地址
if ($address['is_default'] == 1) {
$address2 = M('user_address')->where("user_id", $this->user_id)->find();
$address2 && M('user_address')->where("address_id", $address2['address_id'])->save(array('is_default' => 1));
}
if (!$row)
$this->error('操作失败', U('User/address_list'));
else
$this->success("操作成功", U('User/address_list'));
}
/*
* 评论晒单
*/
public function comment()
{
$user_id = $this->user_id;
$status = I('get.status');
$logic = new UsersLogic();
$result = $logic->get_comment($user_id, $status); //获取评论列表
$this->assign('comment_list', $result['result']);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_comment_list');
exit;
}
return $this->fetch();
}
/*
*添加评论
*/
public function add_comment()
{
if (IS_POST) {
// 晒图片
$files = request()->file('comment_img_file');
$save_url = 'public/upload/comment/' . date('Y', time()) . '/' . date('m-d', time());
foreach ($files as $file) {
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->rule('uniqid')->validate(['size' => 1024 * 1024 * 3, 'ext' => 'jpg,png,gif,jpeg'])->move($save_url);
if ($info) {
// 成功上传后 获取上传信息
// 输出 jpg
$comment_img[] = '/'.$save_url . '/' . $info->getFilename();
} else {
// 上传失败获取错误信息
$this->error($file->getError());
}
}
if (!empty($comment_img)) {
$add['img'] = serialize($comment_img);
}
$user_info = session('user');
$logic = new UsersLogic();
$add['goods_id'] = I('goods_id/d');
$add['email'] = $user_info['email'];
$hide_username = I('hide_username');
if (empty($hide_username)) {
$add['username'] = $user_info['nickname'];
}
$add['is_anonymous'] = $hide_username; //是否匿名评价:0不是\1是
$add['order_id'] = I('order_id/d');
$add['service_rank'] = I('service_rank');
$add['deliver_rank'] = I('deliver_rank');
$add['goods_rank'] = I('goods_rank');
$add['is'] = I('goods_rank');
//$add['content'] = htmlspecialchars(I('post.content'));
$add['content'] = I('content');
$add['add_time'] = time();
$add['ip_address'] = getIP();
$add['user_id'] = $this->user_id;
//添加评论
$row = $logic->add_comment($add);
if ($row['status'] == 1) {
$this->success('评论成功', U('/Mobile/User/comment', array('status'=>1)));
exit();
} else {
$this->error($row['msg']);
}
}
$rec_id = I('rec_id/d');
$order_goods = M('order_goods')->where("rec_id", $rec_id)->find();
$this->assign('order_goods', $order_goods);
return $this->fetch();
}
/*
* 个人信息
*/
public function userinfo()
{
$userLogic = new UsersLogic();
$user_info = $userLogic->get_info($this->user_id); // 获取用户信息
$user_info = $user_info['result'];
if (IS_POST) {
if ($_FILES['head_pic']['tmp_name']) {
$file = $this->request->file('head_pic');
$validate = ['size'=>1024 * 1024 * 3,'ext'=>'jpg,png,gif,jpeg'];
$dir = 'public/upload/head_pic/';
if (!($_exists = file_exists($dir))){
$isMk = mkdir($dir);
}
$parentDir = date('Ymd');
$info = $file->validate($validate)->move($dir, true);
if($info){
$post['head_pic'] = '/'.$dir.$parentDir.'/'.$info->getFilename();
}else{
$this->error($info->getError());//上传错误提示错误信息
}
}
I('post.nickname') ? $post['nickname'] = I('post.nickname') : false; //昵称
I('post.qq') ? $post['qq'] = I('post.qq') : false; //QQ号码
I('post.head_pic') ? $post['head_pic'] = I('post.head_pic') : false; //头像地址
I('post.sex') ? $post['sex'] = I('post.sex') : $post['sex'] = 0; // 性别
I('post.birthday') ? $post['birthday'] = strtotime(I('post.birthday')) : false; // 生日
I('post.province') ? $post['province'] = I('post.province') : false; //省份
I('post.city') ? $post['city'] = I('post.city') : false; // 城市
I('post.district') ? $post['district'] = I('post.district') : false; //地区
I('post.email') ? $post['email'] = I('post.email') : false; //邮箱
I('post.mobile') ? $post['mobile'] = I('post.mobile') : false; //手机
$email = I('post.email');
$mobile = I('post.mobile');
$code = I('post.mobile_code', '');
$scene = I('post.scene', 6);
if (!empty($email)) {
$c = M('users')->where(['email' => input('post.email'), 'user_id' => ['<>', $this->user_id]])->count();
$c && $this->error("邮箱已被使用");
}
if (!empty($mobile)) {
$c = M('users')->where(['mobile' => input('post.mobile'), 'user_id' => ['<>', $this->user_id]])->count();
$c && $this->error("手机已被使用");
if (!$code)
$this->error('请输入验证码');
$check_code = $userLogic->check_validate_code($code, $mobile, 'phone', $this->session_id, $scene);
if ($check_code['status'] != 1)
$this->error($check_code['msg']);
}
if (!$userLogic->update_info($this->user_id, $post))
$this->error("保存失败");
setcookie('uname',urlencode($post['nickname']),null,'/');
$this->success("操作成功");
exit;
}
// 获取省份
$province = M('region')->where(array('parent_id' => 0, 'level' => 1))->select();
// 获取订单城市
$city = M('region')->where(array('parent_id' => $user_info['province'], 'level' => 2))->select();
// 获取订单地区
$area = M('region')->where(array('parent_id' => $user_info['city'], 'level' => 3))->select();
$this->assign('province', $province);
$this->assign('city', $city);
$this->assign('area', $area);
$this->assign('user', $user_info);
$this->assign('sex', C('SEX'));
//从哪个修改用户信息页面进来,
$dispaly = I('action');
if ($dispaly != '') {
return $this->fetch("$dispaly");
exit;
}
return $this->fetch();
}
/*
* 邮箱验证
*/
public function email_validate()
{
$userLogic = new UsersLogic();
$user_info = $userLogic->get_info($this->user_id); // 获取用户信息
$user_info = $user_info['result'];
$step = I('get.step', 1);
//验证是否未绑定过
if ($user_info['email_validated'] == 0)
$step = 2;
//原邮箱验证是否通过
if ($user_info['email_validated'] == 1 && session('email_step1') == 1)
$step = 2;
if ($user_info['email_validated'] == 1 && session('email_step1') != 1)
$step = 1;
if (IS_POST) {
$email = I('post.email');
$code = I('post.code');
$info = session('email_code');
if (!$info)
$this->error('非法操作');
if ($info['email'] == $email || $info['code'] == $code) {
if ($user_info['email_validated'] == 0 || session('email_step1') == 1) {
session('email_code', null);
session('email_step1', null);
if (!$userLogic->update_email_mobile($email, $this->user_id))
$this->error('邮箱已存在');
$this->success('绑定成功', U('Home/User/index'));
} else {
session('email_code', null);
session('email_step1', 1);
redirect(U('Home/User/email_validate', array('step' => 2)));
}
exit;
}
$this->error('验证码邮箱不匹配');
}
$this->assign('step', $step);
return $this->fetch();
}
/*
* 手机验证
*/
public function mobile_validate()
{
$userLogic = new UsersLogic();
$user_info = $userLogic->get_info($this->user_id); // 获取用户信息
$user_info = $user_info['result'];
$step = I('get.step', 1);
//验证是否未绑定过
if ($user_info['mobile_validated'] == 0)
$step = 2;
//原手机验证是否通过
if ($user_info['mobile_validated'] == 1 && session('mobile_step1') == 1)
$step = 2;
if ($user_info['mobile_validated'] == 1 && session('mobile_step1') != 1)
$step = 1;
if (IS_POST) {
$mobile = I('post.mobile');
$code = I('post.code');
$info = session('mobile_code');
if (!$info)
$this->error('非法操作');
if ($info['email'] == $mobile || $info['code'] == $code) {
if ($user_info['email_validated'] == 0 || session('email_step1') == 1) {
session('mobile_code', null);
session('mobile_step1', null);
if (!$userLogic->update_email_mobile($mobile, $this->user_id, 2))
$this->error('手机已存在');
$this->success('绑定成功', U('Home/User/index'));
} else {
session('mobile_code', null);
session('email_step1', 1);
redirect(U('Home/User/mobile_validate', array('step' => 2)));
}
exit;
}
$this->error('验证码手机不匹配');
}
$this->assign('step', $step);
return $this->fetch();
}
/**
* 用户收藏列表
*/
public function collect_list()
{
$userLogic = new UsersLogic();
$data = $userLogic->get_goods_collect($this->user_id);
$this->assign('page', $data['show']);// 赋值分页输出
$this->assign('goods_list', $data['result']);
if (IS_AJAX) { //ajax加载更多
return $this->fetch('ajax_collect_list');
exit;
}
return $this->fetch();
}
/*
*取消收藏
*/
public function cancel_collect()
{
$collect_id = I('collect_id/d');
$user_id = $this->user_id;
if (M('goods_collect')->where(['collect_id' => $collect_id, 'user_id' => $user_id])->delete()) {
$this->success("取消收藏成功", U('User/collect_list'));
} else {
$this->error("取消收藏失败", U('User/collect_list'));
}
}
/**
* 我的留言
*/
public function message_list()
{
C('TOKEN_ON', true);
if (IS_POST) {
$this->verifyHandle('message');
$data = I('post.');
$data['user_id'] = $this->user_id;
$user = session('user');
$data['user_name'] = $user['nickname'];
$data['msg_time'] = time();
if (M('feedback')->add($data)) {
$this->success("留言成功", U('User/message_list'));
exit;
} else {
$this->error('留言失败', U('User/message_list'));
exit;
}
}
$msg_type = array(0 => '留言', 1 => '投诉', 2 => '询问', 3 => '售后', 4 => '求购');
$count = M('feedback')->where("user_id", $this->user_id)->count();
$Page = new Page($count, 100);
$Page->rollPage = 2;
$message = M('feedback')->where("user_id", $this->user_id)->limit($Page->firstRow . ',' . $Page->listRows)->select();
$showpage = $Page->show();
header("Content-type:text/html;charset=utf-8");
$this->assign('page', $showpage);
$this->assign('message', $message);
$this->assign('msg_type', $msg_type);
return $this->fetch();
}
/**账户明细*/
public function points()
{
$type = I('type', 'all'); //获取类型
$this->assign('type', $type);
if ($type == 'recharge') {
//充值明细
$count = M('recharge')->where("user_id", $this->user_id)->count();
$Page = new Page($count, 16);
$account_log = M('recharge')->where("user_id", $this->user_id)->order('order_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
} else if ($type == 'points') {
//积分记录明细
$count = M('account_log')->where(['user_id' => $this->user_id, 'pay_points' => ['<>', 0]])->count();
$Page = new Page($count, 16);
$account_log = M('account_log')->where(['user_id' => $this->user_id, 'pay_points' => ['<>', 0]])->order('log_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
} else {
//全部
$count = M('account_log')->where(['user_id' => $this->user_id])->count();
$Page = new Page($count, 16);
$account_log = M('account_log')->where(['user_id' => $this->user_id])->order('log_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
}
$showpage = $Page->show();
$this->assign('account_log', $account_log);
$this->assign('page', $showpage);
$this->assign('listRows', $Page->listRows);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_points');
exit;
}
return $this->fetch();
}
/*
* 密码修改
*/
public function password()
{
//检查是否第三方登录用户
$logic = new UsersLogic();
$data = $logic->get_info($this->user_id);
$user = $data['result'];
if ($user['mobile'] == '' && $user['email'] == '')
$this->error('请先到电脑端绑定手机', U('/Mobile/User/index'));
if (IS_POST) {
$userLogic = new UsersLogic();
$data = $userLogic->password($this->user_id, I('post.old_password'), I('post.new_password'), I('post.confirm_password')); // 获取用户信息
if ($data['status'] == -1)
$this->error($data['msg']);
$this->success($data['msg']);
exit;
}
return $this->fetch();
}
function forget_pwd()
{
if ($this->user_id > 0) {
$this->redirect("User/index");
// header("Location: " . U('User/Index'));`
}
$username = I('username');
if (IS_POST) {
if (!empty($username)) {
$this->verifyHandle('forget');
$field = 'mobile';
if (check_email($username)) {
$field = 'email';
}
$user = M('users')->where("email", $username)->whereOr('mobile', $username)->find();
if ($user) {
session('find_password', array('user_id' => $user['user_id'], 'username' => $username,
'email' => $user['email'], 'mobile' => $user['mobile'], 'type' => $field));
header("Location: " . U('User/find_pwd'));
exit;
} else {
$this->error("用户名不存在,请检查");
}
}
}
return $this->fetch();
}
function find_pwd()
{
if ($this->user_id > 0) {
header("Location: " . U('User/index'));
}
$user = session('find_password');
if (empty($user)) {
$this->error("请先验证用户名", U('User/forget_pwd'));
}
$this->assign('user', $user);
return $this->fetch();
}
public function set_pwd()
{
if ($this->user_id > 0) {
// header("Location: " . U('User/Index'));
$this->redirect('Mobile/User/index');
}
$check = session('validate_code');
if (empty($check)) {
header("Location:" . U('User/forget_pwd'));
} elseif ($check['is_check'] == 0) {
$this->error('验证码还未验证通过', U('User/forget_pwd'));
}
if (IS_POST) {
$password = I('post.password');
$password2 = I('post.password2');
if ($password2 != $password) {
$this->error('两次密码不一致', U('User/forget_pwd'));
}
if ($check['is_check'] == 1) {
//$user = get_user_info($check['sender'],1);
$user = M('users')->where("mobile", $check['sender'])->whereOr('email', $check['sender'])->find();
M('users')->where("user_id", $user['user_id'])->save(array('password' => encrypt($password)));
session('validate_code', null);
//header("Location:".U('User/set_pwd',array('is_set'=>1)));
$this->success('新密码已设置行牢记新密码', U('User/index'));
exit;
} else {
$this->error('验证码还未验证通过', U('User/forget_pwd'));
}
}
$is_set = I('is_set', 0);
$this->assign('is_set', $is_set);
return $this->fetch();
}
/**
* 验证码验证
* $id 验证码标示
*/
private function verifyHandle($id)
{
$verify = new Verify();
if (!$verify->check(I('post.verify_code'), $id ? $id : 'user_login')) {
$this->error("验证码错误");
}
}
/**
* 验证码获取
*/
public function verify()
{
//验证码类型
$type = I('get.type') ? I('get.type') : 'user_login';
$config = array(
'fontSize' => 40,
'length' => 4,
'useCurve' => true,
'useNoise' => false,
);
$Verify = new Verify($config);
$Verify->entry($type);
exit();
}
/**
* 账户管理
*/
public function accountManage()
{
return $this->fetch();
}
/**
* 确定收货成功
*/
public function order_confirm()
{
$id = I('get.id/d', 0);
$data = confirm_order($id, $this->user_id);
if ($data['status'] != 1) {
$this->error($data['msg'],U('Mobile/User/order_list'));
} else {
$model = new UsersLogic();
$order_goods = $model->get_order_goods($id);
$this->assign('order_goods', $order_goods);
return $this->fetch();
exit;
}
}
/**
* 申请退货
*/
public function return_goods()
{
$order_id = I('order_id/d', 0);
$order_sn = I('order_sn', 0);
$goods_id = I('goods_id/d', 0);
$good_number = I('good_number/d', 0); //申请数量
$spec_key = I('spec_key');
$order=M('order')->where(["order_id"=>$order_id,'user_id'=>$this->user_id])->find(); //检查是否有这个订单
if(empty($order))
{
$this->error('非法操作');
exit;
}
$order_goods_where = ['order_id'=>$order_id,'goods_id'=>$goods_id,'spec_key'=>$spec_key];
$return_goods = M('return_goods')->where($order_goods_where)->find();
if (!empty($return_goods)) {
$this->success('已经提交过退货申请!', U('Mobile/User/return_goods_info', array('id' => $return_goods['id'])));
exit;
}
if (IS_POST) {
// 晒图片
if (count($_FILES['return_imgs']['tmp_name'])>0) {
$files = request()->file('return_imgs');
$save_url = 'public/upload/return_goods/' . date('Y', time()) . '/' . date('m-d', time());
foreach ($files as $file) {
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->rule('uniqid')->validate(['size' => 1024 * 1024 * 3, 'ext' => 'jpg,png,gif,jpeg'])->move($save_url);
if ($info) {
// 成功上传后 获取上传信息
$return_imgs[] = '/'.$save_url . '/' . $info->getFilename();
} else {
// 上传失败获取错误信息
$this->error($file->getError());
}
}
if (!empty($return_imgs)) {
$data['imgs'] = implode(',', $return_imgs);
}
}
$data['order_id'] = $order_id;
$data['order_sn'] = $order_sn;
$data['goods_id'] = $goods_id;
$data['addtime'] = time();
$data['user_id'] = $this->user_id;
$data['type'] = I('type'); // 服务类型 退货 或者 换货
$data['reason'] = I('reason'); // 问题描述
$data['spec_key'] = I('spec_key'); // 商品规格
$res = M('return_goods')->add($data);
$data['return_id'] = $res; //退换货id
$this->assign('data',$data);
return $this->fetch('return_good_success'); //申请成功
// $this->success('申请成功,客服第一时间会帮你处理', U('Mobile/User/order_list'));
exit;
}
$region_id[] = tpCache('shop_info.province');
$region_id[] = tpCache('shop_info.city');
$region_id[] = tpCache('shop_info.district');
$region_id[] = 0;
$return_address = M('region')->where("id in (".implode(',', $region_id).")")->getField('id,name');
$this->assign('return_address', $return_address);
$order_goods = M('order_goods')->where($order_goods_where)->find(); //找到这个订单商品
$order_info = array_merge($order,$order_goods); //合并数组
//查找订单收货地址
$region = M('order')->field('consignee,country,province,city,district,twon,address,mobile')->where("order_id = $order_id")->find();
$region_list = get_region_list();
$this->assign('region_list', $region_list);
$this->assign('region', $region);
$this->assign('goods', $order_info);
$this->assign('order_id', $order_id);
$this->assign('order_sn', $order_sn);
$this->assign('goods_id', $goods_id);
return $this->fetch();
}
/**
* 退换货列表
*/
public function return_goods_list()
{
//退换货商品信息
$count = M('return_goods')->where("user_id", $this->user_id)->count();
$pagesize = C('PAGESIZE');
$page = new Page($count, $pagesize);
$list = M('return_goods')->where("user_id", $this->user_id)->order("id desc")->limit("{$page->firstRow},{$page->listRows}")->select();
$goods_id_arr = get_arr_column($list, 'goods_id'); //获取商品ID
if (!empty($goods_id_arr)){
$goodsList = M('goods')->where("goods_id", "in", implode(',', $goods_id_arr))->getField('goods_id,goods_name');
}
$state = C('REFUND_STATUS');
$this->assign('goodsList', $goodsList);
$this->assign('list', $list);
$this->assign('state',$state);
$this->assign('page', $page->show());// 赋值分页输出
if (I('is_ajax')) {
return $this->fetch('ajax_return_goods_list');
exit;
}
return $this->fetch();
}
/**
* 退货详情
*/
public function return_goods_info()
{
$id = I('id/d', 0);
$return_goods = M('return_goods')->where("id = $id")->find();
$return_goods['seller_delivery'] = unserialize($return_goods['seller_delivery']); //订单的物流信息,服务类型为换货会显示
if ($return_goods['imgs'])
$return_goods['imgs'] = explode(',', $return_goods['imgs']);
$goods = M('goods')->where("goods_id = {$return_goods['goods_id']} ")->find();
$state = C('REFUND_STATUS');
$this->assign('state',$state);
$this->assign('goods', $goods);
$this->assign('return_goods', $return_goods);
return $this->fetch();
}
public function recharge()
{
$order_id = I('order_id/d');
$paymentList = M('Plugin')->where("`type`='payment' and code!='cod' and status = 1 and scene in(0,1)")->select();
//微信浏览器
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')) {
$paymentList = M('Plugin')->where("`type`='payment' and status = 1 and code='weixin'")->select();
}
$paymentList = convert_arr_key($paymentList, 'code');
foreach ($paymentList as $key => $val) {
$val['config_value'] = unserialize($val['config_value']);
if ($val['config_value']['is_bank'] == 2) {
$bankCodeList[$val['code']] = unserialize($val['bank_code']);
}
}
$bank_img = include APP_PATH . 'home/bank.php'; // 银行对应图片
$payment = M('Plugin')->where("`type`='payment' and status = 1")->select();
$this->assign('paymentList', $paymentList);
$this->assign('bank_img', $bank_img);
$this->assign('bankCodeList', $bankCodeList);
if ($order_id > 0) {
$order = M('recharge')->where("order_id", $order_id)->find();
$this->assign('order', $order);
}
return $this->fetch();
}
/**
* 申请提现记录
*/
public function withdrawals()
{
C('TOKEN_ON', true);
if (IS_POST) {
$this->verifyHandle('withdrawals');
$data = I('post.');
$data['user_id'] = $this->user_id;
$data['create_time'] = time();
$distribut_min = tpCache('basic.min'); // 最少提现额度
if ($data['money'] < $distribut_min) {
$this->error('每次最少提现额度' . $distribut_min);
exit;
}
if ($data['money'] > $this->user['user_money']) {
$this->error("你最多可提现{$this->user['user_money']}账户余额.");
exit;
}
$withdrawal = M('withdrawals')->where(array('user_id' => $this->user_id, 'status' => 0))->sum('money');
if ($this->user['user_money'] < ($withdrawal + $data['money'])) {
$this->error('您有提现申请待处理,本次提现余额不足');
}
if (M('withdrawals')->add($data)) {
$this->success("已提交申请");
exit;
} else {
$this->error('提交失败,联系客服!');
exit;
}
}
$withdrawals_where['user_id'] = $this->user_id;
$count = M('withdrawals')->where($withdrawals_where)->count();
$pagesize = C('PAGESIZE');
$page = new Page($count, $pagesize);
$list = M('withdrawals')->where($withdrawals_where)->order("id desc")->limit("{$page->firstRow},{$page->listRows}")->select();
$this->assign('page', $page->show());// 赋值分页输出
$this->assign('list', $list); // 下线
if (I('is_ajax')) {
return $this->fetch('ajax_withdrawals_list');
exit;
}
$order_count = M('order')->where("user_id", $this->user_id)->count(); // 我的订单数
$goods_collect_count = M('goods_collect')->where("user_id", $this->user_id)->count(); // 我的商品收藏
$comment_count = M('comment')->where("user_id", $this->user_id)->count();// 我的评论数
$coupon_count = M('coupon_list')->where("uid", $this->user_id)->count(); // 我的优惠券数量
$level_name = M('user_level')->where("level_id", $this->user['level'])->getField('level_name'); // 等级名称
$this->assign('level_name', $level_name);
$this->assign('order_count', $order_count);
$this->assign('goods_collect_count', $goods_collect_count);
$this->assign('comment_count', $comment_count);
$this->assign('coupon_count', $coupon_count);
$this->assign('user_money', $this->user['user_money']); //用户余额
return $this->fetch();
}
/**
* 申请记录列表
*/
public function withdrawals_list()
{
$withdrawals_where['user_id'] = $this->user_id;
$count = M('withdrawals')->where($withdrawals_where)->count();
$pagesize = C('PAGESIZE');
$page = new Page($count, $pagesize);
$list = M('withdrawals')->where($withdrawals_where)->order("id desc")->limit("{$page->firstRow},{$page->listRows}")->select();
$this->assign('page', $page->show());// 赋值分页输出
$this->assign('list', $list); // 下线
if (I('is_ajax')) {
return $this->fetch('ajax_withdrawals_list');
exit;
}
return $this->fetch();
}
/**
* 删除已取消的订单
*/
public function order_del()
{
$user_id = $this->user_id;
$order_id = I('get.order_id/d');
$order = M('order')->where(array('order_id' => $order_id, 'user_id' => $user_id))->find();
if (empty($order)) {
return $this->error('订单不存在');
exit;
}
$res = M('order')->where("order_id=$order_id and order_status=3")->delete();
$result = M('order_goods')->where("order_id=$order_id")->delete();
if ($res && $result) {
return $this->success('成功', "mobile/User/order_list");
exit;
} else {
return $this->error('删除失败');
exit;
}
}
/**
* 我的关注
* @author lxl
* @time 2017/1
*/
public function myfocus()
{
return $this->fetch();
}
/**
* 待收货列表
* @author lxl
* @time 2017/1
*/
public function wait_receive()
{
$where = ' user_id=' . $this->user_id;
//条件搜索
if (I('type') == 'WAITRECEIVE') {
$where .= C(strtoupper(I('type')));
}
$count = M('order')->where($where)->count();
$pagesize = C('PAGESIZE');
$Page = new Page($count, $pagesize);
$show = $Page->show();
$order_str = "order_id DESC";
$order_list = M('order')->order($order_str)->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
//获取订单商品
$model = new UsersLogic();
foreach ($order_list as $k => $v) {
$order_list[$k] = set_btn_order_status($v); // 添加属性 包括按钮显示属性 和 订单状态显示属性
//$order_list[$k]['total_fee'] = $v['goods_amount'] + $v['shipping_fee'] - $v['integral_money'] -$v['bonus'] - $v['discount']; //订单总额
$data = $model->get_order_goods($v['order_id']);
$order_list[$k]['goods_list'] = $data['result'];
}
//统计订单商品数量
foreach ($order_list as $key => $value) {
$count_goods_num = '';
foreach ($value['goods_list'] as $kk => $vv) {
$count_goods_num += $vv['goods_num'];
}
$order_list[$key]['count_goods_num'] = $count_goods_num;
//订单物流单号
$invoice_no = M('DeliveryDoc')->where("order_id", $value['order_id'])->getField('invoice_no', true);
$order_list[$key][invoice_no] = implode(' , ', $invoice_no);
}
$this->assign('page', $show);
$this->assign('order_list', $order_list);
if ($_GET['is_ajax']) {
return $this->fetch('ajax_wait_receive');
exit;
}
return $this->fetch();
}
/**
* 用户消息通知
* @author dyr
* @time 2016/09/01
*/
public function message_notice()
{
return $this->fetch();
}
/**
* ajax用户消息通知请求
* @author dyr
* @time 2016/09/01
*/
public function ajax_message_notice()
{
$type = I('type', 0);
$user_logic = new UsersLogic();
$message_model = new Message();
if ($type == 1) {
//系统消息
$user_sys_message = $message_model->getUserMessageNotice();
$user_logic->setSysMessageForRead();
} else if ($type == 2) {
//活动消息:后续开发
$user_sys_message = array();
} else {
//全部消息:后续完善
$user_sys_message = $message_model->getUserMessageNotice();
}
$this->assign('messages', $user_sys_message);
return $this->fetch('ajax_message_notice');
}
/**
* 设置消息通知
*/
public function set_notice(){
//暂无数据
return $this->fetch();
}
/**
* 取消售后服务
* @author lxl
* @time 2017-4-19
*/
public function return_goods_cancel(){
$id = I('id',0);
if(empty($id))$this->error('参数错误');
$return_goods = M('return_goods')->where(array('id'=>$id,'user_id'=>$this->user_id))->find();
if(empty($return_goods)) $this->error('参数错误');
M('return_goods')->where(array('id'=>$id))->save(array('status'=>-2,'canceltime'=>time()));
$this->success('取消成功',U('User/return_goods_list'));
exit;
}
/**
* 换货商品确认收货
* @author lxl
* @time 17-4-25
* */
public function receiveConfirm(){
$return_id=I('return_id/d');
$return_info=M('return_goods')->field('order_id,order_sn,goods_id,spec_key')->where('id',$return_id)->find(); //查找退换货商品信息
$update = M('return_goods')->where('id',$return_id)->save(['status'=>3]); //要更新状态为已完成
if($update) {
M('order_goods')->where(array(
'order_id' => $return_info['order_id'],
'goods_id' => $return_info['goods_id'],
'spec_key' => $return_info['spec_key']))->save(['is_send' => 2]); //订单商品改为已换货
$this->success("操作成功", U("User/return_goods_info", array('id' => $return_id)));
}
$this->error("操作失败");
}
/**
* 浏览记录
*/
public function visit_log()
{
$count = M('goods_visit')->where('user_id', $this->user_id)->count();
$Page = new Page($count, 20);
$visit = M('goods_visit')->alias('v')
->field('v.visit_id, v.goods_id, v.visittime, g.goods_name, g.shop_price, g.cat_id')
->join('__GOODS__ g', 'v.goods_id=g.goods_id')
->where('v.user_id', $this->user_id)
->order('v.visittime desc')
->limit($Page->firstRow, $Page->listRows)
->select();
/* 浏览记录按日期分组 */
$curyear = date('Y');
$visit_list = [];
foreach ($visit as $v) {
if ($curyear == date('Y', $v['visittime'])) {
$date = date('m月d日', $v['visittime']);
} else {
$date = date('Y年m月d日', $v['visittime']);
}
$visit_list[$date][] = $v;
}
$this->assign('visit_list', $visit_list);
if (I('get.is_ajax', 0)) {
return $this->fetch('ajax_visit_log');
}
return $this->fetch();
}
/**
* 删除浏览记录
*/
public function del_visit_log()
{
$visit_ids = I('get.visit_ids', 0);
$row = M('goods_visit')->where('visit_id','IN', $visit_ids)->delete();
if(!$row) {
$this->error('操作失败',U('User/visit_log'));
} else {
$this->success("操作成功",U('User/visit_log'));
}
}
/**
* 清空浏览记录
*/
public function clear_visit_log()
{
$row = M('goods_visit')->where('user_id', $this->user_id)->delete();
if(!$row) {
$this->error('操作失败',U('User/visit_log'));
} else {
$this->success("操作成功",U('User/visit_log'));
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。