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

1383 行
65 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Addons\Api\GlobalFunction;
use Addons\Api\ResultCodeManager;
//[1.4.13]
class TurntableController extends BaseController
{
private $merchant_id;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->merchant_id = session('merchant_userinfo')['id'];
}
/**
* 大转盘列表
*/
public function index()
{
$this->display();
}
/**
* 大转盘活动添加
*/
public function add()
{
$this->display();
}
/**
* 大转盘添加历史活动
*/
public function addHistory()
{
$id = I('param.id');
$this->assign('id', $id);
$this->display('addHistory');
}
/**
* 大转盘活动编辑
*/
public function edit()
{
$id = I('param.id');
$this->assign('id', $id);
$this->display('edit');
}
//中奖详情
public function winDetails()
{
$this->display();
}
//中奖记录
public function winList()
{
$this->display();
}
//添加大转盘活动
public function addTurntable()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_name',// '大转盘活动名',
'start_time',// '活动开始时间',
'end_time',// '活动结束时间',
'strategy',// '活动规则',
'explain',// '活动说明',
'status',// '状态:1,可用,2,关闭,3,删除',
'max_num',// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num',// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit',// '是否限制门店 默认0 不限制 1限制',
'turntable_type',// '大转盘类型 1 公众号通知栏 2 小程序商城 3 线上支付 4 线下支付 5 任务',
'shop_id',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit',// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit',// '线下 线上支付转盘消费限制的金额数',
'task_type',// '任务大转盘的任务形式 1每笔消费 2单月累计',
'one_consume',// '每笔消费或单次消费金额',
'one_month_num',// '单月累计消费数',
'prizeArr',// 奖品二维数组
/*
* 奖品二维数组 包含字段
* `prize_name` '奖品名',
`prize_img` '奖品图片',
`prize_num` '奖品数量',
`prize_total` '奖品总量',
prob` '概率',
`type` '奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾',
`grant_type` '奖品发放方式:1商户发放 2门店发放',
`delivery_type` '配送方式:1配送 2自提 3配送或自提',
`receive_auth` '奖品领取时间限制: 1无限制 2限制时间',
`receive_start` '领取开始时间',
`receive_end` '领取截至时间',
* */
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$prizeArr = json_decode($post['prizeArr'], true);
//计算活动奖品总数
if (empty($prizeArr)) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::PARAM_VAL_NOT_EMPTY, ResultCodeManager::$messages[ResultCodeManager::PARAM_VAL_NOT_EMPTY], $post['prizeArr']));
}
$prize_total = 0;
foreach ($prizeArr as $value) {
$prize_total += $value['prize_total'];
}
//逻辑层
switch ($post['turntable_type']) {
case 1: //公众号通知栏
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 1,// '公众号通知栏',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,// '所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->addOrder($add_data);
if ($Turntable) {//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $Turntable,
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 2: //小程序商城
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 2,// '小程序商城',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->addOrder($add_data);
if ($Turntable) {//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $Turntable,
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 3: //线上支付
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 3,// '线上支付',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit' => $post['money_limit'],// '线下 线上支付转盘消费限制的金额数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->addOrder($add_data);
if ($Turntable) {//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $Turntable,
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 4: //线下支付
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 4,// '线下支付',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit' => $post['money_limit'],// '线下 线上支付转盘消费限制的金额数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->addOrder($add_data);
if ($Turntable) {//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $Turntable,
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 5: //任务
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 5,// '任务',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'task_type' => $post['task_type'],// '任务大转盘的任务形式 1每笔消费 2单月累计',
'one_consume' => $post['day_num'],// '每笔消费或单次消费金额',
'one_month_num' => $post['day_num'],// '单月累计消费数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->addOrder($add_data);
if ($Turntable) {//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $Turntable,
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
default:
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::PARAMS_CLASS_ERROR, ResultCodeManager::$messages[ResultCodeManager::PARAMS_CLASS_ERROR], $post['turntable_type']));
}
if (!$Turntable) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR], $Turntable));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
//大转盘活动编辑修改
public function updateTurntable()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_id',// '大转盘活动ID',
'turntable_name',// '大转盘活动名',
'start_time',// '活动开始时间',
'end_time',// '活动结束时间',
'strategy',// '活动规则',
'explain',// '活动说明',
'status',// '状态:1,可用,2,关闭,3,删除',
'max_num',// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num',// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit',// '是否限制门店 默认0 不限制 1限制',
'turntable_type',// '大转盘类型 1 公众号通知栏 2 小程序商城 3 线上支付 4 线下支付 5 任务',
'shop_id',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit',// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit',// '线下 线上支付转盘消费限制的金额数',
'task_type',// '任务大转盘的任务形式 1每笔消费 2单月累计',
'one_consume',// '每笔消费或单次消费金额',
'one_month_num',// '单月累计消费数',
'prizeArr',// 奖品二维数组
/*
* 奖品二维数组 包含字段
* `prize_name` '奖品名',
`prize_img` '奖品图片',
`prize_num` '奖品数量',
`prize_total` '奖品总量',
prob` '概率',
`type` '奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾',
`grant_type` '奖品发放方式:1商户发放 2门店发放',
`delivery_type` '配送方式:1配送 2自提 3配送或自提',
`receive_auth` '奖品领取时间限制: 1无限制 2限制时间',
`receive_start` '领取开始时间',
`receive_end` '领取截至时间',
* */
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
//判断是否已产生中奖记录
$prize_record = M('turntable_use')->where(['turntable_id' => $post['turntable_id']])->find();
if ($prize_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_WIN_RECORD, ResultCodeManager::$messages[ResultCodeManager::HAVE_WIN_RECORD]));
}
$prizeArr = json_decode($post['prizeArr'], true);
//计算活动奖品总数
if (empty($prizeArr)) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::PARAM_VAL_NOT_EMPTY, ResultCodeManager::$messages[ResultCodeManager::PARAM_VAL_NOT_EMPTY], $post['prizeArr']));
}
$prize_total = 0;
foreach ($prizeArr as $value) {
$prize_total += $value['prize_total'];
}
//逻辑层
switch ($post['turntable_type']) {
case 1: //公众号通知栏
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 1,// '公众号通知栏',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,// '所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->updateOrder(['id' => $post['turntable_id']], $add_data);
if ($Turntable) {
//删除之前奖品表数据
$map['turntable_id'] = $post['turntable_id'];
M('turntable_prize')->where($map)->delete();
//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $post['turntable_id'],
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 2: //小程序商城
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 2,// '小程序商城',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->updateOrder(['id' => $post['turntable_id']], $add_data);
if ($Turntable) {
//删除之前奖品表数据
$map['turntable_id'] = $post['turntable_id'];
M('turntable_prize')->where($map)->delete();
//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $post['turntable_id'],
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 3: //线上支付
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 3,// '线上支付',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit' => $post['money_limit'],// '线下 线上支付转盘消费限制的金额数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->updateOrder(['id' => $post['turntable_id']], $add_data);
if ($Turntable) {
//删除之前奖品表数据
$map['turntable_id'] = $post['turntable_id'];
M('turntable_prize')->where($map)->delete();
//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $post['turntable_id'],
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 4: //线下支付
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 4,// '线下支付',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'shop_limit' => $post['shop_limit'],// '是否限制门店 默认0 不限制 1限制',
'shop_id' => $post['shop_limit'] == 1 ? $post['shop_id'] : '',// '参与活动门店ID ‘,’ 拼接 不限门店时为空',
'vip_limit' => $post['vip_limit'],// '是否会员限制 0关闭不限制 1开启 仅选中的会员等级可参与',
'vip_level' => $post['vip_limit'] == 1 ? $post['vip_level'] : '',// '会员限制开启时 所选会员等级ID 多个'',''拼接',
'money_limit' => $post['money_limit'],// '线下 线上支付转盘消费限制的金额数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->updateOrder(['id' => $post['turntable_id']], $add_data);
if ($Turntable) {
//删除之前奖品表数据
$map['turntable_id'] = $post['turntable_id'];
M('turntable_prize')->where($map)->delete();
//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $post['turntable_id'],
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
case 5: //任务
$add_data = [
'turntable_name' => $post['turntable_name'],// '大转盘活动名',
'turntable_type' => 5,// '任务',
'start_time' => $post['start_time'],// '活动开始时间',
'end_time' => $post['end_time'],// '活动结束时间',
'add_time' => time(),// '活动添加时间',
'strategy' => $post['strategy'],// '活动规则',
'explain' => $post['explain'],// '活动说明',
'merchant_id' => $this->merchant_id,//'所属商户ID',
'status' => 2,// '状态:1,可用,2,关闭,3,删除',
'max_num' => $post['max_num'],// '每个用户最多中奖次数:0,不限制。1,1次。。。',
'day_num' => $post['day_num'],// '每人每天最多中奖次数:0为无限制,1,1次。。。',
'task_type' => $post['task_type'],// '任务大转盘的任务形式 1每笔消费 2单月累计',
'one_consume' => $post['one_consume'],// '每笔消费或单次消费金额',
'one_month_num' => $post['one_month_num'],// '单月累计消费数',
'prize_total' => $prize_total,// 活动奖品总数
];
$Turntable = D('Turntable')->updateOrder(['id' => $post['turntable_id']], $add_data);
if ($Turntable) {
//删除之前奖品表数据
$map['turntable_id'] = $post['turntable_id'];
M('turntable_prize')->where($map)->delete();
//添加奖品
foreach ($prizeArr as $val) {
$prize_data = [
'prize_name' => $val['prize_name'],
'prize_img' => $val['prize_img'],
'prize_num' => $val['prize_num'],
'prize_total' => $val['prize_total'],
'prob' => $val['prob'],
'type' => $val['type'],
'grant_type' => $val['grant_type'],
'delivery_type' => $val['delivery_type'],
'receive_auth' => $val['receive_auth'],
'receive_start' => $val['receive_start'],
'receive_end' => $val['receive_end'],
'turntable_id' => $post['turntable_id'],
];
$turntablePrize = D('TurntablePrize')->addOrder($prize_data);
}
}
break;
default:
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::PARAMS_CLASS_ERROR, ResultCodeManager::$messages[ResultCodeManager::PARAMS_CLASS_ERROR], $post['turntable_type']));
}
if (!$Turntable) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR], $Turntable));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
//大转盘活动详情
public function TurntableDetailInfo()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_id',// '大转盘活动ID',
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$turntable = D('Turntable')->getTurntableInfo($post['turntable_id']);
$turntable['shop_list'] = [];
//获取限制的门店
if ($turntable['shop_limit'] == 1) {
$where['id'] = ['in', $turntable['shop_id']];
$shops = M('retail_store')->where($where)->field('id,storetag')->select();
$turntable['shop_list'] = $shops;
}
//获取对应奖品数据
$prize_list = M('turntable_prize')
->where(['turntable_id' => $post['turntable_id']])
->field('id,prize_name,prize_img,prize_num,prob,type,prize_total,grant_type,delivery_type,receive_auth,receive_start,receive_end')
->order('id asc')->select();
$turntable['prize_list'] = $prize_list;
if (!$turntable) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_DATA, ResultCodeManager::$messages[ResultCodeManager::NO_DATA]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $turntable));
}
//大转盘历史活动列表
public function historyTurntableList()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'title',// '大转盘活动名',
'type',// '大转盘类型 1 公众号通知栏 2 小程序商城 3线上支付 线下支付 5任务',
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
$turntableList = D('Turntable')->getMerchantList($this->merchant_id, $post['title'], $post['type'], $page, $page_size);
//获取记录总数
$total = D('Turntable')->getTurntableCount($this->merchant_id, $post['title'], $post['type']);
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
if (!empty($turntableList)) {
foreach ($turntableList as &$val) {
//获取改活动的奖品数量
$prize_num = M('turntable_prize')->field('sum(prize_num)as num')->where(['turntable_id' => $val['id']])->find();
$val['use_num'] = $val['prize_total'] - $prize_num['num'];
$val['surplus_num'] = $prize_num['num'];
}
unset($val);
}
$data = [
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//获取门店列表
public function storeList()
{
$jurisdiction_user = session('merchant_userinfo');//登录的商户信息
$turntableList = M('retail_store')->where(['merchantid' => $jurisdiction_user['merchantid'], 'state' => 0])->field('id,storetag')->select();
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $turntableList));
}
//模糊查询活动列表
public function getTurntableByKey()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'key',// '搜索字段,
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$map['merchant_id'] = $this->merchant_id;
$map['turntable_name'] = ['like', '%' . $post['key'] . '%'];
$map['status'] = array('neq', 3);
$turntableList = M('turntable')->where($map)->field('id,turntable_name')->select();
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $turntableList));
}
//大转盘中奖记录列表
public function winTurntableList()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'title',// '搜索字段,
'turntable_id',// 大转盘活动ID,
'grant_type',// 发放形式,
'grant_status',// 发放状态,
'prize_type',// 奖品类型,
'start_time',// 开始时间,
'end_time',// 结束时间,
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
//查询列表
$turntableList = D('TurntableUse')->getWinList($this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_type'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time'], $page, $page_size);
//获取记录总数
$total = D('TurntableUse')->getWinCount($this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_type'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time']);
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
$data = [
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
/* jsy门店大转盘中奖纪录页面*/
public function winningRecord()
{
$this->display();
}
//门店大转盘中奖记录列表
public function winRecordStoreTurntableList()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'title',// '搜索字段,
'turntable_id',// 大转盘活动ID,
'grant_type',// 发放形式,
'grant_status',// 发放状态,
'prize_type',// 奖品类型,
'start_time',// 开始时间,
'end_time',// 结束时间,
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$store_id = session('storeid');//登录的门店ID
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
//查询列表
$turntableList = D('TurntableUse')->getWinRecordStoreList($store_id, $this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_type'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time'], $page, $page_size);
//获取记录总数
$total = D('TurntableUse')->getWinRecordStoreCount($store_id, $this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_type'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time']);
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
$data = [
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//大转盘中奖记录详情
public function winTurntableDetail()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'title',// 搜索字段,
'turntable_id',// 大转盘活动ID,
'grant_status',// 发放状态,
'prize_type',// 奖品类型,
'start_time',// 开始时间,
'end_time',// 结束时间,
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
//查询列表
$turntableList = D('TurntableUse')->getWinDetail($this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time'], $page, $page_size);
//获取记录总数
$total = D('TurntableUse')->getWinDetailCount($this->merchant_id, $post['title'], $post['turntable_id'], $post['grant_status'], $post['prize_type'], $post['start_time'], $post['end_time']);
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
$data = [
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//大转盘活动列表
public function turntableList()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'title',// 搜索字段,
'status',// 活动状态 1,未开始,2,进行中,3已结束
'turntable_type',// 活动类型 1 公众号通知栏 2 小程序商城 3线上支付 线下支付 5任务,
'start_time',// 开始时间,
'end_time',// 结束时间,
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
//查询列表
$turntableList = D('Turntable')->getTurntableList($this->merchant_id, $post['title'], $post['status'], $post['turntable_type'], $post['start_time'], $post['end_time'], $page, $page_size);
//获取记录总数
$total = D('Turntable')->getTurntableListCount($this->merchant_id, $post['title'], $post['status'], $post['turntable_type'], $post['start_time'], $post['end_time']);
//查询大转盘总开关状态
$sys_status=D('RetailMerchantConfig')->getFind(['merchant_id'=>$this->merchant_id]);
if (!empty($turntableList)) {
foreach ($turntableList as &$val) {
//获取改活动的奖品数量
$prize_num = M('turntable_prize')->field('sum(prize_total)as num')->where(['turntable_id' => $val['id']])->find();
$val['use_num'] = $val['prize_total'] - $prize_num['num'];
$val['surplus_num'] = $prize_num['num'];
}
unset($val);
}
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
$data = [
'turntable_status'=>$sys_status['turntable_status'],
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//大转盘活动列表查看门店
public function turntableShopList()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_id',// 大转盘ID,
'page',// 当前页数
'page_size',// 每页记录数
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$page_size = empty($post['page_size']) ? 10 : $post['page_size'];
//查询列表
$turntable = M('turntable')->where(['id' => $post['turntable_id']])->find();
$w['id'] = ['in', $turntable['shop_id']];
$turntableList = M('retail_store')->where($w)->field('id,storetag')->page($page, $page_size)->select();
//获取记录总数
$total = M('retail_store')->where($w)->field('id,storetag')->count();
$page_info = [
'page' => $page,
'page_size' => $page_size,
'data_total' => $total,
];
$data = [
'data' => $turntableList,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//大转盘活动状态更新
public function turntableStatusUpdate()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_id',// 大转盘ID,
'status',// 活动状态 1,开启,2,关闭
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
//过滤开启时是否存在同类型转盘和红包活动
if ($post['status'] == 1) {
$turntable_info = D('Turntable')->getFind(['id' => $post['turntable_id']]);
switch ($turntable_info['turntable_type']) {
case 1://公众号
//查询红包活动
$mop['type'] = 1;
$mop['start_time'] = ['elt', $turntable_info['end_time']];
$mop['end_time'] = ['egt', $turntable_info['start_time']];
$mop['status'] = 1;
$mop['is_del'] = 0;
$mop['merchant_id'] = $this->merchant_id;
$red_record = D('Reward')->getFind($mop);
if ($red_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
//查询转盘
$map['turntable_type'] = 1;
$map['start_time'] = ['elt', $turntable_info['end_time']];
$map['end_time'] = ['egt', $turntable_info['start_time']];
$map['status'] = 1;
$map['merchant_id'] = $this->merchant_id;
$turntable_record = D('Turntable')->getFind($map);
if ($turntable_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
break;
case 2://小程序商城
//查询红包活动
$mop['type'] = 3;
$mop['start_time'] = ['elt', $turntable_info['end_time']];
$mop['end_time'] = ['egt', $turntable_info['start_time']];
$mop['status'] = 1;
$mop['is_del'] = 0;
$mop['merchant_id'] = $this->merchant_id;
$red_record = D('Reward')->getFind($mop);
if ($red_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
//查询转盘
$map['turntable_type'] = 2;
$map['start_time'] = ['elt', $turntable_info['end_time']];
$map['end_time'] = ['egt', $turntable_info['start_time']];
$map['status'] = 1;
$map['merchant_id'] = $this->merchant_id;
$turntable_record = D('Turntable')->getFind($map);
if ($turntable_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
break;
case 3://线上支付
//查询红包活动
$mop['type'] = 4;
$mop['start_time'] = ['elt', $turntable_info['end_time']];
$mop['end_time'] = ['egt', $turntable_info['start_time']];
$mop['status'] = 1;
$mop['is_del'] = 0;
$mop['merchant_id'] = $this->merchant_id;
$red_record = D('Reward')->getFind($mop);
if ($red_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
//查询转盘
$map['turntable_type'] = 3;
$map['start_time'] = ['elt', $turntable_info['end_time']];
$map['end_time'] = ['egt', $turntable_info['start_time']];
$map['status'] = 1;
$map['merchant_id'] = $this->merchant_id;
$turntable_record = D('Turntable')->getFind($map);
if ($turntable_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
break;
case 4://线下支付
//查询红包活动
$mop['type'] = 2;
$mop['start_time'] = ['elt', $turntable_info['end_time']];
$mop['end_time'] = ['egt', $turntable_info['start_time']];
$mop['status'] = 1;
$mop['is_del'] = 0;
$mop['merchant_id'] = $this->merchant_id;
$red_record = D('Reward')->getFind($mop);
if ($red_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
//查询转盘
$map['turntable_type'] = 4;
$map['start_time'] = ['elt', $turntable_info['end_time']];
$map['end_time'] = ['egt', $turntable_info['start_time']];
$map['status'] = 1;
$map['merchant_id'] = $this->merchant_id;
$turntable_record = D('Turntable')->getFind($map);
if ($turntable_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
break;
case 5:
//查询转盘
$map['turntable_type'] = 5;
$map['start_time'] = ['elt', $turntable_info['end_time']];
$map['end_time'] = ['egt', $turntable_info['start_time']];
$map['status'] = 1;
$map['merchant_id'] = $this->merchant_id;
$turntable_record = D('Turntable')->getFind($map);
if ($turntable_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::HAVE_RED_ACTION, ResultCodeManager::$messages[ResultCodeManager::HAVE_RED_ACTION]));
}
default:
break;
}
}
//查询列表
$turntable = M('turntable')->where(['id' => $post['turntable_id']])->save(['status' => $post['status']]);
if ($turntable) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR], $turntable));
}
//大转盘活动删除
public function turntableStatusDel()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'turntable_id',// 大转盘ID,
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
//查询列表
$turntable = M('turntable')->where(['id' => $post['turntable_id']])->save(['status' => 3]);
if ($turntable) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR], $turntable));
}
//大转盘上传图片
public function turntableUploads()
{
$item = array(
'add_time' => time(),
'from_type_id' => 43,
'localUrl' => 'Merchant/Turntable',
'user_type' => 3,
'merchant_id' => $this->merchant_id,
);
$uploads = uploadFiles($item);//上传图片
$data = [
'uploads' => $uploads,
'key' => I('post.key'),
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//大转盘添加页面获取会员等级
public function turntableGetVip()
{
$vip = D('RetailVipIntegral')->getSelect(['merchantid' => $this->merchant_id], 'id,cardname', '', '');
if (!$vip) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_DATA, ResultCodeManager::$messages[ResultCodeManager::NO_DATA]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $vip));
}
//大转盘添加页面获取门店商品
public function turntableGetGoods()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'store_id',// 门店ID,
'page',// 当前页,
'limit',// 每页记录数,
'keyword',// 商品名 货号 条码,
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
$page = empty($post['page']) ? 1 : $post['page'];
$limit = empty($post['limit']) ? 10 : $post['limit'];
$where = ['merchant_id' => $this->merchant_id, 'store_id' => $post['store_id']];
if (!empty($post['keyword'])) {
$map['goods_name'] = array('like', '%' . $post['keyword'] . '%');
$map['goods_number'] = array('like', '%' . $post['keyword'] . '%');
$map['goods_code'] = array('like', '%' . $post['keyword'] . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$vip = D('RetailGoods')->selectStoreGoods($where, $page, $limit);
$count = D('RetailGoods')->getCount($where);
$page_info = [
'page' => $post['page'],
'limit' => $post['limit'],
'count' => (int)$count,
];
if (!$vip) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_DATA, ResultCodeManager::$messages[ResultCodeManager::NO_DATA]));
}
$data = [
'list' => $vip,
'page_info' => $page_info,
];
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS], $data));
}
//收银机核销自提奖品
public function turntableSelfPrizeCode()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'store_id',// 门店ID,
'code',// 核销码
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
//查询中奖记录
$map = [
'store_id' => $post['store_id'],
'receive_code' => $post['code'],
'status' => 2,
'delivery_status' => 1,
];
$prize_record = D('TurntableUse') - getOrderFind($map);
if (!$prize_record) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::NO_WIN_PRIZE_RECORD, ResultCodeManager::$messages[ResultCodeManager::NO_WIN_PRIZE_RECORD]));
}
//核销中奖记录
$save_data = [
'delivery_status' => 2
];
D('TurntableUse')->updateOrder(['id' => $prize_record['id']], $save_data);
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
//大转盘商户发货
public function sendGoods()
{
$post = I('post.');//接收前端传参 array
//添加发货订单
$add_data = [
'merchant_id' => $this->merchant_id,//'所属商户ID',
'store_id' => 0,// '状态:1,可用,2,关闭,3,删除',
'bill_id' => $post['id'],// '状态:1,可用,2,关闭,3,删除',
'express_no' => $post['express_no'], //varchar(50) DEFAULT NULL COMMENT '物流单号',
'express_name' => $post['express_name'], //varchar(50) DEFAULT NULL COMMENT '物流名称',
'express_code' => $post['express_code'], //varchar(50) DEFAULT NULL COMMENT '快递公司编码',
'order_type' => 2, //tinyint(2) DEFAULT '1' COMMENT '1购买商品订单 其他预留',
'add_time' => time(), //varchar(20) DEFAULT NULL COMMENT '添加时间',
'status' => 1, //tinyint(1) DEFAULT '1' COMMENT '1正常 0取消',
'type' => 2, //tinyint(1) DEFAULT '1' COMMENT '1电子面单 2直接填写单号',
'logistics_id' => 0, //int(11) DEFAULT '0' COMMENT '菜鸟电子面单记录表id',
'operation_type' => 3, //1门店发货 2客户发货(换货退款)
];
$expressOrder = D('ExpressOrder')->addOrder($add_data);
//修改中奖信息的发货状态
$turntableUse = D('TurntableUse')->updateOrder(['id' => $post['id']], ['delivery_status' => 2]);
if ($expressOrder && $turntableUse) {
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR]));
}
//大转盘 状态系统设置
public function turntableStatusInstall()
{
$post = I('post.');//接收前端传参 array
$validParams = [
'status',// 1关闭 2开启,
];//定义过滤字段
$check = GlobalFunction::checkParams($validParams, $post);
if ($check['status'] == 1) {//值为1 过滤出错 前端字段传参不全
$this->ajaxReturn($check['result']);//返回缺失字段
}
//更新数据
$map['merchant_id'] = $this->merchant_id;
$save = [
'turntable_status' => $post['status']
];
$turntable = D('RetailMerchantConfig')->updateOrder($map, $save);
if ($turntable) {
if ($post['status'] == 1) {//关闭总开关时 关闭所有开启中的转盘
$mop['merchant_id'] = $this->merchant_id;
$s_data = [
'status' => 2
];
D('Turntable')->updateOrder($mop, $s_data);
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::SUCCESS, ResultCodeManager::$messages[ResultCodeManager::SUCCESS]));
}
$this->ajaxReturn(GlobalFunction::buildResult(ResultCodeManager::E_SAVE_ERROR, ResultCodeManager::$messages[ResultCodeManager::E_SAVE_ERROR]));
}
}