1482 行
60 KiB
PHP
可执行文件
1482 行
60 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
use Common\Model\RetailMCouponGroupModel;
|
||
use Common\Model\RetailMCouponModel;
|
||
use Common\Model\RetailMerchantModel;
|
||
use Common\Model\RetailRechargeOrderModel;
|
||
use Common\Model\RetailStoreModel;
|
||
use Common\Model\RetailVipRechargeModel;
|
||
use Retail\Business\Vip;
|
||
use Think\Controller;
|
||
use Think\Page;
|
||
|
||
//[1.8.70]
|
||
class ViprechargeController extends BaseController
|
||
{
|
||
//选择角色场景改变
|
||
public function scene()
|
||
{
|
||
$role_type_id = I('post.role_type_id');
|
||
if ($role_type_id == 3) { //常规会员
|
||
//场景
|
||
$scene_type = array(
|
||
array('scene_type_name' => '常规充值活动', 'scene_type_val' => 1),
|
||
array('scene_type_name' => '成为Plus会员充值活动', 'scene_type_val' => 2),
|
||
);
|
||
} else if ($role_type_id == 2) { //plus会员
|
||
//场景
|
||
$scene_type = array(
|
||
array('scene_type_name' => '常规充值活动', 'scene_type_val' => 1),
|
||
array('scene_type_name' => 'plus会员续费充值活动', 'scene_type_val' => 3),
|
||
);
|
||
} else {
|
||
$scene_type = array();
|
||
}
|
||
$res['data'] = $scene_type;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/*
|
||
* 充值记录页面
|
||
*/
|
||
public function recharge()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
/*
|
||
* 获取会员充值记录-列表
|
||
*/
|
||
public function vipRechargeList()
|
||
{
|
||
$param['req_data'] = I('post.req_data'); // 搜索条件
|
||
$param['page'] = I('post.page');
|
||
$param['limit'] = I('post.limit');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$vipClass = new Vip();
|
||
$result = $vipClass->getRechargeList($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 获取会员充值记录-统计
|
||
*/
|
||
public function rechargeTotal()
|
||
{
|
||
$param['req_data'] = I('post.req_data'); // 搜索条件
|
||
$param['page'] = I('post.page');
|
||
$param['limit'] = I('post.limit');
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$vipClass = new Vip();
|
||
$result = $vipClass->getRechargeTotal($param);
|
||
$this->ajaxReturn($result);
|
||
}
|
||
|
||
/**
|
||
* 充值记录导出
|
||
*/
|
||
public function rechargeExport()
|
||
{
|
||
$param['req_data'] = I('get.req_data'); // 搜索条件
|
||
$param['page'] = I('get.page');
|
||
$param['limit'] = I('get.limit');
|
||
$param['is_export'] = 1;
|
||
$param['merchant_id'] = $this->merchant_id;
|
||
$vipClass = new Vip();
|
||
$result = $vipClass->getRechargeList($param);
|
||
if ($result['status'] != 1) {
|
||
$this->ajaxReturn($result);
|
||
}
|
||
$file_name = "会员充值记录";
|
||
$str = $file_name . "导出时间:" . date('Y-m-d H:i:s', time());
|
||
$head_arr = [
|
||
['index', '序号'],
|
||
['name', '姓名'],
|
||
['nickname', '昵称'],
|
||
['mobile_phone', '手机号'],
|
||
['card_key', '实体卡'],
|
||
['store_name', '充值门店'],
|
||
['scene_name', '充值类型'],
|
||
['recharge_mode', '充值方式'],
|
||
['money', '充值金额'],
|
||
['give_money', '赠送金额'],
|
||
['all_money', '到账金额'],
|
||
['pay_coupon_fee', '代金券'],
|
||
['aging_repay_name', '到账方式'],
|
||
['add_time', '充值时间'],
|
||
['remark', '备注'],
|
||
];
|
||
getExcel($file_name, $head_arr, $result['data']['list'], $str);
|
||
}
|
||
|
||
/*
|
||
* plus会员2019-4-27
|
||
*/
|
||
public function Viprechargeset()
|
||
{
|
||
if (IS_POST) {
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$store_id = I('post.store_id'); //选择的门店数组
|
||
$data['role_type'] = I('post.role_type_id');
|
||
$data['scene_type'] = I('post.scene_type_id');
|
||
$data['recharge_money'] = I('post.money');
|
||
$data['give_money'] = I('post.give') ? I('post.give') : 0;
|
||
$data['merchant_id'] = $merchantid;
|
||
$data['add_time'] = time();
|
||
$data['limit_num'] = I('post.limit');
|
||
$data['stock'] = I('post.maxnum');
|
||
$data['surplus'] = !$data['stock'] || $data['stock'] == 0 ? '-1' : $data['stock'];
|
||
$data['start_time'] = I('post.stime') ? newStrToTime(I('post.stime') . ' 00:00:00') : "0";
|
||
$data['end_time'] = I('post.etime') ? newStrToTime(I('post.etime') . ' 23:59:59') : "0";
|
||
$data['coupon_type'] = I('post.couponType');
|
||
$data['coupon_id'] = I('post.coupon_id');
|
||
if (!$data['recharge_money'] || !$merchantid || !$data['role_type'] || !$data['scene_type'] || !$store_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请刷新重试';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
foreach ($store_id as $key => &$val) {
|
||
$data['store_id'] = $val;
|
||
$ret = M('vip_recharge')->add($data);
|
||
}
|
||
if ($ret !== false) {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置成功';
|
||
} else {
|
||
$rt['status'] = 0;
|
||
$rt['msg'] = '设置失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
public function ViprechargDel()
|
||
{
|
||
if (IS_POST) {
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$data['merchantid'] = $merchantid;
|
||
$data['id'] = I('post.id');
|
||
if (!$data['merchantid'] || !$data['id']) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$ret = M('vip_recharge')->where($data)->delete();
|
||
if ($ret !== false) {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '删除成功';
|
||
} else {
|
||
$rt['status'] = 0;
|
||
$rt['msg'] = '删除失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
}
|
||
|
||
//修改优惠券活动
|
||
public function modifyCoupon()
|
||
{
|
||
$recharge_id = I('post.recharge_id');
|
||
$coupon_id = I('post.coupon_id');
|
||
$coupon_type = I('post.coupon_type');
|
||
if (!$recharge_id || !$coupon_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '登录超时,请重新登录';
|
||
$this->ajaxReturn($res);
|
||
exit;
|
||
}
|
||
$map['coupon_type'] = $coupon_type;
|
||
$map['coupon_id'] = $coupon_id;
|
||
$save = M('vip_recharge')->where(array('id' => $recharge_id))->save($map);
|
||
if ($save) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '操作成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '操作成功';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 充值记录
|
||
*/
|
||
public function rechargeRecord()
|
||
{
|
||
// 获取session
|
||
$userinfo = session("ls_userinfo");
|
||
$merchant_id = $userinfo['merchantid'];
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$map = array(
|
||
'merchant_id' => $merchant_id,
|
||
'status' => 1,
|
||
'state' => 1,
|
||
'type' => 1,
|
||
'vip_recharge_id' => $id
|
||
);
|
||
$info = M('recharge_order')->where($map)->page($page, $limit)->order('add_time desc')->select();
|
||
if ($info) {
|
||
$count = M('recharge_order')->where($map)->count();
|
||
foreach ($info as $k => &$v) {
|
||
$v['index'] = $k + 1 + $limit * ($page - 1);
|
||
$vip = M('retail_vip')->where(array('id' => $v['vid']))->find();
|
||
$v['vipname'] = $vip['name'] ? $vip['name'] : $vip['nickname'];
|
||
$v['addtime'] = date('Y-m-d H:i:s', $v['add_time']);
|
||
}
|
||
} else {
|
||
$count = 0;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['recordList'] = $info;
|
||
$res['recordLen'] = (int)$count;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//自定义充值开关
|
||
public function setinputrecharge()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$inputrecharge = I('post.inputrecharge');
|
||
$ret = M('retail_merchant')->where(array('id' => $merchantid))->save(array('inputrecharge' => $inputrecharge));
|
||
if ($ret) {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置成功';
|
||
} else {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
|
||
//自动读取充值档次
|
||
public function setauto_read_recharge_grade()
|
||
{
|
||
$userinfo = session("ls_userinfo");
|
||
$merchantid = $userinfo['merchantid'];
|
||
$auto_read_recharge_grade = I('post.auto_read_recharge_grade');
|
||
$ret = M('retail_merchant')->where(array('id' => $merchantid))->save(array('auto_read_recharge_grade' => $auto_read_recharge_grade));
|
||
if ($ret) {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置成功';
|
||
} else {
|
||
$rt['status'] = 1;
|
||
$rt['msg'] = '设置失败';
|
||
}
|
||
$this->ajaxReturn($rt);
|
||
}
|
||
|
||
/*
|
||
* 单张优惠券活动
|
||
*/
|
||
public function coupon_activity()
|
||
{
|
||
$merchantid = session("merchant_userinfo")['id']; //商户id
|
||
$stime = time();
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
$map['merchantid'] = $merchantid;
|
||
$map['coupon_num'] = array('gt', 0); //优惠券剩余数量
|
||
$map['status'] = 1; //正常
|
||
$map['give_status'] = 2; //充值赠送
|
||
$map['type'] = 1; //普通优惠券
|
||
$coupon = M('retail_mcoupon')->where($map)->page($page, $limit)->order('addtime desc')->select();
|
||
if (!$coupon) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无可用优惠券';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$count = M('retail_mcoupon')->where($map)->count();
|
||
foreach ($coupon as $key => &$val) {
|
||
switch ($val['coupontype']) {
|
||
case 1:
|
||
$val['usetime'] = date('Y-m-d H:i:s', $val['starttime']) . '至' . date('Y-m-d H:i:s', $val['endtime']);
|
||
if ($val['starttime'] > $stime) {
|
||
$val['state'] = 1;
|
||
$val['typename'] = '未开始';
|
||
} else if ($val['starttime'] < $stime && $val['endtime'] > $stime) {
|
||
$val['state'] = 1;
|
||
$val['typename'] = '进行中';
|
||
} else {
|
||
$val['state'] = 2;
|
||
$val['typename'] = '已结束';
|
||
}
|
||
break;
|
||
case 2:
|
||
$val['usetime'] = "会员领取当日起" . $val['daynum'] . '天内有效';
|
||
$val['state'] = $val['coupon_num'] > 0 ? 1 : 2;
|
||
$val['typename'] = $val['coupon_num'] > 0 ? '进行中' : '已结束';
|
||
break;
|
||
case 3:
|
||
$val['usetime'] = "会员领取次日日起" . $val['daynum'] . '天内有效';
|
||
$val['state'] = $val['coupon_num'] > 0 ? 1 : 2;
|
||
$val['typename'] = $val['coupon_num'] > 0 ? '进行中' : '已结束';
|
||
break;
|
||
default:
|
||
$val['usetime'] = "错误的优惠券,建议删除";
|
||
$val['typename'] = '已结束';
|
||
$val['state'] = 2;
|
||
}
|
||
}
|
||
$res['status'] = 1;
|
||
$res['coupon'] = $coupon;
|
||
$res['count'] = $count ? (int)$count : 0;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取券包数据
|
||
* @return $res
|
||
*/
|
||
public function couponGroupList()
|
||
{
|
||
$merchantid = session("merchant_userinfo")['id'];
|
||
$page = I('post.page');
|
||
$limit = I('post.limit');
|
||
$map['merchantid'] = $merchantid;
|
||
$map['status'] = 1;
|
||
$map['give_status'] = 2;
|
||
$coupon_group = M('retail_mcoupon_group')->where($map)->page($page, $limit)->order('addtime desc')->select();
|
||
if (!$coupon_group) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无数据';
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$count = M('retail_mcoupon_group')->where($map)->count();
|
||
foreach ($coupon_group as &$val) {
|
||
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
||
$val['coupon_group_allnum'] = floatval($val['coupon_group_allnum']);
|
||
$val['coupon_group_num'] = floatval($val['coupon_group_num']);
|
||
$val['coupon_group_money'] = floatval($val['coupon_group_money']);
|
||
}
|
||
$res['status'] = 1;
|
||
$res['coupon_group'] = $coupon_group;
|
||
$res['count'] = $count ? (int)$count : 0;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
//执行秘法更新plus会员版本要更改用户之前的数据库的数据不做更新
|
||
public function implementLaw()
|
||
{
|
||
$recharge_where['status'] = 1;
|
||
$recharge = M('vip_recharge')->where($recharge_where)->select();
|
||
if ($recharge) {
|
||
foreach ($recharge as $key => &$val) {
|
||
$data['money'] = $val['money'];
|
||
$data['give'] = $val['give'];
|
||
$data['addtime'] = $val['addtime'];
|
||
$data['merchantid'] = $val['merchantid'];
|
||
$data['num'] = $val['num'];
|
||
$data['maxnum'] = $val['maxnum'];
|
||
$data['limit'] = $val['limit'];
|
||
$data['stime'] = $val['stime'];
|
||
$data['etime'] = $val['etime'];
|
||
$store_where['state'] = 0;
|
||
$store_where['store_status'] = 0;
|
||
$store_where['merchantid'] = $val['merchantid'];
|
||
$store_ids = M('retail_store')->where($store_where)->getField("id", true);
|
||
foreach ($store_ids as $k => &$v) {
|
||
$data['store_id'] = $v;
|
||
M('vip_recharge')->add($data);
|
||
}
|
||
M('vip_recharge')->where(array('id' => $val['id']))->delete();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
/*******************************************************************************************************************************************
|
||
* 充值管理
|
||
*/
|
||
/**
|
||
*
|
||
*/
|
||
public function index()
|
||
{
|
||
// 节点
|
||
$arr = array(
|
||
'viprechargeset' => '/index.php/Retail/viprecharge/viprechargeset',
|
||
'setinputrecharge' => '/index.php/Retail/viprecharge/setinputrecharge',
|
||
'setauto_read_recharge_grade' => '/index.php/Retail/viprecharge/setauto_read_recharge_grade',
|
||
'rechargerecord' => '/index.php/Retail/viprecharge/rechargerecord',
|
||
'Viprechargdel' => '/index.php/Retail/viprecharge/Viprechargdel',
|
||
'coupon_activity' => '/index.php/Retail/viprecharge/coupon_activity',
|
||
'modifyCoupon' => '/index.php/Retail/viprecharge/modifyCoupon',
|
||
'updateState' => '/index.php/Retail/Viprecharge/updateState',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
/**
|
||
* 获取活动列表
|
||
* @param $seek_data array 搜索条件
|
||
* @param $page string 分页
|
||
* @param $limit string 数量
|
||
* @return $res array
|
||
*/
|
||
public function getVipRechargeActivity()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$page = intval(I('post.page'));
|
||
$limit = intval(I('post.limit'));
|
||
$seek_data = I('post.seek_data');
|
||
// 判断门店搜索条件
|
||
if ($seek_data['rechargeStoreId']) {
|
||
$map['r.store_id'] = $seek_data['rechargeStoreId'];
|
||
}
|
||
// 判断角色
|
||
if ($seek_data['rechargeRole']) {
|
||
$map['r.role_type'] = $seek_data['rechargeRole'];
|
||
}
|
||
// 判断场景
|
||
if ($seek_data['rechargeScene']) {
|
||
$map['r.scene_type'] = $seek_data['rechargeScene'];
|
||
}
|
||
$map['r.status'] = 1;
|
||
$map['r.stock'] = array('egt', 0);
|
||
$map['r.merchant_id'] = $merchant_id;
|
||
$map['s.state'] = 0;
|
||
$rechargeList = M('vip_recharge as r')
|
||
->join("ls_retail_store as s on r.store_id=s.id")
|
||
->field("r.*,s.storetag")
|
||
->where($map)
|
||
->page($page, $limit)
|
||
->order('r.add_time desc')
|
||
->select();
|
||
$rechargeLen = M('vip_recharge as r')->join("ls_retail_store as s on r.store_id=s.id")->where($map)->count();
|
||
// 处理数据
|
||
foreach ($rechargeList as $key => &$val) {
|
||
$val['recharge_money'] = floatval($val['recharge_money']);
|
||
$val['give_money'] = floatval($val['give_money']);
|
||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||
$val['stock'] = $val['stock'] == 0 ? '无限制' : $val['stock'] . '次';
|
||
$val['surplus'] = $val['surplus'] == -1 ? '无限制' : '剩余' . $val['surplus'] . '次';
|
||
$val['limit_num'] = $val['limit_num'] == 0 ? '无限制' : $val['limit_num'] . '次';
|
||
// 有效时间
|
||
if ($val['start_time'] && $val['end_time']) {
|
||
$val['time_slot'] = date('Y-m-d', $val['start_time']) . '至' . date('Y-m-d', $val['end_time']);
|
||
} else if ($val['start_time'] && !$val['end_time']) {
|
||
$val['time_slot'] = date('Y-m-d', $val['start_time']) . '生效';
|
||
} else if (!$val['start_time'] && $val['end_time']) {
|
||
$val['time_slot'] = date('Y-m-d', $val['end_time']) . '截止';
|
||
} else if (!$val['start_time'] && !$val['end_time']) {
|
||
$val['time_slot'] = '不限制';
|
||
}
|
||
// 角色
|
||
if ($val['role_type'] == 3) {
|
||
$val['role'] = '普通会员';
|
||
} else if ($val['role_type'] == 2) {
|
||
$val['role'] = 'plus会员';
|
||
} else {
|
||
$val['role'] = '未知类型';
|
||
}
|
||
// 场景
|
||
if ($val['scene_type'] == 1) {
|
||
$val['scene'] = '常规活动';
|
||
} else if ($val['scene_type'] == 2) {
|
||
$val['scene'] = '开通plus';
|
||
} else if ($val['scene_type'] == 3) {
|
||
$val['scene'] = '续费plus';
|
||
} else {
|
||
$val['scene'] = '未知类型';
|
||
}
|
||
// 是否绑定活动
|
||
if ($val['coupon_type'] == 1) {
|
||
$val['coupon_type_name'] = '优惠券活动';
|
||
} else if ($val['coupon_type'] == 2) {
|
||
$val['coupon_type_name'] = '券包活动';
|
||
} else {
|
||
$val['coupon_type_name'] = '未绑定活动';
|
||
}
|
||
// 活动名称
|
||
if ($val['coupon_id']) {
|
||
if ($val['coupon_type'] == 1) {
|
||
$coupon_name = M('retail_mcoupon')->where(array('id' => $val['coupon_id']))->getField("coupon_name");
|
||
$val['coupon_name'] = $coupon_name ? $coupon_name : '异常活动';
|
||
} else if ($val['coupon_type'] == 2) {
|
||
$coupon_name = M('retail_mcoupon_group')->where(array('id' => $val['coupon_id']))->getField("coupon_group_name");
|
||
$val['coupon_name'] = $coupon_name ? $coupon_name : '异常活动';
|
||
} else {
|
||
$val['coupon_name'] = '未绑定活动';
|
||
}
|
||
} else {
|
||
$val['coupon_name'] = '未绑定活动';
|
||
}
|
||
// 活动状态
|
||
$val['state'] = $val['state'] ? strval($val['state']) : '0';
|
||
}
|
||
$res = array(
|
||
'status' => 1,
|
||
'rechargeList' => !empty($rechargeList) ? $rechargeList : array(),
|
||
'rechargeLen' => $rechargeLen ? intval($rechargeLen) : 0
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取商户充值设置,判断节点操作权限
|
||
*/
|
||
public function getRechargeSet()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 获取节点操作
|
||
$arr = array(
|
||
'setinputrecharge' => '/index.php/Retail/viprecharge/setinputrecharge',
|
||
'setauto_read_recharge_grade' => '/index.php/Retail/viprecharge/setauto_read_recharge_grade',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
// 判断节点
|
||
if ($authArr['setinputrecharge'] != 1 && $authArr['setauto_read_recharge_grade'] != 1) {
|
||
$res = array('status' => 0, 'msg' => '无权操作');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 获取商户充值设置
|
||
$RMModel = new RetailMerchantModel();
|
||
$map = array(
|
||
'id' => $merchant_id,
|
||
'status' => 1
|
||
);
|
||
$field = array('inputrecharge', 'auto_read_recharge_grade', 'aging_cycle', 'aging_repay', 'aging_time');
|
||
$setting = $RMModel->getFind($map, $field);
|
||
if (empty($setting)) {
|
||
$res = array('status' => 0, 'msg' => '商户状态异常,请联系代理商');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 处理数据
|
||
$setting['inputrecharge'] = strval($setting['inputrecharge']);
|
||
$setting['aging_cycle'] = strval($setting['aging_cycle']);
|
||
$setting['aging_repay'] = strval($setting['aging_repay']);
|
||
$setting['aging_time'] = strval($setting['aging_time']);
|
||
$setting['auto_read_recharge_grade'] = strval($setting['auto_read_recharge_grade']);
|
||
$res = array('status' => 1, 'setting' => $setting);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 编辑充值这设置
|
||
* @param $setting array 充值设置
|
||
* @return $res array
|
||
*/
|
||
public function updateRechargeSet()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$setting = I('post.setting');
|
||
// 判断参数
|
||
if (!$setting['inputrecharge'] || !$setting['auto_read_recharge_grade']) {
|
||
$res = array('status' => 0, 'msg' => '提交异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
// 获取原社会
|
||
$RMModel = D('RetailMerchant');
|
||
$map = array(
|
||
'id' => $merchant_id,
|
||
'status' => 1
|
||
);
|
||
$field = array('inputrecharge', 'auto_read_recharge_grade', 'aging_cycle', 'aging_repay', 'aging_time');
|
||
$find_setting = $RMModel->getFind($map, $field);
|
||
if (empty($setting)) {
|
||
$res = array('status' => 0, 'msg' => '商户状态异常,请联系代理商');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 判断修改
|
||
$up = array();
|
||
// 判断自定义充值
|
||
if ($find_setting['inputrecharge'] != intval($setting['inputrecharge'])) {
|
||
$up['inputrecharge'] = intval($setting['inputrecharge']);
|
||
}
|
||
// 判断动读取充值档次
|
||
if ($find_setting['auto_read_recharge_grade'] != intval($setting['auto_read_recharge_grade'])) {
|
||
$up['auto_read_recharge_grade'] = intval($setting['auto_read_recharge_grade']);
|
||
}
|
||
// 判断分期周期(日/月)
|
||
if ($find_setting['aging_cycle'] != intval($setting['aging_cycle'])) {
|
||
$up['aging_cycle'] = intval($setting['aging_cycle']);
|
||
}
|
||
// 判断分期到账开启状态
|
||
if ($find_setting['aging_repay'] != intval($setting['aging_repay'])) {
|
||
$up['aging_repay'] = intval($setting['aging_repay']);
|
||
}
|
||
// 判断分期到账间隔
|
||
if ($find_setting['aging_time'] != intval($setting['aging_time'])) {
|
||
$up['aging_time'] = intval($setting['aging_time']);
|
||
}
|
||
// 二次判断提交
|
||
if (empty($up)) {
|
||
$res = array('status' => 0, 'msg' => '请修改后再提交');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
$save_reult = $RMModel->updateOrder($map, $up);
|
||
if ($save_reult) {
|
||
$res = array('status' => 1, '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 = array('status' => 0, 'msg' => '修改失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取充值赠送的优惠券或券包
|
||
* @param $type string 类型 1.优惠券 2.券包
|
||
* @return $res array
|
||
*/
|
||
public function getCouponOrCouponGroup()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$type = intval(I('post.type'));
|
||
if (!$type) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 判断类型
|
||
switch ($type) {
|
||
case 1:
|
||
// 获取优惠券
|
||
$res = $this->getCoupon($merchant_id);
|
||
break;
|
||
case 2:
|
||
$res = $this->getCouponGroup($merchant_id);
|
||
break;
|
||
default:
|
||
$res = array('status' => 0, 'msg' => '未知类型');
|
||
break;
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 获取优惠券列表
|
||
* @return $res array
|
||
*/
|
||
protected function getCoupon($merchant_id)
|
||
{
|
||
// 优惠券模型
|
||
$RMcModel = new RetailMCouponModel();
|
||
$time = time();
|
||
// 条件
|
||
$map = array(
|
||
'merchantid' => $merchant_id,
|
||
'give_status' => 2,
|
||
'status' => 1,
|
||
'type' => 1,
|
||
'coupon_num' => array('gt', 0),
|
||
'_string' => "(coupontype = 1 AND endtime > {$time}) OR (coupontype = 2) OR (coupontype = 3)",
|
||
);
|
||
$field = array('id', 'coupon_name', 'coupontype', 'coupon_allnum', 'coupon_num', 'needmoney', 'reducemoney', 'starttime', 'endtime', 'daynum');
|
||
$coupon = $RMcModel->getSelect($map, $field);
|
||
if (empty($coupon)) {
|
||
$res = array('status' => 0, 'msg' => '暂无可用优惠券');
|
||
return $res;
|
||
}
|
||
// 处理数据
|
||
foreach ($coupon as &$val) {
|
||
$val['name'] = $val['coupon_name'];
|
||
switch ($val['coupontype']) {
|
||
case 1:
|
||
// 判断活动
|
||
$val['use_time'] = date('Y-m-d H:i:s', $val['starttime']) . '至' . date('Y-m-d H:i:s', $val['endtime']);
|
||
break;
|
||
case 2:
|
||
$val['use_time'] = "会员领取当日起" . $val['daynum'] . '天内有效';
|
||
break;
|
||
case 3:
|
||
$val['use_time'] = "会员领取次日日起" . $val['daynum'] . '天内有效';
|
||
break;
|
||
default:
|
||
$val['use_time'] = "异常的优惠券,建议删除";
|
||
}
|
||
}
|
||
$res = array('status' => 1, 'coupon_list' => $coupon);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取券包列表
|
||
* @return $res array
|
||
*/
|
||
protected function getCouponGroup($merchant_id)
|
||
{
|
||
// 券包模型
|
||
$RMCGModel = new RetailMCouponGroupModel();
|
||
// 条件
|
||
$map = array(
|
||
'merchantid' => $merchant_id,
|
||
'coupon_group_num' => array('gt', 0),
|
||
'give_status' => 2,
|
||
'status' => 1,
|
||
);
|
||
$field = ['id', 'coupon_group_name', 'coupon_group_allnum', 'coupon_group_num', 'coupon_group_money', 'addtime'];
|
||
$coupon_group = $RMCGModel->getSelect($map, $field);
|
||
if (empty($coupon_group)) {
|
||
$res = array('status' => 0, 'msg' => '暂无可用券包');
|
||
return $res;
|
||
}
|
||
// 处理数据
|
||
foreach ($coupon_group as &$val) {
|
||
$val['name'] = $val['coupon_group_name'];
|
||
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
||
}
|
||
$res = array('status' => 1, 'coupon_list' => $coupon_group);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 提交
|
||
* @param $data array 提交数据
|
||
* @return $res array
|
||
*/
|
||
public function submitActivity()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接收数据
|
||
$data = I('post.data');
|
||
// 判断表单提交
|
||
if (empty($data) || empty($data['store_id']) || !$data['role_type'] || !$data['scene_type'] || !$data['recharge_money']) {
|
||
$res = array('status' => 0, 'msg' => '请完善表单提交');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
//判断是否是成为plus或续费plus活动并且是否设置有效时长
|
||
if ($data['role_type'] == 3 && $data['scene_type'] == 2 || $data['role_type'] == 2 && $data['scene_type'] == 3) {
|
||
if (!$data['time']) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '请输入Plus会员有效时间'
|
||
);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
} else {
|
||
$data['time'] = 0;
|
||
}
|
||
// 判断时间
|
||
if ($data['start_time'] && $data['end_time'] && $data['start_time'] > $data['end_time']) {
|
||
$res = array('status' => 0, 'msg' => '结束时间设置不正确');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 判断活动类型
|
||
if (intval($data['coupon_type']) != 0 && !$data['coupon_id']) {
|
||
$res = array('status' => 0, 'msg' => '请选择优惠活动');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 判断创建,修改
|
||
if (!$data['id'] || $data['id'] == '') {
|
||
// 创建
|
||
$res = $this->createActivity($merchant_id, $data);
|
||
if ($res['status'] == 1) {
|
||
//操作日志记录
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = 3; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST); //请求参数 json数据
|
||
$desc = '新增充值活动'; //操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
}
|
||
} else {
|
||
// 修改
|
||
$res = $this->updateActivity($merchant_id, $data);
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 创建活动
|
||
* @param $merchant_id int 商户id
|
||
* @param $data array 表单提交
|
||
* @return $res array
|
||
*/
|
||
private function createActivity($merchant_id, $data)
|
||
{
|
||
// 判断优惠活动类型
|
||
if ($data['coupon_type'] && intval($data['coupon_type']) != 0) {
|
||
// 判断是否选择优惠活动
|
||
if (!$data['coupon_id'] || intval($data['coupon_id']) == 0) {
|
||
$res = array('status' => 0, 'msg' => '请选择优惠活动');
|
||
return $res;
|
||
}
|
||
} else {
|
||
$data['coupon_id'] = 0;
|
||
}
|
||
// 充值活动模型
|
||
$RVRModel = new RetailVipRechargeModel();
|
||
$cr = array(
|
||
'merchant_id' => $merchant_id,
|
||
'recharge_money' => $data['recharge_money'],
|
||
'give_money' => $data['give_money'],
|
||
'stock' => $data['stock'] && intval($data['stock']) > 0 ? intval($data['stock']) : 0,
|
||
'surplus' => $data['stock'] && intval($data['stock']) > 0 ? intval($data['stock']) : '-1',
|
||
'limit_num' => $data['limit_num'] && intval($data['limit_num']) > 0 ? intval($data['limit_num']) : 0,
|
||
'start_time' => $data['start_time'] ? strtotime($data['start_time'] . "00:00:00") : time(),
|
||
'end_time' => $data['end_time'] ? strtotime($data['end_time'] . "23:59:59") : '',
|
||
'role_type' => $data['role_type'],
|
||
'scene_type' => $data['scene_type'],
|
||
'coupon_type' => $data['coupon_type'] ? $data['coupon_type'] : 0,
|
||
'coupon_id' => $data['coupon_id'] ? $data['coupon_id'] : 0,
|
||
'status' => 1,
|
||
'state' => $data['state'] ? intval($data['state']) : 0,
|
||
'line_state' => $data['line_state'] ? intval($data['line_state']) : 0,
|
||
'online_state' => $data['online_state'] ? intval($data['online_state']) : 0,
|
||
'add_time' => time(),
|
||
'time' => $data['time'] ? intval($data['time']) : 0,
|
||
'aging_repay' => $data['aging_repay'],
|
||
'aging_time' => $data['aging_time'] ?: 0,
|
||
);
|
||
// 添加单个门店活动
|
||
$sign = 0;
|
||
foreach ($data['store_id'] as &$val) {
|
||
$cr1 = $cr;
|
||
$cr1['store_id'] = $val;
|
||
$result = $RVRModel->addOrder($cr1);
|
||
if (!$result) {
|
||
$sign++;
|
||
}
|
||
unset($cr1);
|
||
unset($result);
|
||
}
|
||
// 判断
|
||
if ($sign && intval($sign) > 0) {
|
||
if ($sign >= count($data['store_id'])) {
|
||
$res = array('status' => 0, 'msg' => '创建失败');
|
||
} else {
|
||
$res = array('status' => 2, 'msg' => '部分门店创建失败');
|
||
}
|
||
} else {
|
||
$res = array('status' => 1, 'msg' => '创建成功');
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 编辑活动,获取数据
|
||
* @param $id int 活动id
|
||
* @return $res array
|
||
*/
|
||
public function getUpdateData()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询
|
||
$RVRModel = new RetailVipRechargeModel();
|
||
$map = array(
|
||
'id' => $id,
|
||
'merchant_id' => $merchant_id,
|
||
'status' => 1
|
||
);
|
||
|
||
$field = array(
|
||
'id',
|
||
'store_id',
|
||
'role_type',
|
||
'scene_type',
|
||
'recharge_money',
|
||
'give_money',
|
||
'stock',
|
||
'surplus',
|
||
'limit_num',
|
||
'start_time',
|
||
'end_time',
|
||
'coupon_type',
|
||
'coupon_id',
|
||
'state',
|
||
'line_state',
|
||
'online_state',
|
||
'time',
|
||
'aging_repay',
|
||
'aging_time',
|
||
);
|
||
$find = $RVRModel->getFind($map, $field);
|
||
|
||
if (empty($find)) {
|
||
$res = array('status' => 0, 'msg' => '活动异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 处理数据
|
||
$find['num'] = $find['stock'];
|
||
$find['store_id'] = (array)$find['store_id'];
|
||
$find['recharge_money'] = floatval($find['recharge_money']);
|
||
$find['give_money'] = floatval($find['give_money']);
|
||
$find['coupon_type'] = $find['coupon_type'] && $find['coupon_type'] != 0 ? strval($find['coupon_type']) : '0';
|
||
$find['coupon_id'] = $find['coupon_id'] && $find['coupon_id'] != 0 ? $find['coupon_id'] : '';
|
||
$find['state'] = $find['state'] ? strval($find['state']) : '0';
|
||
$find['line_state'] = $find['line_state'] ? strval($find['line_state']) : '0';
|
||
$find['online_state'] = $find['online_state'] ? strval($find['online_state']) : '0';
|
||
// 判断时间
|
||
if ($find['start_time']) {
|
||
$find['start_time'] = date('Y-m-d', $find['start_time']);
|
||
}
|
||
if ($find['end_time']) {
|
||
$find['end_time'] = date('Y-m-d', $find['end_time']);
|
||
}
|
||
// 定义优惠券数据
|
||
$coupon_data = array(
|
||
'name' => '', // 优惠券或券包名称
|
||
'use_time' => '', // 使用时间
|
||
'all_num' => '', // 总数量
|
||
'num' => '', // 剩余数量
|
||
'need_money' => '', // 优惠门槛
|
||
'reduce_money' => '', // 优惠金额
|
||
'money' => '', // 券包金额
|
||
'add_time' => '', // 时间
|
||
);
|
||
// 判断优惠活动
|
||
$coupon_list = array();
|
||
if ($find['coupon_type'] && $find['coupon_id']) {
|
||
switch (intval($find['coupon_type'])) {
|
||
case 1:
|
||
// 查询优惠券
|
||
$RMcModel = D('RetailMCoupon'); // 优惠券模型
|
||
// 条件
|
||
$map2 = array(
|
||
'id' => $find['coupon_id'],
|
||
'merchantid' => $merchant_id,
|
||
'give_status' => 2,
|
||
'type' => 1,
|
||
);
|
||
$field2 = array('coupon_name', 'coupontype', 'coupon_allnum', 'coupon_num', 'needmoney', 'reducemoney', 'starttime', 'endtime', 'daynum', 'status');
|
||
$coupon = $RMcModel->getFind($map2, $field2);
|
||
if (empty($coupon)) {
|
||
$find['coupon_id'] = '';
|
||
} else {
|
||
// 判断优惠券类型
|
||
switch ($coupon['coupontype']) {
|
||
case 1:
|
||
$coupon['use_time'] = date('Y-m-d H:i:s', $coupon['starttime']) . '至' . date('Y-m-d H:i:s', $coupon['endtime']);
|
||
break;
|
||
case 2:
|
||
$coupon['use_time'] = "会员领取当日起" . $coupon['daynum'] . '天内有效';
|
||
break;
|
||
case 3:
|
||
$coupon['use_time'] = "会员领取次日日起" . $coupon['daynum'] . '天内有效';
|
||
break;
|
||
default:
|
||
$find['coupon_type'] = '0';
|
||
$find['coupon_id'] = '';
|
||
$val['use_time'] = "异常的优惠券,建议删除";
|
||
}
|
||
// 判断剩余数量
|
||
if ($coupon['coupon_num'] <= 0) {
|
||
// 数量不足
|
||
$find['coupon_id'] = '';
|
||
}
|
||
// 判断是否失效
|
||
if ($coupon['status'] != 1) {
|
||
// 数量不足
|
||
$find['coupon_id'] = '';
|
||
}
|
||
// 再次定义优惠券数据
|
||
$coupon_data['name'] = $coupon['coupon_name'];
|
||
$coupon_data['use_time'] = $coupon['use_time'];
|
||
$coupon_data['all_num'] = $coupon['coupon_allnum'];
|
||
$coupon_data['num'] = $coupon['coupon_num'] ? $coupon['coupon_num'] : 0;
|
||
$coupon_data['need_money'] = $coupon['needmoney'];
|
||
$coupon_data['reduce_money'] = $coupon['reducemoney'];
|
||
}
|
||
// 获取优惠券列表
|
||
$result = $this->getCoupon($merchant_id);
|
||
if ($result['status'] == 1) {
|
||
$coupon_list = $result['coupon_list'];
|
||
}
|
||
break;
|
||
case 2:
|
||
// 券包模型
|
||
$RMCGModel = D('RetailMCouponGroup');
|
||
// 条件
|
||
$map3 = array(
|
||
'id' => $find['coupon_id'],
|
||
'merchantid' => $merchant_id,
|
||
'give_status' => 2,
|
||
);
|
||
$field3 = array('id', 'coupon_group_name', 'coupon_group_allnum', 'coupon_group_num', 'coupon_group_money', 'addtime', 'status');
|
||
$coupon_group = $RMCGModel->getFind($map3, $field3);
|
||
if (empty($coupon_group)) {
|
||
$find['coupon_id'] = '';
|
||
} else {
|
||
$coupon_group['addtime'] = date('Y-m-d H:i:s', $coupon_group['addtime']);
|
||
// 判断剩余数量
|
||
if ($coupon_group['coupon_group_num'] <= 0) {
|
||
// 数量不足
|
||
$find['coupon_id'] = '';
|
||
}
|
||
// 判断是否失效
|
||
if ($coupon_group['status'] != 1) {
|
||
// 数量不足
|
||
$find['coupon_id'] = '';
|
||
}
|
||
// 再次定义优惠券数据
|
||
$coupon_data['name'] = $coupon_group['coupon_group_name'];
|
||
$coupon_data['all_num'] = $coupon_group['coupon_group_allnum'];
|
||
$coupon_data['num'] = $coupon_group['coupon_group_num'] ? $coupon_group['coupon_group_num'] : 0;
|
||
$coupon_data['money'] = $coupon_group['coupon_group_money'];
|
||
$coupon_data['add_time'] = $coupon_group['addtime'];
|
||
}
|
||
// 获取券包列表
|
||
$result = $this->getCouponGroup($merchant_id);
|
||
if ($result['status'] == 1) {
|
||
$coupon_list = $result['coupon_list'];
|
||
}
|
||
break;
|
||
default:
|
||
$find['coupon_type'] = '0';
|
||
$find['coupon_id'] = '';
|
||
break;
|
||
}
|
||
}
|
||
// 返回值
|
||
$res = array('status' => 1, 'add_form' => $find, 'coupon_data' => $coupon_data, 'coupon_list' => $coupon_list);
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 编辑活动
|
||
* @param $merchant_id int 商户id
|
||
* @param $data array 表单提交
|
||
* @return $res array
|
||
*/
|
||
private function updateActivity($merchant_id, $data)
|
||
{
|
||
$store_id = $data['store_id'][0];
|
||
if (!$store_id) {
|
||
$res = array('status' => 0, 'msg' => '缺少必要的门店参数');
|
||
return $res;
|
||
}
|
||
// 查询活动
|
||
$RVRModel = D('RetailVipRecharge');
|
||
$map = array(
|
||
'id' => $data['id'],
|
||
'merchant_id' => $merchant_id,
|
||
'store_id' => $store_id,
|
||
'status' => 1
|
||
);
|
||
$find = $RVRModel->getFind($map);
|
||
if (empty($find)) {
|
||
$res = array('status' => 0, 'msg' => '活动异常,请刷新重试');
|
||
return $res;
|
||
}
|
||
// 判断修改
|
||
$up = array();
|
||
// 判断角色
|
||
if ($find['role_type'] != $data['role_type']) {
|
||
$up['role_type'] = $data['role_type'];
|
||
}
|
||
// 判断角色
|
||
if ($find['scene_type'] != $data['scene_type']) {
|
||
$up['scene_type'] = $data['scene_type'];
|
||
}
|
||
// 判断类型
|
||
if ($find['state'] != intval($data['state'])) {
|
||
$up['state'] = intval($data['state']);
|
||
}
|
||
// 判断支付金额
|
||
if ($find['recharge_money'] != $data['recharge_money']) {
|
||
$up['recharge_money'] = $data['recharge_money'];
|
||
}
|
||
// 判断赠送金额
|
||
if ($find['give_money'] != $data['give_money']) {
|
||
$up['give_money'] = $data['give_money'] ? $data['give_money'] : 0;
|
||
}
|
||
// 判断总数量
|
||
if ($find['stock'] != $data['stock']) {
|
||
// 判断剩余数量
|
||
if (intval($find['stock']) > 0 && intval($data['stock']) > 0) {
|
||
// 原活动,修改后都有限制
|
||
if (intval($data['stock']) < intval($find['stock']) - intval($data['surplus'])) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '该活动已经充值' . intval($find['stock']) - intval($data['surplus']) . '次,总数量不能小于此数值'
|
||
);
|
||
return $res;
|
||
} else {
|
||
$up['stock'] = $data['stock'];
|
||
$up['surplus'] = $data['stock'] - (intval($find['stock']) - intval($data['surplus']));
|
||
}
|
||
} else if (intval($find['stock']) > 0 && !$data['stock']) {
|
||
// 原活动有限制,修改后不限制
|
||
$up['stock'] = 0;
|
||
$up['surplus'] = '-1';
|
||
} else if (!$find['stock'] && intval($data['stock']) > 0) {
|
||
// 原活动不限制,修改后有限制
|
||
$up['stock'] = intval($data['stock']);
|
||
$up['surplus'] = intval($data['stock']);
|
||
}
|
||
}
|
||
// 判断会员限制
|
||
if ($find['limit_num'] != $data['limit_num']) {
|
||
$up['limit_num'] = $data['limit_num'] ? $data['limit_num'] : 0;
|
||
}
|
||
// 判断开始时间
|
||
$start_time = $data['start_time'] ? strtotime($data['start_time'] . "00:00:00") : time();
|
||
if ($find['start_time'] != $start_time) {
|
||
$up['start_time'] = $start_time;
|
||
}
|
||
// 判断结束时间
|
||
$end_time = $data['end_time'] ? strtotime($data['end_time'] . "23:59:59") : '';
|
||
if ($find['end_time'] != $end_time) {
|
||
$up['end_time'] = $end_time;
|
||
}
|
||
if ($find['line_state'] != intval($data['line_state'])) {
|
||
$up['line_state'] = $data['line_state'];
|
||
}
|
||
if ($find['online_state'] != intval($data['online_state'])) {
|
||
$up['online_state'] = $data['online_state'];
|
||
}
|
||
// 判断活动类型
|
||
if ($find['coupon_type'] != intval($data['coupon_type'])) {
|
||
$up['coupon_type'] = intval($data['coupon_type']) ? intval($data['coupon_type']) : 0;
|
||
}
|
||
//plus时长
|
||
if ($find['time'] != intval($data['time'])) {
|
||
$up['time'] = intval($data['time']) ? intval($data['time']) : 0;
|
||
}
|
||
//分期偿还:0.关闭,1.开启.
|
||
if ($find['aging_repay'] != intval($data['aging_repay'])) {
|
||
$up['aging_repay'] = intval($data['aging_repay']) ? intval($data['aging_repay']) : 0;
|
||
}
|
||
//分期时间
|
||
if ($find['aging_time'] != intval($data['aging_time'])) {
|
||
$up['aging_time'] = intval($data['aging_time']) ? intval($data['aging_time']) : 0;
|
||
}
|
||
// 判断活动
|
||
if ($data['coupon_type'] || intval($data['coupon_type']) != 0) {
|
||
if ($find['coupon_id'] != $data['coupon_id']) {
|
||
$up['coupon_id'] = $data['coupon_id'] ? $data['coupon_id'] : 0;
|
||
}
|
||
} else {
|
||
$up['coupon_id'] = 0;
|
||
}
|
||
// 二次判断修改提交
|
||
if (empty($up)) {
|
||
$res = array('status' => 0, 'msg' => '请修改后再提交');
|
||
return $res;
|
||
}
|
||
// 修改
|
||
$save_reult = $RVRModel->updateOrder($map, $up);
|
||
if ($save_reult) {
|
||
$res = array('status' => 1, 'msg' => '编辑成功');
|
||
} else {
|
||
$res = array('status' => 0, 'msg' => '编辑失败');
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取充值记录
|
||
*
|
||
*/
|
||
public function getVipRechargeRecord()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
$page = intval(I('post.page'));
|
||
$limit = intval(I('post.limit'));
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询记录
|
||
$ROModel = new RetailRechargeOrderModel();
|
||
$map = array(
|
||
'r.merchant_id' => $merchant_id,
|
||
'r.status' => 1,
|
||
'r.state' => 1,
|
||
'r.type' => 1,
|
||
'r.vip_recharge_id' => $id,
|
||
);
|
||
$field = array('r.money', 'r.all_money', 'r.add_time', 'v.name', 'v.nickname', 'v.mobile_phone');
|
||
$viprechargeRecord = $ROModel->getVipRechargeList($map, $field, $page, $limit);
|
||
if (empty($viprechargeRecord)) {
|
||
$res = array('status' => 0, 'msg' => '暂无充值记录');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 统计数量
|
||
$count = $ROModel->getVipRechargeCount($map);
|
||
// 处理数据
|
||
foreach ($viprechargeRecord as $key => &$val) {
|
||
$val['add_time'] = date('Y-m-d H:i:s', $val['add_time']);
|
||
$val['money'] = floatval($val['money']);
|
||
$val['all_money'] = floatval($val['all_money']);
|
||
$val['name'] = $val['name'] ? $val['name'] : '未设置';
|
||
$val['nickname'] = $val['nickname'] ? $val['nickname'] : '未设置';
|
||
$val['mobile_phone'] = $val['mobile_phone'] ? $val['mobile_phone'] : '未设置';
|
||
}
|
||
$res = array('status' => 1, 'viprechargeRecord' => $viprechargeRecord, 'recordLen' => intval($count));
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 删除活动
|
||
* @param $id int 活动id
|
||
* @return $res array
|
||
*/
|
||
public function deleteActivity()
|
||
{
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
if (!$id) {
|
||
$res = array('status' => 0, 'msg' => '参数缺失');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询
|
||
$RVRModel = D('RetailVipRecharge');
|
||
$map = array(
|
||
'id' => $id,
|
||
'merchant_id' => $merchant_id,
|
||
'status' => 1
|
||
);
|
||
$find = $RVRModel->getFind($map);
|
||
if (empty($find)) {
|
||
$res = array('status' => 0, 'msg' => '活动异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 删除活动
|
||
$find = $RVRModel->updateOrder($map, array('status' => 2));
|
||
if ($find) {
|
||
$res = array('status' => 1, 'msg' => '删除成功');
|
||
} else {
|
||
$res = array('status' => 0, 'msg' => '删除失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
/**
|
||
* 开启,关闭活动
|
||
* @param $id int 活动id
|
||
* @param $state int 活动状态
|
||
* @return $res array
|
||
*/
|
||
public function updateState()
|
||
{
|
||
try {
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
$state = I('post.state');
|
||
if (!$id || !in_array($state, array(0, 1))) {
|
||
$res = array('status' => 0, 'msg' => '缺失参数,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询
|
||
$RVRModel = D('RetailVipRecharge');
|
||
$map = array(
|
||
'id' => $id,
|
||
'status' => 1,
|
||
'state' => array('neq', $state)
|
||
);
|
||
$find_result = $RVRModel->getFind($map);
|
||
// 判断
|
||
if (!$find_result) {
|
||
throw new \Exception("异常操作");
|
||
}
|
||
// 修改
|
||
$save_reult = $RVRModel->updateOrder(array('id' => $id), array('state' => $state));
|
||
if ($save_reult) {
|
||
$res = array('status' => 1, 'msg' => '修改成功');
|
||
} else {
|
||
$res = array('status' => 0, 'msg' => '修改失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
} catch (\Exception $e) {
|
||
// 异常操作,抛出错误
|
||
$res = array('status' => 0, 'msg' => '操作异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开启,关闭线下活动
|
||
* @param $id int 活动id
|
||
* @param $state int 活动状态
|
||
* @return $res array
|
||
*/
|
||
public function updateLineState()
|
||
{
|
||
try {
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
$state = I('post.state');
|
||
if (!$id || !in_array($state, array(0, 1))) {
|
||
$res = array('status' => 0, 'msg' => '缺失参数,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询
|
||
$RVRModel = D('RetailVipRecharge');
|
||
$map = array(
|
||
'id' => $id,
|
||
'status' => 1,
|
||
'line_state' => array('neq', $state)
|
||
);
|
||
$find_result = $RVRModel->getFind($map);
|
||
// 判断
|
||
if (!$find_result) {
|
||
throw new \Exception("异常操作");
|
||
}
|
||
// 修改
|
||
$save_reult = $RVRModel->updateOrder(array('id' => $id), array('line_state' => $state));
|
||
if ($save_reult) {
|
||
$res = array('status' => 1, '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 = array('status' => 0, 'msg' => '修改失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
} catch (\Exception $e) {
|
||
// 异常操作,抛出错误
|
||
$res = array('status' => 0, 'msg' => '操作异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开启,关闭线上活动
|
||
* @param $id int 活动id
|
||
* @param $state int 活动状态
|
||
* @return $res array
|
||
*/
|
||
public function updateOnlineState()
|
||
{
|
||
try {
|
||
// 获取缓存
|
||
$merchant_id = I('session.merchant_userinfo')['id'];
|
||
// 判断登录
|
||
if (!$merchant_id) {
|
||
$res = array('status' => 0, 'msg' => '登录超时');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 接受数据
|
||
$id = I('post.id');
|
||
$state = I('post.state');
|
||
if (!$id || !in_array($state, array(0, 1))) {
|
||
$res = array('status' => 0, 'msg' => '缺失参数,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
// 查询
|
||
$RVRModel = D('RetailVipRecharge');
|
||
$map = array(
|
||
'id' => $id,
|
||
'status' => 1,
|
||
'online_state' => array('neq', $state)
|
||
);
|
||
$find_result = $RVRModel->getFind($map);
|
||
// 判断
|
||
if (!$find_result) {
|
||
throw new \Exception("异常操作");
|
||
}
|
||
// 修改
|
||
$save_reult = $RVRModel->updateOrder(array('id' => $id), array('online_state' => $state));
|
||
if ($save_reult) {
|
||
$res = array('status' => 1, '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 = array('status' => 0, 'msg' => '修改失败');
|
||
}
|
||
$this->ajaxReturn($res);
|
||
} catch (\Exception $e) {
|
||
// 异常操作,抛出错误
|
||
$res = array('status' => 0, 'msg' => '操作异常,请刷新重试');
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
}
|