文件
mashangyoujiu/Application/Retail/Controller/VipController.class.php

672 行
22 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Api\Controller\RechargeRefundController;
use Common\Business\VipEdit;
use Common\Business\VipInfo;
use Common\Model\RetailVipModel;
use Common\Order\VipChangeRecord;
use Retail\Business\GeneralUser;
use Retail\Model\WeekDiscountModel;
use Retail\Business\Vip;
use Think\Controller;
//[1.8.50]
/**
* 商户管理常规会员
* Class VipController
* @package Retail\Controller
*/
class VipController extends BaseController
{
/**
* 会员列表
*/
public function index()
{
$this->display();
}
/**
* 获取会员列表
*/
public function vipList()
{
$data = I('post.');
$data['merchant_id'] = $this->merchant_id;
$Vip = new Vip();
$this->ajaxReturn($Vip->getVipList($data));
}
/**
* 获取会员统计
*/
public function getSumData()
{
$data = I("post.");
$data['merchant_id'] = $this->merchant_id;
$Vip = new Vip();
$this->ajaxReturn($Vip->getVipSumData($data));
}
/**
* 导出会员
*/
public function exportVip()
{
$data = I('get.');
$data['merchant_id'] = $this->merchant_id;
$data['need_count'] = false;
$data['need_index'] = true;
$data['is_export'] = true;
$Vip = new Vip();
$vip_info = $Vip->getVipList($data)['data']['list'];
$filename = "会员信息统计";
$headArr = array(
array('index', '序号'),
array('name', '会员姓名'),
array('nickname', '会员昵称'),
array('mobile_phone', '手机号'),
array('card_key', '实体卡'),
array('birthday', '生日'),
array('grade_name', '等级'),
array('discount', '折扣'),
array('balance', '余额'),
array('integral', '积分'),
array('store_name', '所属门店'),
array('guide_name', '所属导购'),
array('add_time', '激活时间'),
array('status_name', '会员状态'),
);
$str = $filename . ',导出日期:' . date('Y-m-d H:i:s');
getExcel($filename, $headArr, $vip_info, $str);
}
/**
* 编辑会员信息提交
*/
public function modifyVip()
{
$data = I('post.');
$data['operator_type'] = 1;
$data['user_type'] = 3;
$data['operator_id'] = $this->login_user['id'];
$data['merchant_id'] = $this->merchant_id;
$data['platform_type'] = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
$VipEditClass = new VipEdit();
$this->ajaxReturn($VipEditClass->editInfo($data));
}
/**
* 修改会员支付密码
*/
public function modifyPassword()
{
$data['operator_type'] = 1;
$data['user_type'] = 3;
$data['operator_id'] = $this->login_user['id'];
$data['merchant_id'] = $this->merchant_id;
$data['vip_id'] = I('post.vip_id');
$data['password'] = I('post.password');
$VipEditClass = new VipEdit();
$this->ajaxReturn($VipEditClass->editVipPassword($data));
}
/**
* 冻结会员
*/
public function frozenVip()
{
$VipEditClass = new VipEdit();
$this->ajaxReturn($VipEditClass->operateVipStatus([
'merchant_id' => $this->merchant_id,
'vip_id' => I('post.vip_id'),
'status' => 3,//1恢复 3冻结 4挂失
'plus_type' => 3,
'scene' => 3,//3商户 4门店
]));
}
/**
* 解冻
*/
public function thawVip()
{
$VipEditClass = new VipEdit();
$this->ajaxReturn($VipEditClass->operateVipStatus([
'merchant_id' => $this->merchant_id,
'vip_id' => I('post.vip_id'),
'status' => 1,//1恢复 3冻结 4挂失
'plus_type' => 2,
'scene' => 3,//3商户 4门店
]));
}
/**
* 挂失
*/
public function lossVip()
{
$VipEditClass = new VipEdit();
$this->ajaxReturn($VipEditClass->operateVipStatus([
'merchant_id' => $this->merchant_id,
'vip_id' => I('post.vip_id'),
'status' => 4,//1恢复 3冻结 4挂失
'plus_type' => 2,
'scene' => 3,//3商户 4门店
]));
}
/**
* 重置会员openid
*/
public function resetOpenId()
{
$VipModel = new RetailVipModel();
$update = $VipModel->updateOrder(['merchantid' => $this->merchant_id], ['openid' => '', 'is_register' => 0]);
if ($update) {
$res['status'] = 1;
$res['msg'] = '重置成功';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = '{}'; //请求参数 json数据
$desc = '常规会员进行重置会员openID所属操作'; //操作行为描述
action_log($source, $type, $request_data, $desc);
} else {
$res['status'] = 0;
$res['msg'] = '暂无可重置会员';
}
$this->ajaxReturn($res);
}
/**
* 2018-10-20 会员批量删除
*/
public function batchDelete()
{
if (IS_POST) {
$ids = I("post.ids");
if (isset($ids)) {
$map['id'] = array("in", rtrim($ids, ','));
$change = M("retail_vip")->where($map)->save(array("status" => 3));
if ($change) {
$res['status'] = 1;
$res['msg'] = '操作成功';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '常规会员批量冻结'; //操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数错误';
}
}
$this->ajaxReturn($res);
}
/**
* 批量恢复会员
*/
public function batchRecovery()
{
if (IS_POST) {
$ids = I("post.ids");
if (isset($ids)) {
$map['id'] = array("in", rtrim($ids, ','));
$change = M("retail_vip")->where($map)->save(array("status" => 1));
if ($change) {
$res['status'] = 1;
$res['msg'] = '操作成功';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '常规会员批量恢复'; //操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数错误';
}
}
$this->ajaxReturn($res);
}
/**
* 充值列表
*/
public function rechargeIndex()
{
$vip_id = I('get.id');
$this->assign('vip_id', $vip_id);
$this->display();
}
/**
* 点击会员退款获取该会员充值列表
*/
public function rechargeList()
{
if (IS_POST) {
$id = I('post.id');
$page = I('post.page');
$limit = I('post.limit');
$RechargeRefund = new RechargeRefundController();
$this->ajaxReturn($RechargeRefund->rechargeList($id, $this->merchant_id, 0, 0, 1, $page, $limit));
}
}
/**
* 会员余额退款
*/
public function refundMoney()
{
if (IS_POST) {
$id = I('post.id');
$RechargeRefund = new RechargeRefundController();
$res = $RechargeRefund->refundMoney($this->merchant_id, $id, 2);
//操作日志记录
if ($res['status'] == 1) {
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '会员充值余额退款操作'; //操作行为描述
action_log($source, $type, $request_data, $desc);
}
$this->ajaxReturn($res);
}
}
/**
* 2018-09-25 会员等级管理
*/
public function groups()
{
$arr = array(
'groupSet' => '/index.php/Retail/Vip/groupSet',
'groupDel' => '/index.php/Retail/Vip/groupDel',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function groupList()
{
$map = [
'merchantid' => $this->merchant_id
];
$page = I('post.page');
$limit = I('post.limit');
$list = M("retail_vip_integral")->where($map)->page($page, $limit)->order('id asc')->select();
$count = M("retail_vip_integral")->where($map)->count();
foreach ($list as $key => $value) {
$list[$key]['index'] = $key + 1;
if (!empty($value['gradeimgurl_id'])) {
$list[$key]['gradeimgurl'] = D('ImageGallery')->getOneField(array('id' => $value['gradeimgurl_id']), 'path');
}
}
$res['count'] = (int)$count;
$res['data'] = $list;
$res['status'] = 1;
$res['msg'] = '查询成功';
$this->ajaxReturn($res);
}
/**
* 会员卡编辑
*/
public function groupSet()
{
if ($_POST) {
$post = I("post.");
$where['merchantid'] = $this->merchant_id;
$where['cardname'] = $post['cardname'];
if ($post['id']) {
$where['id'] = ['NEQ', $post['id']];
}
$find = M('retail_vip_integral')->where($where)->getField('id');
if ($find && $find != $post['id']) {
$res['status'] = 0;
$res['msg'] = '会员组名称已存在';
$this->ajaxReturn($res);
}
unset($where['cardname']);
$where['grade'] = $post['grade'];
$find = M('retail_vip_integral')->where($where)->getField('id');
if ($find && $find != $post['id']) {
$res['status'] = 0;
$res['msg'] = '会员组等级已存在';
$this->ajaxReturn($res);
}
unset($where['grade']);
$where['min_integral'] = $post['min_integral'];
$find = M('retail_vip_integral')->where($where)->getField('id');
if ($find && $find != $post['id']) {
$res['status'] = 0;
$res['msg'] = '会员组等级积分已存在';
$this->ajaxReturn($res);
}
$gradeimgurl_id = $post['gradeimgurl_id'];
if (!$gradeimgurl_id && empty($_FILES['gradeimgurl']['name'])) {
$res['status'] = 0;
$res['msg'] = '请上传图片';
$this->ajaxReturn($res);
}
if ($_FILES['gradeimgurl']['error'] == 0) {
$item = array(
'add_time' => time(),
'from_type_id' => 20,
'localUrl' => 'Merchant/Grade',
'user_type' => 3,
'merchant_id' => $this->merchant_id
);
$uploads = uploadFiles($item);
if (!empty($uploads['gradeimgurl'])) {
$gradeimgurl_id = $uploads['gradeimgurl']['id'];
$data['gradeimgurl'] = $uploads['gradeimgurl']['path'];
}
} else if ($gradeimgurl_id) {
$data['gradeimgurl'] = D('ImageGallery')->getOneField(array('id' => $gradeimgurl_id), 'path');
}
$data['gradeimgurl_id'] = $gradeimgurl_id ? $gradeimgurl_id : 0;
$data['cardname'] = $post['cardname'];
$data['grade'] = $post['grade'];
$data['min_integral'] = $post['min_integral'];
$data['discount'] = $post['discount'];
$data['addtime'] = time();
$data['merchantid'] = $this->merchant_id;
if ($post['id']) {
$rows = M("retail_vip_integral")->where(array('id' => $post['id']))->save($data);
if ($rows) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '常规会员进行编辑会员等级操作'; //操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
} else {
$rows = M("retail_vip_integral")->add($data);
if ($rows) {
$res['status'] = 1;
$res['msg'] = '创建成功';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '常规会员进行新增会员等级操作'; //操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '创建失败';
}
}
$this->ajaxReturn($res);
}
}
/**
* 删除会员卡
*/
public function groupDel()
{
if ($_POST) {
$id = I("post.id");
if ($id) {
$row = M("retail_vip_integral")->where("id=" . $id)->delete();
if ($row) {
$res['status'] = 1;
$res['msg'] = '已删除';
//操作日志记录
$source = 0; //请求来源: 0pc系统 1小助手
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST); //请求参数 json数据
$desc = '常规会员进行删除会员等级操作'; //操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数有误,请检查';
}
$this->ajaxReturn($res);
}
}
/**
* 获取会员等级列表 供筛选 2021-02-06
*/
public function getVipGradeList()
{
$VipInfo = new VipInfo();
$list = $VipInfo->getVipGradeList([
'merchant_id' => $this->merchant_id,
'integralRange' => I('post.integralRange'),
]);
$this->ajaxReturn([
'status' => 1,
'message' => $list ? '获取成功' : '暂无数据',
'data' => $list,
]);
}
/***********************************************普通用户模块*************************************************/
public function xcxvip()
{
$this->display();
}
/**
* 获取小程序用户
*/
public function getXcxUser()
{
$GeneralUser = new GeneralUser();
$param['merchant_id'] = $this->merchant_id;
// 分页
$param['page'] = (int)I('post.page') ? (int)I('post.page') : 1;
$param['limit'] = (int)I('post.limit') ? (int)I('post.limit') : 10;
// 搜索条件
$param['search_info'] = I('post.search_info');
$result = $GeneralUser->getGeneralUserList($param);
$this->ajaxReturn($result);
}
/**
* 导出小程序用户
*/
public function xcxUserExport()
{
$GeneralUser = new GeneralUser();
$param['merchant_id'] = $this->merchant_id;
$param['search_info'] = I('get.search_info');
$result = $GeneralUser->getGeneralUserList($param);
$data = $result['list'];
// 导出
$file_name = '普通成员';
$heararr = array(
array('index', '序号'),
array('nickname', '昵称'),
array('add_time', '注册时间'),
array('mobile_phone', '自提手机号'),
array('link_name', '自提姓名'),
);
$str = $file_name . '导出时间' . date('Y-m-d', time());
getExcel($file_name, $heararr, $data, $str);
}
/**
* 变更小程序用户
* @param [array] $edit_form 提交数据
* @return [array] $res
*/
public function changeRole()
{
$GeneralUser = new GeneralUser();
$edit_form = I('post.');
$param['merchant_id'] = $this->merchant_id;
$param['operator_id'] = $this->login_user['id'];
$param['platform_type'] = $this->role_info['platform_type'] ? $this->role_info['platform_type'] : 1;
$result = $GeneralUser->changeXcxInfo($edit_form, $param, 1);
$this->ajaxReturn($result);
}
/********************************************变更记录*****************************************************/
/**
* 变更记录,加载页面
*/
public function editRecord()
{
$this->display();
}
// 提交特殊等级折扣
public function submitDiscount()
{
$param = I('post.');
$weekDiscountModel = new WeekDiscountModel();
$result = array();
$res = $weekDiscountModel->setData($param);
if($res > 0){
$result['msg'] = "操作成功";
$result['status'] = 1;
}else{
$result['msg'] = "操作失败";
$result['status'] = -1;
}
$this->ajaxReturn($result);
}
//获取特殊折扣
public function getWeekDiscount()
{
$weekDiscountModel = new WeekDiscountModel();
$result = array();
$result['msg'] = "成功";
$result['status'] = 1;
$result['data'] = $weekDiscountModel->getData();
$this->ajaxReturn($result);
}
/**
* 获取变更记录
* $seek_data array 搜索条件
* $page int|string 字符串
* $limit int|string 数量
*/
public function getVipChangeList()
{
if (IS_POST) {
$seek_data = I('post.');
$VipChangeRecordApi = new VipChangeRecord();
$res = $VipChangeRecordApi->getRecordList([
'merchant_id' => $this->merchant_id,
'store_id' => $seek_data['store_id'],
'get_vip_type' => $seek_data['store_id'] ? 1 : 2,
'start_time' => $seek_data['time_slot'] ? $seek_data['time_slot'][0] : '',
'end_time' => $seek_data['time_slot'] ? $seek_data['time_slot'][1] : '',
'keyword' => $seek_data['keyword'],
'page' => $seek_data['page'],
'limit' => $seek_data['limit'],
'need_count' => 1,
]);
$this->ajaxReturn($res);
}
}
/**
* 变更记录导出
*/
public function vipChangeExport()
{
if (IS_GET) {
$seek_data = I('get.data');
$seek_data = json_decode($seek_data, true);
$VipChangeRecordApi = new VipChangeRecord();
$res = $VipChangeRecordApi->getRecordList([
'merchant_id' => $this->merchant_id,
'store_id' => $seek_data['store_id'],
'get_vip_type' => $seek_data['store_id'] ? 1 : 2,
'start_time' => $seek_data['time_slot'] ? $seek_data['time_slot'][0] : '',
'end_time' => $seek_data['time_slot'] ? $seek_data['time_slot'][1] : '',
'keyword' => $seek_data['keyword'],
'page' => I('post.page'),
'limit' => I('post.limit'),
'need_count' => 0,
]);
$filename = "会员变更记录";
$headerArr = array(
array('index', '序号'),
array('name', '会员姓名'),
array('nickname', '会员昵称'),
array('store_name', '操作门店'),
array('operator_type', '操作人员类型'),
array('operator_name', '操作人员'),
array('add_time', '操作时间'),
array('before_phone', '变更前手机号'),
array('after_phone', '变更后手机号'),
array('before_card_key', '变更前实体卡'),
array('after_card_key', '变更后实体卡'),
array('before_balance', '变更前余额'),
array('after_balance', '变更后余额'),
array('before_grade', '变更前等级'),
array('after_grade', '变更后等级'),
array('before_integral', '变更前积分'),
array('after_integral', '变更后积分'),
array('password', '是否修改密码'),
);
if ($res['status'] == 1) {
$one_line_str = $filename . '导出日期' . date('Y-m-d H:i:s', time());
getExcel($filename, $headerArr, $res['data']['list'], $one_line_str);
} else {
$one_line_str = $res['message'];
getExcel($filename, $headerArr, [], $one_line_str);
}
}
}
}