334 行
9.7 KiB
PHP
可执行文件
334 行
9.7 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace CashierApi\Controller;
|
|
|
|
use Common\Model\RetailVipLabelModel;
|
|
use Common\Model\RetailVipWithLabelModel;
|
|
use Think\Controller;
|
|
|
|
//[1.8.8]
|
|
|
|
/**
|
|
* 收银端会员分析
|
|
* Class VipLabelController
|
|
* @package CashierApi\Controller
|
|
*/
|
|
class VipLabelController extends Controller
|
|
{
|
|
static $merchant_id;
|
|
static $store_id;
|
|
|
|
public function _initialize()
|
|
{
|
|
$user_type = I('post.user_type');
|
|
if ($user_type != 2) {
|
|
$Base = new BaseController();
|
|
$Base->_initialize();
|
|
}
|
|
|
|
self::$merchant_id = I('post.merchant_id');
|
|
self::$store_id = I('post.store_id');
|
|
}
|
|
|
|
// 获取当前会员的标签
|
|
public function getUserLabel()
|
|
{
|
|
$vid = I('post.vid');
|
|
if (!$vid) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
$map = [
|
|
'rvwl.is_del' => 1,
|
|
'rvl.is_del' => 1,
|
|
'vid' => $vid,
|
|
'rvl.store_id' => self::$store_id,
|
|
];
|
|
|
|
$field = [
|
|
'rvwl.vip_label_id',
|
|
'rvl.name',
|
|
];
|
|
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$vipLabel = $RetailVipLabelModel->getUserLabel($map, $field, 1, 20);
|
|
if ($vipLabel['list']) {
|
|
$res = ['status' => 1, 'msg' => '数据获取成功', 'data' => $vipLabel];
|
|
} else {
|
|
$res = ['status' => 1, 'msg' => '暂无数据,请稍后重试', 'data' => [
|
|
'list' => [],
|
|
'total' => 0,
|
|
]];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 给用户添加标签
|
|
public function addUserLabel()
|
|
{
|
|
$vid = I('post.vid');
|
|
$vip_label_id = I('post.vip_label_id');
|
|
if (!$vid || !$vip_label_id) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
$field = [
|
|
'vid' => $vid,
|
|
'vip_label_id' => $vip_label_id,
|
|
'created_at' => date('Y-m-d H:i:s', time()),
|
|
];
|
|
|
|
if ($this->checkUserLabel($vid, $vip_label_id)) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '用户标签已拥有']);
|
|
}
|
|
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
$anchor_info = $RetailVipWithLabelModel->addOrder($field);
|
|
|
|
if ($anchor_info) {
|
|
$res = ['status' => 1, 'msg' => '添加成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '数据异常,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 批量添加用户标签
|
|
public function addUserLabelArray()
|
|
{
|
|
$vid = I('post.vid');
|
|
$vip_label_id = I('post.vip_label_id');
|
|
if (!$vid || !$vip_label_id) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
// 转数组
|
|
$vip_label_arr = explode(',', $vip_label_id);
|
|
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
foreach ($vip_label_arr as &$value) {
|
|
if ($this->checkUserLabel($vid, $value)) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '用户标签已拥有']);
|
|
}
|
|
|
|
$field = [
|
|
'vid' => $vid,
|
|
'vip_label_id' => $value,
|
|
'created_at' => date('Y-m-d H:i:s', time())
|
|
];
|
|
|
|
$label_arr = $RetailVipWithLabelModel->addOrder($field);
|
|
}
|
|
|
|
if ($label_arr) {
|
|
$res = ['status' => 1, 'msg' => '添加成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '数据异常,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 删除会员的标签
|
|
public function delUserLabel()
|
|
{
|
|
$vid = I('post.vid');
|
|
$vip_label_id = I('post.vip_label_id');
|
|
if (!$vid || !$vip_label_id) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
$where = [
|
|
'vip_label_id' => $vip_label_id,
|
|
'vid' => $vid,
|
|
'is_del' => 1,
|
|
];
|
|
|
|
|
|
$save = [
|
|
'is_del' => 2,
|
|
'deleted_at' => date('Y-m-d H:i:s', time())
|
|
];
|
|
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
$label_info = $RetailVipWithLabelModel->updateOrder($where, $save);
|
|
if ($label_info) {
|
|
$res = ['status' => 1, 'msg' => '操作成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '操作失败,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/* ************************************** 会员标签Start ************************************** */
|
|
|
|
// 添加会员标签
|
|
public function addVipLabel()
|
|
{
|
|
$name = I('post.name');
|
|
if (!isset($name) || $name === '') {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
if ($this->checkNameRepeat($name)) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '标签重复']);
|
|
}
|
|
|
|
|
|
$field = [
|
|
'store_id' => self::$store_id,
|
|
'merchant_id' => self::$merchant_id,
|
|
'name' => $name,
|
|
'created_at' => date('Y-m-d H:i:s', time())
|
|
];
|
|
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$anchor_info = $RetailVipLabelModel->addOrder($field);
|
|
|
|
if ($anchor_info) {
|
|
$res = ['status' => 1, 'msg' => '添加成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '数据异常,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 获取会员标签
|
|
public function getVipLabel()
|
|
{
|
|
$name = I('post.name');
|
|
$page = I('post.page');
|
|
$add_time = I('post.add_time');
|
|
$pageSize = I('post.pageSize');
|
|
|
|
$map['is_del'] = 1;
|
|
$map['merchant_id'] = self::$merchant_id;
|
|
$map['store_id'] = self::$store_id;
|
|
if ($name) {
|
|
$map['name'] = ['like', "%{$name}%"];
|
|
}
|
|
|
|
if (!empty($add_time)) {
|
|
$map['created_at'] = array('between', array($add_time[0], $add_time[1]));
|
|
}
|
|
|
|
$field = [
|
|
'id',
|
|
'name',
|
|
'created_at'
|
|
];
|
|
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
$report['list'] = $RetailVipLabelModel->getSelect($map, $field, 'id desc', $page . ',' . $pageSize);
|
|
$report['total'] = $RetailVipLabelModel->getCount($map);
|
|
if ($report['list']) {
|
|
foreach ($report['list'] as &$value) {
|
|
// 获取该标签会员数
|
|
$value['vip_num'] = $RetailVipWithLabelModel->getCount(['vip_label_id' => $value['id'], 'is_del' => 1]);
|
|
}
|
|
$res = ['status' => 1, 'msg' => '数据获取成功', 'data' => $report];
|
|
} else {
|
|
$res = ['status' => 1, 'msg' => '暂无数据,请稍后重试', 'data' => [
|
|
'list' => [],
|
|
'total' => 0,
|
|
]];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 编辑会员标签
|
|
public function editVipLabel()
|
|
{
|
|
$id = I('post.label_id');
|
|
$name = I('post.name');
|
|
if (!$id) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
if ($this->checkNameRepeat($name)) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '标签重复']);
|
|
}
|
|
|
|
$map = [
|
|
'id' => $id,
|
|
'store_id' => self::$store_id,
|
|
];
|
|
|
|
$save = [
|
|
'name' => $name
|
|
];
|
|
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$result = $RetailVipLabelModel->updateOrder($map, $save);
|
|
if ($result) {
|
|
$res = ['status' => 1, 'msg' => '操作成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '操作失败,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 删除会员标签--软删除
|
|
public function delVipLabel()
|
|
{
|
|
$id = I('post.label_id');
|
|
if (!$id) {
|
|
$this->ajaxReturn(['status' => 0, 'msg' => '必要参数缺失']);
|
|
}
|
|
|
|
$map = [
|
|
'id' => $id,
|
|
'merchant_id' => self::$merchant_id,
|
|
'store_id' => self::$store_id,
|
|
];
|
|
|
|
$save = [
|
|
'is_del' => 2,
|
|
'deleted_at' => date('Y-m-d H:i:s', time())
|
|
];
|
|
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$result = $RetailVipLabelModel->updateOrder($map, $save);
|
|
if ($result) {
|
|
// 同步处理会员-标签
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
$RetailVipWithLabelModel->updateOrder(['vip_label_id' => $id], $save);
|
|
|
|
$res = ['status' => 1, 'msg' => '操作成功'];
|
|
} else {
|
|
$res = ['status' => 0, 'msg' => '操作失败,请稍后重试'];
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 标签是否重复
|
|
public function checkNameRepeat($name)
|
|
{
|
|
$RetailVipLabelModel = new RetailVipLabelModel();
|
|
$nameInfo = $RetailVipLabelModel->getFind(['name' => $name, 'is_del' => 1, 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id]);
|
|
if ($nameInfo) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 用户标签是否重复
|
|
public function checkUserLabel($vid, $label_id)
|
|
{
|
|
$RetailVipWithLabelModel = new RetailVipWithLabelModel();
|
|
$nameMap = [
|
|
'vid' => $vid,
|
|
'is_del' => 1,
|
|
'merchant_id' => self::$merchant_id,
|
|
'vip_label_id' => $label_id,
|
|
];
|
|
$nameInfo = $RetailVipWithLabelModel->getFind($nameMap);
|
|
if ($nameInfo) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|