240 行
8.7 KiB
PHP
可执行文件
240 行
8.7 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Retail\Controller;
|
||
|
||
//[1.7.14]
|
||
class CouponController extends BaseController
|
||
{
|
||
public function coupons()
|
||
{
|
||
$arr = array(
|
||
'couponSet' => '/index.php/Retail/Coupon/couponSet',
|
||
'couponLogs' => '/index.php/Retail/Coupon/couponLogs',
|
||
'changeCoupon' => '/index.php/Retail/Coupon/changeCoupon',
|
||
'deleteCoupon' => '/index.php/Retail/Coupon/deleteCoupon',
|
||
);
|
||
$authArr = checkFunction($arr);
|
||
$this->assign('authArr', $authArr);
|
||
$this->display();
|
||
}
|
||
|
||
public function couponList()
|
||
{
|
||
$where = [
|
||
'storeid' => $this->store_id,
|
||
'merchantid' => $this->merchant_id,
|
||
'status' => array('in', array(0, 1, 2)),
|
||
'end_time' => array('gt', time()),
|
||
];
|
||
if (!empty($_POST['status'])) {
|
||
if ($_POST['status'] == 1) {
|
||
//正常状态
|
||
$where['status'] = 2;
|
||
$where['end_time'] = array('gt', time());
|
||
} elseif ($_POST['status'] == 2) {
|
||
//下架
|
||
$where['status'] = 1;
|
||
} elseif ($_POST['status'] == 3) {
|
||
//过期
|
||
$where['end_time'] = array('lt', time());
|
||
} else if ($_POST['status'] == 101) {
|
||
$where['status'] = array('in', '1,2');
|
||
unset($where['end_time']);
|
||
}
|
||
}
|
||
|
||
$coupon_count = M('retail_coupon')->where($where)->count();
|
||
$coupons = M('retail_coupon')
|
||
->where($where)
|
||
->page($_POST['page'], $_POST['limit'])
|
||
->order('addtime desc')
|
||
->select();
|
||
foreach ($coupons as $key => &$value) {
|
||
$value['key'] = $key + 1;
|
||
|
||
if ($value['status'] == 2) {
|
||
$value['status_s'] = '正常';
|
||
} else {
|
||
$value['status_s'] = '已下架';
|
||
}
|
||
|
||
//如果优惠券已过期
|
||
if ($value['end_time'] < time()) {
|
||
$value['status_s'] = '已过期';
|
||
}
|
||
|
||
$value['begin_time'] = date('Y-m-d H:i:s', $value['begin_time']);
|
||
$value['end_time'] = date('Y-m-d H:i:s', $value['end_time']);
|
||
|
||
$value['receive_num'] = $value['coupon_num'] - $value['quantity'] . '张';
|
||
$value['rule'] = '满' . $value['needmoney'] . '减' . $value['reductionmoney'];
|
||
}
|
||
|
||
|
||
$res['code'] = 0;
|
||
$res['msg'] = '';
|
||
$res['data'] = $coupons;
|
||
$res['count'] = $coupon_count;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
|
||
public function couponSet()
|
||
{
|
||
if (IS_POST) {
|
||
$data = $_POST;
|
||
$data['storeid'] = $this->store_id;
|
||
$data['merchantid'] = $this->merchant_id;
|
||
$data['addtime'] = time();
|
||
$data['quantity'] = $data['coupon_num'];
|
||
|
||
//需要截取时间
|
||
$start_time = substr($data['usetime'], 0, 10);
|
||
$end_time = substr($data['usetime'], -10);
|
||
$data['begin_time'] = strtotime($start_time);//开始时间
|
||
$data['end_time'] = strtotime($end_time) + 86399;//结束时间截止到当天的23:59:59
|
||
|
||
$create = M('retail_coupon')->add($data);
|
||
if ($create) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '优惠卷-新增';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$res['status'] = 1;
|
||
$res['msg'] = '创建优惠券成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '创建失败';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
|
||
}
|
||
}
|
||
|
||
//删除优惠券(修改状态为3)
|
||
public function deleteCoupon()
|
||
{
|
||
if (IS_POST) {
|
||
$id = $_POST['id'];
|
||
if ($id) {
|
||
$change = M('retail_coupon')->where(array('id' => $id))->setField('status', 3);
|
||
if ($change) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = '优惠卷-删除';//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$res['status'] = 1;
|
||
$res['msg'] = '删除成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '删除失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '无效的参数ID';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
//修改优惠券状态
|
||
public function changeCoupon()
|
||
{
|
||
if (IS_POST) {
|
||
$id = $_POST['id'];
|
||
$status = $_POST['status'];
|
||
|
||
if ($id) {
|
||
$change = M('retail_coupon')->where(array('id' => $id))->setField('status', $status);
|
||
if ($change) {
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
if ($status == 1) {
|
||
$desc = '优惠卷-修改状态-下架优惠卷';//操作行为描述
|
||
} elseif ($status == 2) {
|
||
$desc = '优惠卷-修改状态-开启优惠卷';//操作行为描述
|
||
}
|
||
action_log($source, $type, $request_data, $desc);
|
||
|
||
$res['status'] = 1;
|
||
$res['msg'] = '切换成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '切换失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '无效的参数ID';
|
||
}
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 优惠券领取列表
|
||
*/
|
||
public function couponLogs()
|
||
{
|
||
$this->display();
|
||
}
|
||
|
||
public function couponLogsList()
|
||
{
|
||
if (IS_POST) {
|
||
$map = [
|
||
'l.storeid' => $this->store_id,
|
||
'l.merchantid' => $this->merchant_id,
|
||
];
|
||
$keyword = I('post.keyword');
|
||
if ($keyword !== '' && $keyword !== null) {
|
||
$map['x.nickname'] = ['like', '%' . $keyword . '%'];
|
||
}
|
||
$logs = M('retail_coupon_logs as l')
|
||
->join('ls_retail_xcxvip as x ON x.id=l.uid')
|
||
->where($map)
|
||
->field('l.*,x.nickname as vip_name')
|
||
->page($_POST['page'], $_POST['limit'])
|
||
->select();
|
||
$logs_count = M('retail_coupon_logs as l')
|
||
->join('ls_retail_xcxvip as x ON x.id=l.uid')
|
||
->where($map)->count();
|
||
|
||
foreach ($logs as $key => &$value) {
|
||
$value['key'] = $key + 1;
|
||
$value['vip_name'] = $value['vip_name'] ? $value['vip_name'] : '--';
|
||
if ($value['status'] == 1) {
|
||
$value['status_name'] = '未使用';
|
||
} elseif ($value['status'] == 2) {
|
||
$value['status_name'] = '已使用';
|
||
}
|
||
|
||
//判断优惠券是否有效期
|
||
$coupon = M('retail_coupon')->field('coupon_name,end_time')->where(array('id' => $value['coupon_id']))->find();
|
||
if ($coupon['end_time'] > time()) {
|
||
$value['effective'] = '可使用';
|
||
$value['end_time'] = date('Y-m-d H:i:s', $coupon['end_time']);
|
||
} else {
|
||
$value['effective'] = '已过期';
|
||
$value['end_time'] = date('Y-m-d H:i:s', $coupon['end_time']);
|
||
}
|
||
|
||
$value['addtime'] = date('Y-m-d H:i:s', $value['addtime']);
|
||
$value['coupon_name'] = $coupon['coupon_name'];
|
||
}
|
||
|
||
$res['code'] = 0;
|
||
$res['msg'] = '';
|
||
$res['data'] = $logs;
|
||
$res['count'] = $logs_count;
|
||
$this->ajaxReturn($res);
|
||
}
|
||
}
|
||
|
||
} |