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

2174 行
87 KiB
PHP
可执行文件

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

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

<?php
namespace Retail\Controller;
use Think\Controller;
//[1.9.20]
/**
* 商户插件管理
* Class PlugController
* @package Retail\Controller
*/
class PlugController extends BaseController
{
public function index()
{
$list = array();
$user = session('ls_userinfo');
$class = M('plug_class')->select();
foreach ($class as $val) {
$map = array(
array(
array(
'p.origin_type' => 2,
'p.is_install' => 1
),
'p.origin_type' => 1,
'_logic' => 'OR',
),
'p.class_id' => $val['id'],
'pm.m_status' => 1,
);
$plug = M('plug as p')
->join('ls_plug_merchant as pm on pm.plug_id=p.id AND pm.merchant_id=' . $user['id'], 'LEFT')
->where($map)
->field('p.*,pm.m_status')
->select();
$temp = array();
$temp['class_id'] = $val['id'];
$temp['class_name'] = $val['class_name'];
$temp['list'] = $plug ? $plug : array();
$list[] = $temp;
unset($temp);
unset($plug);
}
$this->assign('list', $list);
$arr = array(
'Retail/Plug/gift_card' => '/index.php/Retail/Plug/gift_card', //礼品卡
'Retail/Plug/turntable' => '/index.php/Retail/Plug/turntable', //大转盘
// 'Retail/Turntable/index' => '/index.php/Retail/Turntable/index', //新版大转盘
'Retail/Mcoupon/index' => '/index.php/Retail/Mcoupon/index', //优惠券
'Retail/Plug/group' => '/index.php/Retail/Plug/group', //拼团
'Retail/Plug/secKill' => '/index.php/Retail/Plug/secKill', //秒杀
'Retail/Plug/score_mall' => '/index.php/Retail/Plug/score_mall', //积分商城
'Retail/Reward/index' => '/index.php/Retail/Reward/index', //新版红包
'Retail/SubCard/index' => '/index.php/Retail/SubCard/index', //次卡
'Retail/Plug/advance' => '/index.php/Retail/Plug/advance', //预售
'Distribution/BackstageConfig/index' => '/index.php/Distribution/BackstageConfig/index', //分销
'PayCoupon/Index/index' => '/index.php/PayCoupon/Index/index', //微信支付代金券
'ShopCoupon/Index/index' => '/index.php/ShopCoupon/Index/index', //微信商家券
'Make/Index/index' => '/index.php/Make/Index/index', //码科
'Credit/MerchantCredit/index' => '/index.php/Credit/MerchantCredit/index', //赊账
'Blessing/Merchant/index' => '/index.php/Blessing/Merchant/index', //祝福语
'MoralEducationCoin/Merchant/set' => '/index.php/MoralEducationCoin/Merchant/set', //德育币
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/* 红包 */
public function reward()
{
$arr = array(
'editad' => '/index.php/Retail/Plug/editad',
'redSwitch' => '/index.php/Retail/Plug/redSwitch',
'reward_details' => '/index.php/Retail/Plug/reward_details',
'redDelete' => '/index.php/Retail/Plug/redDelete',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function redlist()
{
$user = session('ls_userinfo');
// dump($user);
$map['merchantid'] = $user['id'];
$count = M('reward')->where($map)->count();
$info = M('reward')->where($map)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
foreach ($info as &$val) {
$val['starttime'] = date('Y-m-d', $val['starttime']);
$val['endtime'] = date('Y-m-d', $val['endtime']);
$w['phase'] = $val['phase'];
$hongbaorecord = M('reward_record')->where($w)->count();
$val['hbuse'] = $hongbaorecord;
$val['phase'] = "红包(第" . $val['phase'] . "期)";
if ($val['type'] == 1) {
$val['typename'] = '公众号会员通知栏';
} elseif ($val['type'] == 2) {
$val['typename'] = '会员刷卡支付';
} else {
$val['typename'] = '小程序商城';
}
}
$res['code'] = 0;
$res['count'] = $count;
$res['data'] = $info;
$this->ajaxReturn($res);
}
//添加红包
public function editad()
{
$user = session('ls_userinfo');
$merchantid = $user['id'];
if (IS_POST) {
$money = I('post.money');
$number = I('post.number');
$minmoney = I('post.minmoney');
$maxmoney = I('post.maxmoney');
$starttime = I('post.starttime');
$endtime = I('post.endtime');
if (!is_numeric($money) || !is_numeric($number) || !is_numeric($minmoney) || !is_numeric($maxmoney)) {
$res['status'] = 0;
$res['msg'] = '参数类型不正确,请检查';
$this->ajaxReturn($res);
} else if (empty($money) || empty($number) || empty($minmoney) || empty($maxmoney)) {
$res['status'] = 0;
$res['msg'] = '参数值不完整,请检查';
$this->ajaxReturn($res);
} else if (round($money, 2) != $money || round($money, 2) < 0.01 || round($number) != $number || round($number) < 1 || round($minmoney, 2) != $minmoney || round($minmoney, 2) < 0.01 || round($maxmoney, 2) != $maxmoney || round($maxmoney, 2) < 0.01) {
$res['status'] = 0;
$res['msg'] = '参数值不正确,请检查';
$this->ajaxReturn($res);
}
if ($number > 1000) {
$res['status'] = 0;
$res['msg'] = '红包数量最大上限为1000';
$this->ajaxReturn($res);
}
if ($number == 1) {
if ($minmoney != $maxmoney || $minmoney != $money) {
$res['status'] = 0;
$res['msg'] = '红包数量为1,所有金额设置须相等';
$this->ajaxReturn($res);
}
} else {
if ($minmoney == $maxmoney) {
if ($maxmoney - ($money / $number) < 0 || ($maxmoney - ($money / $number) > 0)) {
$res['status'] = 0;
$res['msg'] = '红包最大最小金额必须等于' . round($money / $number, 2) . '元';
$this->ajaxReturn($res);
}
} else {
if ($minmoney - ($money / $number) >= 0 || $minmoney < 0.01) {
$res['status'] = 0;
$res['msg'] = '红包最小金取值(0.01~' . round($money / $number - 0.01, 2) . ')元';
$this->ajaxReturn($res);
}
$temp = round($money - ($minmoney * $number) + $minmoney, 2);
if ($maxmoney - ($money / $number) <= 0 || $maxmoney > $temp) {
$res['status'] = 0;
$res['msg'] = '红包最大金额取值(' . round($money / $number + 0.01, 2) . '~' . $temp . '元)';
$this->ajaxReturn($res);
}
}
}
if (!$starttime || !$endtime) {
$res['status'] = 0;
$res['msg'] = '请选择正确的时间';
$this->ajaxReturn($res);
}
$needmoney = I('post.needmoney');
$type = I('post.type');
$is_everyday = I('post.is_everyday');
$day_max_time = I('post.day_max_time');
$sum_max_time = I('post.sum_max_time');
if ($type == 2) {
if (empty($needmoney)) {
$res['status'] = 0;
$res['msg'] = '消费金额不正确';
$this->ajaxReturn($res);
}
$Ad['needmoney'] = $needmoney;
}
if ($is_everyday == 1) {
if ($day_max_time != '' && $day_max_time != 0) {
if ($day_max_time > $number) {
$res['status'] = 0;
$res['msg'] = '每日领取次数不能大于' . $number;
$this->ajaxReturn($res);
}
if (round($day_max_time) != $day_max_time || round($day_max_time) < 0) {
$res['status'] = 0;
$res['msg'] = '每日领取次数值有误';
$this->ajaxReturn($res);
}
}
if ($sum_max_time != '' && $sum_max_time != 0) {
if ($sum_max_time > $number) {
$res['status'] = 0;
$res['msg'] = '会员最大领取次数不能大于' . $number;
$this->ajaxReturn($res);
}
if (round($sum_max_time) != $sum_max_time || round($sum_max_time) < 0) {
$res['status'] = 0;
$res['msg'] = '最大领取次数值有误';
$this->ajaxReturn($res);
}
}
if ($day_max_time != '' && $day_max_time != 0 && $sum_max_time != '' && $sum_max_time != 0) {
if ($sum_max_time < $day_max_time) {
$res['status'] = 0;
$res['msg'] = '每日领取次数不能大于最大领取次数';
$this->ajaxReturn($res);
}
} else if ($day_max_time == '' && $day_max_time == 0 && $sum_max_time != '' && $sum_max_time != 0) {
$res['status'] = 0;
$res['msg'] = '限制最大领取次数,每日领取次数必须限制';
$this->ajaxReturn($res);
}
$Ad['day_max_time'] = $day_max_time;
$Ad['sum_max_time'] = $sum_max_time;
}
$arr = $this->rewardRandArray($money, $minmoney, $maxmoney, $number);
$Ad['reward_list'] = implode(',', $arr);
$Ad['money'] = $money;
$Ad['number'] = $number;
$Ad['minmoney'] = $minmoney;
$Ad['maxmoney'] = $maxmoney;
$Ad['type'] = $type;
$Ad['starttime'] = strtotime($starttime);
$Ad['endtime'] = strtotime($endtime);
$Ad['merchantid'] = $merchantid;
$Ad['is_everyday'] = $is_everyday;
$map['merchantid'] = $merchantid;
$map['type'] = $type;
$one = M('reward')->where($map)->order('phase desc')->find(); // 查询是否存在数据。
if ($one) {
$sdata['status'] = 0;
$where['id'] = $one['id'];
M('reward')->where($where)->save($sdata);
$Ad['lessnumber'] = I('post.number');
$Ad['lessmoney'] = I('post.money');
$Ad['status'] = $one['status'];
$Ad['addtime'] = time();
$Ad['phase'] = $one['phase'] + 1; // 开启新的红包数据。
$ret = M('reward')->add($Ad);
//操作日志记录
$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 {
$Ad['lessnumber'] = I('post.number');
$Ad['lessmoney'] = I('post.money');
$Ad['addtime'] = time();
$Ad['phase'] = 1;
$Ad['status'] = 0; // 添加红包时为关闭状态;
$ret = M('reward')->add($Ad);
}
if ($ret !== false) {
$res['status'] = 1;
$res['msg'] = '红包编辑成功';
if ($one) {
if ($one['status'] == 0) {
$res['msg'] = '红包添加成功,当前为关闭状态,开启红包功能请到红包主页';
} else {
$res['msg'] = '红包添加成功,当前为开启转台,修改状态请到红包主页';
}
}
if (!$one) {
$res['msg'] = '红包添加成功,当前为关闭状态,开启请到红包主页';
}
} else {
$res['status'] = 2;
$res['msg'] = '请检查参数';
}
$this->ajaxReturn($res);
}
}
protected function rewardRandArray($money, $min, $max, $number)
{
$money = floatval($money);
$min = floatval($min);
$max = floatval($max);
$number = floatval($number);
$arr = array();
if ($number > 1) {
$array = array_pad($arr, $number, $min);
$lessMoney = round($money - ($min * $number), 2);
$average = round($money / $number, 2);
$max_1 = round($average - $min, 2);
$minMaxAvg = round(round(($min + $max) / 2), 2);
$a = intval($minMaxAvg / $average) / 10;
$a = $a ? $a : 1;
while ($lessMoney > 0) {
$index = rand(0, $number - 1);
if ($lessMoney > $max_1) {
$rate = round($max_1 / $a, 2) > 0.01 ? round($max_1 / $a, 2) : 0.01;
$tempMoney = rand(0, $rate * 100) / 100;
if ($tempMoney <= $lessMoney) {
$allMoney = round($array[$index] + $tempMoney, 2);
if ($allMoney < $max) {
$array[$index] = round($array[$index] + $tempMoney, 2);
$lessMoney = round($lessMoney - $tempMoney, 2);
}
}
} else if ($lessMoney > 0.01) {
$rate = round($lessMoney / $a, 2) > 0.01 ? round($lessMoney / $a, 2) : 0.01;
$tempMoney = rand(0, $rate * 100) / 100;
if ($tempMoney <= $lessMoney) {
$allMoney = round($array[$index] + $tempMoney, 2);
if ($allMoney < $max) {
$array[$index] = round($array[$index] + $tempMoney, 2);
$lessMoney = round($lessMoney - $tempMoney, 2);
}
}
} else {
$allMoney = round($array[$index] + $lessMoney, 2);
if ($allMoney < $max) {
$array[$index] = round($array[$index] + $lessMoney, 2);
$lessMoney = 0;
}
}
}
} else {
$array = array(0 => $money);
}
return $array;
}
//删除红包
public function redDelete()
{
$where['id'] = I('post.id');
$res = M('reward')->where($where)->find();
if ($res) {
if ($res['status'] == 1) {
$data['status'] = 0;
$data['msg'] = '请先关闭红包';
$this->ajaxReturn($data);
}
$rt = M('reward')->where($where)->delete();
if ($rt) {
$data['status'] = 1;
$data['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 {
$data['status'] = 0;
$data['msg'] = '删除失败';
}
}
$this->ajaxReturn($data);
}
//红包开启关闭
public function redSwitch()
{
$user = session('ls_userinfo');
$map['merchantid'] = $user['id'];
if (IS_POST) {
$id = I('post.id');
$status = I('post.status');
if ($status == 1) {
$res = M('reward')->where(array('id' => $id))->save(array('status' => 0));
if ($res) {
$data['status'] = 1;
$data['value'] = 0;
$data['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 {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '关闭失败';
}
} else {
$times = time();
$endtime = M('reward')->where(array('id' => $id))->getField('endtime');
if ($times > $endtime) {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败,活动已过期!';
$this->ajaxReturn($data);
}
$map['status'] = 1;
$map['type'] = M('reward')->where(array('id' => $id))->getField('type');
if ($map['type'] == 2) {
$turntable = M('turntable')->where(array('merchantid' => $map['merchantid'], 'status' => 1, 'turntable_type' => 2))->find();
$info = M('reward')->where($map)->find();
if ($info || $turntable) {
$data['status'] = 0;
$data['value'] = 0;
if ($info) {
$data['msg'] = '开启失败,请先关闭同类型开启的红包!';
} else {
$data['msg'] = '开启失败,请先关闭同类型开启的大转盘!';
}
} else {
$res = M('reward')->where(array('id' => $id))->save(array('status' => 1));
if ($res) {
$data['status'] = 1;
$data['value'] = 1;
$data['msg'] = '开启成功';
} else {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败';
}
}
} else {
$times = time();
$endtime = M('reward')->where(array('id' => $id))->getField('endtime');
if ($times > $endtime) {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败,活动已过期!';
} else {
$map['status'] = 1;
$map['type'] = M('reward')->where(array('id' => $id))->getField('type');
$infos = M('reward')->where($map)->find();
if ($infos) {
$data['msg'] = '开启失败,请先关闭同类型开启的红包!';
} else {
$res = M('reward')->where(array('id' => $id))->save(array('status' => 1));
if ($res) {
$data['status'] = 1;
$data['value'] = 1;
$data['msg'] = '开启成功';
} else {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败';
}
}
}
}
}
$this->ajaxReturn($data);
}
}
//红包领取详情表
public function reward_details()
{
$user = session('ls_userinfo');
$map['merchantid'] = $user['merchantid'];
$map['reward_id'] = I('get.id');
$map['status'] = 1;
$info = M('reward_record')->where($map)->select();
foreach ($info as &$val) {
$val['nickname'] = M('retail_vip')->where(array('id' => $val['vid']))->getField('nickname');
$val['mobile_phone'] = M('retail_vip')->where(array('id' => $val['vid']))->getField('mobile_phone');
$val['storename'] = M('retail_store')->where(array('id' => $val['storeid']))->getField('storetag');
$val['addtime'] = date('Y-m-d', $val['addtime']);
$phas = M('reward')->where(array('id' => $val['reward_id']))->getField('phase');
$val['phase'] = "红包(第" . $phas . "期)";
}
$this->assign('info', $info);
$this->display();
}
//-------------------------------大转盘------------------------------------
//大转盘列表
public function turntable()
{
$arr = array(
'turntable_addtures' => '/index.php/Retail/Plug/turntable_addtures',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
//大转盘首页数据
public function Adventureslist()
{
if (IS_POST) {
$page = I('post.page');
$limit = I('post.limit');
$map['merchantid'] = $this->merchant_id;
$map['status'] = array('in', '1,2');
$counts = M('turntable')->where($map)->count();
$list = M('turntable')->where($map)->order('id desc')->page($page, $limit)->select();
foreach ($list as &$val) {
$w['turntableid'] = $val['id'];
$count = M('turntable_use')->where($w)->count();
$val['usercount'] = $count;
$val['start_time'] = date('Y-m-d', $val['start_time']);
$val['end_time'] = date('Y-m-d', $val['end_time']);
if ($val['turntable_type'] == 1) {
$val['typename'] = '公众号';
} else {
$val['typename'] = '刷卡支付';
}
}
$res['code'] = 0;
$res['count'] = $counts;
$res['data'] = $list;
$this->ajaxReturn($res);
}
}
//切换大转盘状态
public function turnSwitch()
{
if (IS_POST) {
$id = I('post.id');
$map['merchantid'] = $this->merchant_id;
$status = I('post.status');
if ($status == 1) {
$res = M('turntable')->where(array('id' => $id))->save(array('status' => 2));
if ($res) {
$data['status'] = 1;
$data['value'] = 0;
$data['msg'] = '关闭成功';
} else {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '关闭失败';
}
} else {
$times = time();
$endtime = M('turntable')->where(array('id' => $id))->getField('end_time');
if ($times > $endtime) {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败,活动已过期!';
$this->ajaxReturn($data);
}
$map['status'] = 1;
$map['type'] = M('turntable')->where(array('id' => $id))->getField('turntable_type');
$turntable = M('turntable')->where(array('merchantid' => $this->merchant_id, 'status' => 1, 'turntable_type' => $map['type']))->find();
if ($turntable) {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败,请先关闭同类型开启的大转盘!';
$this->ajaxReturn($data);
}
$res = M('turntable')->where(array('id' => $id))->save(array('status' => 1));
if ($res) {
$data['status'] = 1;
$data['value'] = 1;
$data['msg'] = '开启成功';
} else {
$data['status'] = 0;
$data['value'] = 0;
$data['msg'] = '开启失败';
}
}
$this->ajaxReturn($data);
}
}
//添加页面
public function turntable_addtures()
{
$id = I('get.id');
if (!empty($id)) {
$turnTable = M('turntable')->where(array('id' => $id))->find();
$turnTable['date'] = json_encode(array(date('Y-m-d H:i:s', $turnTable['start_time']), date('Y-m-d H:i:s', $turnTable['end_time'])));
$prizeList = M('turntable_prize')->where(array('turntableid' => $turnTable['id']))->select();
foreach ($prizeList as &$value) {
$value['prize_img'] = $value['prizeimg'];
}
} else {
$turnTable = array(
'turntable_type' => '',
'turntable_name' => '',
'explain' => '',
'date' => '',
'strategy' => '',
'isshownum' => '',
'needmoney' => '',
'maxnum' => '',
'daymaxnum' => '',
'playnum' => '',
'copyright' => '',
'prizecode' => '',
'btn_word' => '',
'link' => '',
);
$prizeList = array(
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
array('type' => '', 'prize_name' => '', 'prizenum' => '', 'prob' => '', 'prize_img' => '', 'prizemsg' => '', 'integral' => '', 'money' => ''),
);
}
$this->assign('turnTable', $turnTable);
$this->assign('prizeList', json_encode($prizeList));
$this->display();
}
//添加、编辑大转盘
public function turntable_editad()
{
$post = I('post.');
$file = $_FILES;
if (empty($post)) {
$result['status'] = 0;
$result['msg'] = '缺少参数';
$this->ajaxReturn($result);
}
$user = session('ls_userinfo');
$merchant_id = $user['merchantid'];
$time = time();
$data = explode(',', $post['date']);
$item = array(
'merchantid' => $merchant_id,
'turntable_name' => $post['turntable_name'],
'link' => $post['link'],
'prizecode' => $post['prizecode'],
'address' => $post['address'] ? 2 : 1,
'write' => $post['write'] ? $post['write'] : 0,
'company' => $post['company'] ? $post['company'] : 1,
'copyright' => $post['copyright'],
'start_time' => strtotime($data[0]),
'end_time' => strtotime($data[1]),
'strategy' => $post['strategy'],
'explain' => $post['explain'],
'prizeidlist' => '',
'needmoney' => $post['needmoney'],
'btn_word' => $post['btn_word'],
);
if (empty($post['id'])) {
$item['status'] = 2;
if (!in_array($post['turntable_type'], array('1', '2'))) {
$result['status'] = 0;
$result['msg'] = '请选择活动类型';
$this->ajaxReturn($result);
}
$item['turntable_type'] = $post['turntable_type'];
}
if (empty($post['turntable_name'])) {
$result['status'] = 0;
$result['msg'] = '请输入活动名称';
$this->ajaxReturn($result);
}
if (empty($post['explain'])) {
$result['status'] = 0;
$result['msg'] = '请输入活动说明';
$this->ajaxReturn($result);
}
if (empty($post['date'])) {
$result['status'] = 0;
$result['msg'] = '请选择活动有效时间';
$this->ajaxReturn($result);
}
if (empty($post['strategy'])) {
$result['status'] = 0;
$result['msg'] = '请输入活动规则';
$this->ajaxReturn($result);
}
if ($post['turntable_type'] == 2 && !verifyPrice($post['needmoney'])) {
$result['status'] = 0;
$result['msg'] = '请设置正确的消费门槛金额';
$this->ajaxReturn($result);
}
if (empty($post['id'])) {
if (!in_array($post['isshownum'], array('1', '2'))) {
$result['status'] = 0;
$result['msg'] = '请选择是否显示奖品数量';
$this->ajaxReturn($result);
}
$item['isshownum'] = $post['isshownum'];
$item['addtime'] = $time;
if (!verifyNumber($post['maxnum'], 0, 0)) {
$result['status'] = 0;
$result['msg'] = '请输入每人最多获奖次数';
$this->ajaxReturn($result);
}
$item['maxnum'] = $post['maxnum'];
if (!verifyNumber($post['daymaxnum'], 0, 0)) {
$result['status'] = 0;
$result['msg'] = '请输入正确的每人每天最多获奖次数';
$this->ajaxReturn($result);
}
$item['daymaxnum'] = $post['daymaxnum'];
if (!verifyNumber($post['playnum'], 0, 0)) {
$result['status'] = 0;
$result['msg'] = '请输入正确的每人每天最多抽奖次数';
$this->ajaxReturn($result);
}
$item['playnum'] = $post['playnum'];
$prizeList = htmlspecialchars_decode($post['prizeList']);
$prizeList = json_decode($prizeList, true);
if (empty($prizeList)) {
$result['status'] = 0;
$result['msg'] = '缺少奖品参数';
$this->ajaxReturn($result);
}
if (!is_array($prizeList)) {
$result['status'] = 0;
$result['msg'] = '奖品数据有误';
$this->ajaxReturn($result);
}
$prob = 0;
$flag = false;
foreach ($prizeList as $key => $val) {
if (!in_array($val['type'], array('1', '2', '3', '5'))) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '类型未选择';
$this->ajaxReturn($result);
}
switch ($val['type']) {
case '1':
if (!$val['prize_img_id'] && (!$file['prize_img_' . $key] || $file['prize_img_' . $key]['error'])) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '图片未选择';
$this->ajaxReturn($result);
}
$flag = true;
break;
case '2':
if (!$val['integral']) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '积分数量未填写';
$this->ajaxReturn($result);
}
break;
case '3':
if (!$val['money']) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '金额未填写';
$this->ajaxReturn($result);
}
break;
}
if (!$val['prize_name']) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '名称未填写';
$this->ajaxReturn($result);
} else if (!$val['prizenum']) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '数量未填写';
$this->ajaxReturn($result);
} else if (!$val['prob']) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '中奖概率未填写';
$this->ajaxReturn($result);
} else if ($val['prob'] != round($val['prob']) || floatval($val['prob']) <= 0 || floatval($val['prob']) > 93) {
$result['status'] = 0;
$result['msg'] = '奖品' . ($key + 1) . '中奖概率设置有误';
$this->ajaxReturn($result);
}
$prob += $val['prob'];
}
$prob = round($prob);
if ($prob != 100) {
$result['status'] = 0;
$result['msg'] = '奖品的中奖概率之和应为 1';
$this->ajaxReturn($result);
}
if (empty($post['prizecode']) && $flag) {
$result['status'] = 0;
$result['msg'] = '奖品中有实物,请设置奖品兑换码';
$this->ajaxReturn($result);
}
$item['turntable_img'] = '/Public/turntable/images/z_bj.png';
$item['turntable_innerimg'] = '/Public/turntable/images/z_zp.png';
$item['turntable_turntableimg'] = '/Public/turntable/images/z_nq.png';
$item['turntable_bgimg'] = '/Public/turntable/images/z_bj.png';
$add_turntable = M('turntable')->add($item);
if ($add_turntable) {
$item = array(
'add_time' => time(),
'from_type_id' => 43,
'localUrl' => 'Merchant/Plug/turntable_prize',
'user_type' => 3,
'merchant_id' => $user['merchantid'],
);
$uploads = uploadFiles($item);
$result['upload'] = $uploads;
$prize_add = array();
foreach ($prizeList as $k => $value) {
$temp = $value;
unset($temp['img']);
$temp['turntableid'] = $add_turntable;
if (!empty($uploads['prize_img_' . $k]['id'])) {
$item['prize_img_id'] = $uploads['prize_img_' . $k]['id'];
$temp['prizeimg'] = $uploads['prize_img_' . $k]['path'];
} else {
$temp['prizeimg'] = $temp['prize_img'];
}
switch ($temp['type']) {
case '2':
$temp['prizeimg'] = '/Public/user/turntable/images/Z_jf.png';
break;
case '3':
$temp['prizeimg'] = '/Public/user/turntable/images/Z_ye.png';
break;
case '4':
$temp['prizeimg'] = '/Public/user/turntable/images/Z_kq.png';
break;
case '5':
$temp['prizeimg'] = '/Public/user/turntable/images/Z_6.png';
break;
}
$add = M('turntable_prize')->add($temp);
if ($add) {
$prize_add[] = $add;
}
}
if (count($prize_add) == 8) {
$result['status'] = 1;
$result['msg'] = '添加成功';
} else {
M('turntable_prize')->where(array('id' => array('in', $prize_add)))->delete();
M('turntable')->where(array('id' => $add_turntable))->delete();
$result['status'] = 0;
$result['msg'] = '数据库发生错误,请重试';
}
}
} else {
$add_turntable = M('turntable')->where(array('id' => $post['id']))->save($item);
}
if ($add_turntable) {
$result['status'] = 1;
$result['msg'] = '编辑成功';
} else {
$result['status'] = 0;
$result['msg'] = '操作失败';
}
$this->ajaxReturn($result);
}
//查看大转盘中奖信息
public function turntable_details()
{
if (IS_POST) {
$page = I('post.page');
$limit = I('post.limit');
$map['u.merchantid'] = $this->merchant_id;
$map['u.turntableid'] = I('post.id');
$info = M('turntable_use as u')
->join('ls_turntable as t on t.id=u.turntableid')
->join('ls_retail_vip as v on v.id=u.vid')
->join('ls_turntable_prize as p on p.id=u.turntable_prizeid')
->where($map)->order('id desc')
->field('u.*,v.nickname,v.name,v.mobile_phone,p.prize_name,t.turntable_name')
->page($page, $limit)->select();
$count = M('turntable_use as u')
->join('ls_turntable as t on t.id=u.turntableid')
->join('ls_retail_vip as v on v.id=u.vid')
->join('ls_turntable_prize as p on p.id=u.turntable_prizeid')
->where($map)->count();
foreach ($info as &$val) {
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
if ($val['status'] == 1) {
$val['status'] = '待领取';
} else {
$val['status'] = '已领取';
}
}
$this->ajaxReturn([
'code' => 0,
'msg' => '获取成功',
'data' => $info,
'count' => $count,
]);
} else {
$this->assign('id', I('get.id'));
$this->display();
}
}
//删除大转盘
public function turntabledel()
{
$where['id'] = I('post.id');
$res = M('turntable')->where($where)->find();
if ($res) {
if ($res['status'] == 1) {
$data['status'] = 0;
$data['msg'] = '请先关闭大转盘';
$this->ajaxReturn($data);
}
$rt = M('turntable')->where($where)->save(array('status' => 3));
if ($rt) {
$data['status'] = 1;
$data['msg'] = '删除成功';
} else {
$data['status'] = 0;
$data['msg'] = '删除失败';
}
}
$this->ajaxReturn($data);
}
//-------------------------------积分商城------------------------------------
public function score_mall()
{
$arr = array(
'score_add' => '/index.php/Retail/Plug/score_add',
'score_exchange' => '/index.php/Retail/Plug/score_exchange',
'score_banner' => '/index.php/Retail/Plug/score_banner',
'score_upstatus' => '/index.php/Retail/Plug/score_upstatus',
'score_dels' => '/index.php/Retail/Plug/score_dels',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function score_add()
{
$id = I('get.id');
if (!empty($id)) {
$list = M("retail_scoremall")->where(array('id' => $id))->find();
if ($list) {
$list['information'] = str_replace("<br/>", "\n", $list['information']);
$list['notice'] = str_replace("<br/>", "\n", $list['notice']);
$type = (int)$list['type'];
if (!empty($list['image_id'])) {
$list['image'] = D('ImageGallery')->getOneField(array('id' => $list['image_id']), 'path');
}
} else {
$this->error2();
}
} else {
$list = array();
}
$type = $type ? $type : 1;
$this->assign('list', $list);
$this->assign('type', $type);
$this->display();
}
public function score_mall_set()
{
$user = session('ls_userinfo');
if (!empty($user) && IS_POST) {
$id = I('post.id');
$image_id = I('post.image_id');
if (empty($image_id) && (empty($_FILES) || $_FILES['image']['error'] != 0) && !$id) {
$res['status'] = 0;
$res['msg'] = "请上传图片";
$this->ajaxReturn($res);
}
if ($_FILES['image']['error'] === 0) {
$item = array(
'add_time' => time(),
'from_type_id' => 25,
'localUrl' => 'Merchant/ScoreMall',
'user_type' => 3,
'merchant_id' => $user['id']
);
$uploads = uploadFiles($item);
if (!empty($uploads['image']['savePath'])) {
$image_id = $uploads['image']['id'];
$data['image'] = $uploads['image']['path'];
} else {
$res['status'] = 0;
$res['msg'] = "图片上传失败";
$this->ajaxReturn($res);
}
} else {
$data['image'] = D('ImageGallery')->getOneField(array('id' => $image_id), 'path');
}
$data['merchantid'] = $user['id'];
$data['name'] = I('post.name');
$data['integral'] = I('post.integral');
$data['price'] = I('post.price');
$data['type'] = I('post.modifyType');
$data['num'] = I('post.num');
$data['time'] = time();
$data['image_id'] = $image_id ? $image_id : 0;
$detail = I('post.information');
$detail = str_replace("\n", "<br/>", $detail);
$data['information'] = $detail;
$notice = I('post.notice');
$notice = str_replace("\n", "<br/>", $notice);
$data['notice'] = $notice;
if ($id) {
$list = M("retail_scoremall")->where(array('id' => $id))->save($data);
} else {
$list = M("retail_scoremall")->add($data);
}
if ($list > 0) {
$res['status'] = 1;
$res['msg'] = $id ? "保存成功" : "添加成功";
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-积分商城' . $msg;//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = $id ? "保存失败" : "添加失败";
}
}
$this->ajaxReturn($res);
}
public function score_upstatus()
{
$id = I('post.id');
$sta['status'] = I('post.status');
$state = M('retail_scoremall')->where(array('id' => $id))->save($sta);
if ($state) {
$res['status'] = 1;
//操作日志记录
if ($sta['status'] == 1) {
$msg = '上架';
} else {
$msg = '下架';
}
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-积分商城商品' . $msg;//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
}
$this->ajaxReturn($res);
}
public function score_dels()
{
$id = i('post.id');
$del = M('retail_scoremall')->where(array('id' => $id))->delete();
if ($del) {
$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 score_getData()
{
$user = session("ls_userinfo");
$news['merchantid'] = $user['id'];
$list = M("retail_scoremall")->where($news)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
$count = M("retail_scoremall")->where($news)->count();
$ImageGalleryModel = D('ImageGallery');
foreach ($list as $key => &$v) {
$v['time'] = date('Y-m-d H:i:s', $v['time']);
$v['information'] = str_replace("<br/>", "\n", $v['information']);
$v['notice'] = str_replace("<br/>", "\n", $v['notice']);
$v['index'] = $key + 1;
$v['image'] = $ImageGalleryModel->getFieldPath(array('id' => $v['image_id']));
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
public function score_exchange()
{
$arr = array(
'score_receive' => '/index.php/Retail/Plug/score_receive',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
//获取兑换记录表单数据
public function score_exchangeData()
{
$user = session("ls_userinfo");
$pid = $user['id'];
$list = M("retail_score_mall_exchange as a")
->join("ls_retail_scoremall as b on a.shopid = b.id")
->join("ls_retail_vip as v on a.vid = v.id")
->where(array('a.merchantid' => $pid, 'a.state' => 1))
->field("a.id,a.status,a.barcode,a.time,b.name,b.image_id,b.type,v.nickname")
->page($_POST['page'], $_POST['limit'])
->order('a.time desc')
->select();
$count = M("retail_score_mall_exchange as a")
->join("ls_retail_scoremall as b on a.shopid = b.id")
->join("ls_retail_vip as v on a.vid = v.id")
->where(array('a.merchantid' => $pid, 'a.state' => 1))
->count();
$ImageGalleryModel = D('ImageGallery');
foreach ($list as &$v) {
$v['time'] = date('Y-m-d H:i:s', $v['time']);
if ($v['type'] == 1) {
$v['type'] = "积分";
} elseif ($v['type'] == 2) {
$v['type'] = "积分+会员卡";
} else {
$v['type'] = "积分+微信";
}
$v['image'] = $ImageGalleryModel->getFieldPath(array('id' => $v['image_id']));
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//领取商品
public function score_receive()
{
$id = $_GET['id'];
$this->assign('id', $id);
$this->display();
}
//执行领取商品
public function score_exgoods()
{
$data['id'] = I('post.id');
$code = I('post.barcode');
$list = M("retail_score_mall_exchange")->where($data)->find();
if ($list['barcode'] == $code) {
$list = M("retail_score_mall_exchange")->where(array('id' => $data['id'], 'barcode' => $code))->save(array('status' => 2));
if ($list) {
$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 score_banner()
{
$arr = array(
'score_banner_add' => '/index.php/Retail/Plug/score_banner_add',
'score_status' => '/index.php/Retail/Plug/score_status',
'score_delimg' => '/index.php/Retail/Plug/score_delimg',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function score_banner_add()
{
// dump($_SESSION);
$this->display();
}
/**
* 获取banner表单数据
*/
public function bannerData()
{
$user = session('ls_userinfo');
$news['pid'] = $user['id'];
$list = M("retail_score_tempbanner")->where($news)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
foreach ($list as $key => &$value) {
if (!empty($value['image_id'])) {
$value['image'] = D('ImageGallery')->getOneField(array('id' => $value['image_id']), 'path');
}
$value['index'] = $key + 1;
}
$count = M("retail_score_tempbanner")->where($news)->count();
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 修改状态
public function score_status()
{
$data['status'] = I('post.status');
$id = I('post.id');
$state = M("retail_score_tempbanner")->where('id=' . $id)->save($data);
if ($state) {
$res['status'] = 1;
$res['msg'] = "修改成功";
if ($data['status'] == 1) {
$msg = '开启';
} else {
$msg = '关闭';
}
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-积分商城banner图' . $msg;//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = "修改失败";
}
$this->ajaxReturn($res);
}
// 添加banner图片
public function score_addimg()
{
$user = session('ls_userinfo');
if (!empty($user) && IS_POST) {
$image_id = I('post.image_id');
if (empty($image_id) && (empty($_FILES) || $_FILES['image']['error'] != 0)) {
$res['status'] = 0;
$res['msg'] = "请上传图片";
$this->ajaxReturn($res);
}
if ($_FILES['image']['error'] === 0) {
$item = array(
'add_time' => time(),
'from_type_id' => 25,
'localUrl' => 'Merchant/ScoreMall',
'user_type' => 3,
'merchant_id' => $user['id']
);
$uploads = uploadFiles($item);
if (!empty($uploads['image']['savePath'])) {
$image_id = $uploads['image']['id'];
$data['image'] = $uploads['image']['path'];
} else {
$res['status'] = 0;
$res['msg'] = "图片上传失败";
$this->ajaxReturn($res);
}
} else {
$data['image'] = D('ImageGallery')->getOneField(array('id' => $image_id), 'path');
}
$data['image_id'] = $image_id ? $image_id : 0;
$data['pid'] = $user['id'];
$data['time'] = time();
$list = M("retail_score_tempbanner")->add($data);
if ($list > 0) {
$res['status'] = 1;
$res['msg'] = "添加成功";
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-积分商城新增banner图';//操作行为描述
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 score_delimg()
{
$id = I('post.id');
$list = M("retail_score_tempbanner")->where('id =' . $id)->delete();
if ($list) {
$res['status'] = 1;
$res['msg'] = "删除成功";
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-积分商城删除banner图';//操作行为描述
action_log($source, $type, $request_data, $desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = "删除失败";
}
$this->ajaxReturn($res);
}
/*
* -------------------------------------礼品卡-------------------------
* */
public function gift_card()
{
$arr = array(
'gift_addcard' => '/index.php/Retail/Plug/gift_addcard', //添加礼品卡
'gift_propaganda' => '/index.php/Retail/Plug/gift_propaganda', //礼品卡首页展示设置
'gift_status' => '/index.php/Retail/Plug/gift_status', //修改礼品卡状态
'gift_editGift' => '/index.php/Retail/Plug/gift_editGift', //编辑礼品卡
'gift_dels' => '/index.php/Retail/Plug/gift_dels', //删除礼品卡
'gift_detail' => '/index.php/Retail/Plug/gift_detail', //礼品卡详情
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function gift_addcard()
{
$this->display();
}
/**
* 获取礼品卡首页表单数据
*/
public function gift_Data()
{
$user = session('ls_userinfo');
$news['merchantid'] = $user['id'];
$news['state'] = 1;
$list = M("gift_card")->where($news)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
$count = M("gift_card")->where($news)->count();
foreach ($list as $key => &$v) {
$v['index'] = round(($_POST['page'] - 1) * $_POST['limit'] + ($key + 1));
$v['notes'] = str_replace("<br/>", "\n", $v['notes']);
$v['time'] = date('Y-m-d', $v['start_time']) . ' -- ' . date('Y-m-d', $v['end_time']);
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 添加礼品卡
public function gift_add()
{
$data['merchantid'] = session('ls_userinfo')['id'];
$data['title'] = I('post.title');
$data['start_time'] = strtotime(I('post.start_time'));
$data['end_time'] = strtotime(I('post.end_time') . '23:59:59');
$data['notes'] = I('post.notes');
$data['notes'] = str_replace("\n", "<br/>", $data['notes']);
$data['addtime'] = time();
$data['status'] = 0;
$data['state'] = 1;
$list = M("gift_card")->add($data);
if ($list) {
$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 gift_status()
{
$status = I('post.status');
$id = I('post.id');
if ($status == 1) {
$gift = M('gift_card as g')
->join('ls_gift_card_price as p on p.gift_cardid=g.id AND p.status=1')
->join('ls_gift_card_cover as c on c.gift_cardid=g.id AND c.status=1')
->where(array('g.id' => $id))
->select();
if (empty($gift)) {
$res['status'] = 0;
$res['msg'] = "请先设置封面图和金额";
$this->ajaxReturn($res);
}
}
$data['status'] = $status;
$state = M("gift_card")->where('id=' . $id)->save($data);
if ($state) {
$res['value'] = $status;
$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['value'] = $status == 1 ? 0 : 1;
$res['status'] = 0;
$res['msg'] = "修改失败";
}
$this->ajaxReturn($res);
}
//删除礼品卡,只是软删除,并没有真的删除数据
public function gift_dels()
{
$id = I('post.id');
$list = M("gift_card")->where('id =' . $id)->save(array('state' => 0));
if ($list) {
$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 gift_detail()
{
$giftid = I('get.giftid');
$this->assign('giftid', $giftid);
$arr = array(
'gift_addcover' => '/index.php/Retail/Plug/gift_addcover',
'gift_card_upcover' => '/index.php/Retail/Plug/gift_card_upcover',
'gift_card_delcover' => '/index.php/Retail/Plug/gift_card_delcover',
'gift_addprice' => '/index.php/Retail/Plug/gift_addprice',
'gift_card_updateprice' => '/index.php/Retail/Plug/gift_card_updateprice',
'gift_card_delprice' => '/index.php/Retail/Plug/gift_card_delprice',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
//----------------------------------加载gift_price 礼品卡金额---------------------------------
//加载 gift_price 礼品卡添加页面
public function gift_addprice()
{
$id = I('get.giftid');
$this->assign("giftid", $id);
$this->display();
}
//礼品卡金额添加
public function gift_price_add()
{
$data['money'] = I('post.money');
$data['price'] = I('post.price');
$data['gift_cardid'] = I('post.gift_cardid');
$data['num'] = I('post.num');
$data['less_num'] = $data['num'];
$data['status'] = 0;
$data['state'] = 1;
$data['merchantid'] = session('ls_userinfo')['id'];
$list = m("gift_card_price")->add($data);
if ($list) {
$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 gift_card_updateprice()
{
$status = I('post.status');
$data['status'] = $status;
$id = I('post.id');
$state = M("gift_card_price")->where('id=' . $id)->save($data);
if ($state) {
$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 gift_price_Data()
{
$user = session('ls_userinfo');
$news['merchantid'] = $user['id'];
$news['gift_cardid'] = I('post.giftid');
$news['state'] = 1;
$list = M("gift_card_price")->where($news)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
$count = M("gift_card_price")->where($news)->count();
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//删除金额
public function gift_card_delprice()
{
$id = I('post.id');
$list = M("gift_card_price")->where('id =' . $id)->save(array('state' => 0));
if ($list) {
$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 gift_addcover()
{
$id = I('get.giftid');
$this->assign("giftid", $id);
$this->display();
}
//添加封面图
public function gift_add_img()
{
$user = session('ls_userinfo');
if (!empty($user) && IS_POST) {
$img_url_id = I('post.img_url_id');
if (empty($img_url_id)) {
$res['status'] = 0;
$res['msg'] = "请选择图片";
$this->ajaxReturn($res);
}
$data['img_url'] = D('ImageGallery')->getOneField(array('id' => $img_url_id), 'path');
$data['img_url_id'] = $img_url_id ? $img_url_id : 0;
$data['gift_cardid'] = I('post.gift_cardid');
$data['addtime'] = time();
$data['status'] = 0;
$data['state'] = 1;
$data['merchantid'] = $user['id'];
$list = M("gift_card_cover")->add($data);
if ($list) {
$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 gift_card_upcover()
{
$status = I('post.status');
$data['status'] = $status;
$id = I('post.id');
$state = M("gift_card_cover")->where('id=' . $id)->save($data);
if ($state) {
$res['status'] = 1;
$res['msg'] = "修改成功";
} else {
$res['status'] = 0;
$res['msg'] = "修改失败";
}
$this->ajaxReturn($res);
}
//删除封面图
public function gift_card_delcover()
{
$id = I('post.id');
$list = M("gift_card_cover")->where('id =' . $id)->save(array('state' => 0));
if ($list) {
$res['status'] = 1;
$res['msg'] = "删除成功";
} else {
$res['status'] = 0;
$res['msg'] = "删除失败";
}
$this->ajaxReturn($res);
}
/**
* 获取金额表单数据
*/
public function gift_cover_Date()
{
$user = session('ls_userinfo');
$news['merchantid'] = $user['id'];
$news['gift_cardid'] = I('post.giftid');
$news['state'] = 1;
$list = M("gift_card_cover")->where($news)->page($_POST['page'], $_POST['limit'])->order('id desc')->select();
$count = M("gift_card_cover")->where($news)->count();
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//----------------------------------------加载展示图页面----------------------------------------
public function gift_propaganda()
{
$arr = array(
'gift_addpropaganda' => '/index.php/Retail/Plug/gift_addpropaganda', //添加展示图
'gift_prostu' => '/index.php/Retail/Plug/gift_prostu', //修改展示图状态
'gift_editTile' => '/index.php/Retail/Plug/gift_editTile', //编辑展示图标题
'gift_prodel' => '/index.php/Retail/Plug/gift_prodel', //删除展示图
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
//宣传图添加页面
public function gift_addpropaganda()
{
$this->display();
}
/**
* 获取礼品卡展示图表单数据
*/
public function gift_pro_Data()
{
$user = session('ls_userinfo');
$news['merchantid'] = $user['id'];
$list = M("gift_card_propaganda")->where($news)->page($_POST['page'], $_POST['limit'])->select();
$count = M("gift_card_propaganda")->where($news)->count();
foreach ($list as &$v) {
$v['addtime'] = date('Y-m-d', $v['addtime']);
if (!empty($v['imgurl_id'])) {
$v['imgurl'] = D('ImageGallery')->getOneField(array('id' => $v['imgurl_id']), 'path');
}
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $list;
$res['count'] = $count;
$this->ajaxReturn($res);
}
//添加礼品卡宣传图
public function gift_addpro()
{
$user = session('ls_userinfo');
if (!empty($user)) {
$imgurl_id = I('post.imgurl_id');
if (empty($imgurl_id) && (empty($_FILES) || $_FILES['imgurl']['error'] != 0)) {
$res['status'] = 0;
$res['msg'] = "请上传图片";
$this->ajaxReturn($res);
}
if ($_FILES['imgurl']['error'] === 0) {
$item = array(
'add_time' => time(),
'from_type_id' => 24,
'localUrl' => 'Merchant/Gift',
'user_type' => 3,
'merchant_id' => $user['id']
);
$uploads = uploadFiles($item);
if (!empty($uploads['imgurl']['savePath'])) {
$imgurl_id = $uploads['imgurl']['id'];
$data['imgurl'] = $uploads['imgurl']['path'];
} else {
$res['status'] = 0;
$res['msg'] = "图片上传失败";
$this->ajaxReturn($res);
}
} else {
$data['imgurl'] = D('ImageGallery')->getOneField(array('id' => $imgurl_id), 'path');
}
$data['imgurl_id'] = $imgurl_id ? $imgurl_id : 0;
$data['addtime'] = time();
$data['status'] = 2;
$data['merchantid'] = $user['id'];
$data['title'] = I('post.title');
$list = M("gift_card_propaganda")->add($data);
if ($list) {
$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 gift_prostu()
{
$user = session('ls_userinfo');
$status = I('post.status');
$data['status'] = $status;
$id = I('post.id');
if ($status == 1) {
$update = M('gift_card_propaganda')->where(array('merchantid' => $user['id'], 'status' => 1))->save(array('status' => 2));
}
$state = M("gift_card_propaganda")->where('id=' . $id)->save($data);
if ($state) {
$res['status'] = 1;
$res['msg'] = "修改成功";
$res['value'] = $status == 1 ? 1 : 2;
//操作日志记录
$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 gift_editTile()
{
$id = I('post.id');
$title = I('post.title');
$update = M("gift_card_propaganda")->where('id =' . $id)->save(array('title' => $title));
if ($update) {
$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 gift_editGift()
{
$id = I('post.id');
$title = I('post.title');
$notes = I('post.notes');
$notes = str_replace("\n", "<br/>", $notes);
$update = M("gift_card")->where('id =' . $id)->save(array('title' => $title, 'notes' => $notes));
if ($update) {
$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 gift_prodel()
{
$id = I('post.id');
$list = M("gift_card_propaganda")->where('id =' . $id)->delete();
if ($list) {
$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 group()
{
$arr = array(
'groupState' => '/index.php/Retail/Plug/groupState',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
// 获取门店数据
public function getStoreList()
{
$User = session('ls_userinfo');
$where['merchantid'] = $User['merchantid'];
$where['store_status'] = 0;
$where['state'] = 0;
$superinfo = M('retail_store')->where($where)->page((int)$_POST['page'], (int)$_POST['limit'])->order('id asc')->select();
$count = M('retail_store')->where($where)->count();
if ($superinfo) {
$plug = M('plug')->where(array('plug_name' => '拼团', 'status' => 1))->find();
if (empty($plug)) {
$this->error("您无权进行此操作");
} else {
$plug_id = $plug['id'];
}
$index = 1;
foreach ($superinfo as $key => &$val) {
$store_plug = M('plug_store')->where(array('plug_id' => $plug_id, 'storeid' => $val['id']))->find();
$val['s_status'] = empty($store_plug) ? 0 : $store_plug['s_status'];
$val['index'] = $index++;
if ($val['store_type'] == 0) {
$val['store_type'] = "主店";
} else {
$val['store_type'] = "分店";
}
$manager = M('retail_manager')->where(array('storeid' => $val['id'], 'status' => 1))->find();
$val['shop_manager'] = $manager ? $manager['name'] : '未设置';
$val['tel'] = $manager ? $manager['mobile'] : '未设置';
$val['plug_id'] = $plug_id;
}
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $superinfo;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 修改拼团插件状态
public function groupState()
{
if (IS_POST) {
$id = I('post.id');
$plug_id = I('post.plug_id');
$s_status = I('post.s_status');
if (!empty($id) && !empty($plug_id) && $s_status != '') {
$find_store = M('plug_store')->where(array('storeid' => $id, 'plug_id' => $plug_id))->find();
if (empty($find_store)) { // 添加
$map['storeid'] = $id;
$map['plug_id'] = $plug_id;
$map['addtime'] = time();
$map['opentime'] = time();
$map['s_status'] = $s_status;
$add_res = M('plug_store')->add($map);
if (!empty($add_res)) {
$res['status'] = 1;
$res['msg'] = '提交成功!';
} else {
$res['status'] = 0;
$res['msg'] = '提交失败!';
}
} else { // 修改
$save['s_status'] = $s_status;
$save['opentime'] = time();
$save_res = M('plug_store')->where(array('storeid' => $id, 'plug_id' => $plug_id))->save($save);
if (!empty($save_res)) {
$res['status'] = 1;
$res['msg'] = '提交成功!';
if ($s_status == 1) {
$msg = '开启';
} else {
$msg = '关闭';
}
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '插件-拼图/秒杀修改门店状态:' . $msg;//操作行为描述
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 secKill()
{
$arr = array(
'groupState' => '/index.php/Retail/Plug/groupState',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
// 获取门店数据
public function getStoreList2()
{
$User = session('ls_userinfo');
$where['merchantid'] = $User['merchantid'];
$where['store_status'] = 0;
$where['state'] = 0;
$superinfo = M('retail_store')->where($where)->page((int)$_POST['page'], (int)$_POST['limit'])->order('id asc')->select();
$count = M('retail_store')->where($where)->count();
if ($superinfo) {
$plug = M('plug')->where(array('plug_name' => '秒杀', 'status' => 1))->find();
if (empty($plug)) {
$this->error("您无权进行此操作");
} else {
$plug_id = $plug['id'];
}
$index = 1;
foreach ($superinfo as $key => &$val) {
$store_plug = M('plug_store')->where(array('plug_id' => $plug_id, 'storeid' => $val['id']))->find();
$val['s_status'] = empty($store_plug) ? 0 : $store_plug['s_status'];
$val['index'] = $index++;
if ($val['store_type'] == 0) {
$val['store_type'] = "主店";
} else {
$val['store_type'] = "分店";
}
$manager = M('retail_manager')->where(array('storeid' => $val['id'], 'status' => 1))->find();
$val['shop_manager'] = $manager ? $manager['name'] : '未设置';
$val['tel'] = $manager ? $manager['mobile'] : '未设置';
$val['plug_id'] = $plug_id;
}
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $superinfo;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 修改秒杀插件状态
public function secKillState()
{
if (IS_POST) {
$id = I('post.id');
$plug_id = I('post.plug_id');
$s_status = I('post.s_status');
if (!empty($id) && !empty($plug_id) && $s_status != '') {
$find_store = M('plug_store')->where(array('storeid' => $id, 'plug_id' => $plug_id))->find();
if (empty($find_store)) { // 添加
$map['storeid'] = $id;
$map['plug_id'] = $plug_id;
$map['addtime'] = time();
$map['opentime'] = time();
$map['s_status'] = $s_status;
$add_res = M('plug_store')->add($map);
if (!empty($add_res)) {
$res['status'] = 1;
$res['msg'] = '提交成功!';
} else {
$res['status'] = 0;
$res['msg'] = '提交失败!';
}
} else { // 修改
$save['s_status'] = $s_status;
$save['opentime'] = time();
$save_res = M('plug_store')->where(array('storeid' => $id, 'plug_id' => $plug_id))->save($save);
if (!empty($save_res)) {
$res['status'] = 1;
$res['msg'] = '提交成功!';
} else {
$res['status'] = 0;
$res['msg'] = '调教失败!';
}
}
} else {
$res['status'] = 0;
$res['msg'] = '参数不全';
}
$this->ajaxReturn($res);
}
}
/**
* 预售
*/
public function advance()
{
$arr = array(
'advanceState' => '/index.php/Retail/Plug/changeAdvance',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
/**
* 列表
*/
public function getAdvanceSale()
{
$merchant_id = session("merchant_userinfo")["id"];
$plug = D("RetailPlug")->plug_mer_verify(array("merchant_id" => $merchant_id, "plug_id" => [45]));
if (empty($plug['advance_id'])) {
$this->error("您无权进行此操作");
}
$plug_id = $plug['advance_id'];
$page = I('post.page') . ',' . I('limit');
$where = array(
'merchantid' => $merchant_id,
'store_status' => 0,
'state' => 0
);
$fields = "id,detail_address,storetag,phone";
$list = D("RetailStore")->getSelect($where, $fields, $order = 'id desc', $page);
if ($list) {
$count = D("RetailStore")->getCount($where);
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
$manager = M('retail_manager')->where(array('storeid' => $val['id'], 'status' => 1))->find();
$val['shop_manager'] = $manager ? $manager['name'] : '未设置';
$store_plug = M('plug_store')->where(array('plug_id' => $plug_id, 'storeid' => $val['id']))->find();
$val['s_status'] = $store_plug ? $store_plug['s_status'] : 0;
$val['plug_id'] = $plug_id;
}
}
$res['data'] = $list;
$res['count'] = $count ? $count : 0;
$this->ajaxReturn($res);
}
/**
* 预售操作
*/
public function changeAdvance()
{
$data = I("post.");
$store_id = $data['id'];
$plug_id = $data['plug_id'];
$s_status = $data['s_status'];
if (!$store_id || !$plug_id) {
$res['status'] = 0;
$res['msg'] = '参数缺失';
$this->ajaxReturn($res);
}
$info = M('plug_store')->where(array('storeid' => $store_id, 'plug_id' => $plug_id))->find();
if ($info) {
$save = M("plug_store")->where(array('storeid' => $store_id, 'plug_id' => $plug_id))->save(array('s_status' => $s_status));
} else {
$content = array(
'storeid' => $store_id,
'plug_id' => $plug_id,
'addtime' => time(),
'opentime' => time(),
's_status' => 1,
);
$save = M("plug_store")->add($content);
}
if ($save) {
$res['status'] = 1;
$res['msg'] = '操作成功';
} else {
$res['status'] = 0;
$res['msg'] = '操作失败';
}
$this->ajaxReturn($res);
}
}