You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.7 KiB
127 lines
3.7 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace addon\hygl\app\adminapi\controller\coupons;
|
|
|
|
use core\base\BaseAdminController;
|
|
use addon\hygl\app\service\admin\coupons\CouponsService;
|
|
|
|
|
|
/**
|
|
* 优惠券控制器
|
|
* Class Coupons
|
|
* @package addon\hygl\app\adminapi\controller\coupons
|
|
*/
|
|
class Coupons extends BaseAdminController
|
|
{
|
|
/**
|
|
* 获取优惠券列表
|
|
* @return \think\Response
|
|
*/
|
|
public function lists(){
|
|
$data = $this->request->params([
|
|
["name",""],
|
|
["nominal_value",["",""]],
|
|
["is_show",""]
|
|
]);
|
|
return success((new CouponsService())->getPage($data));
|
|
}
|
|
|
|
/**
|
|
* 优惠券详情
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function info(int $id){
|
|
return success((new CouponsService())->getInfo($id));
|
|
}
|
|
|
|
/**
|
|
* 添加优惠券
|
|
* @return \think\Response
|
|
*/
|
|
public function add()
|
|
{
|
|
$data = $this->request->params([
|
|
["name", ""],
|
|
["nominal_value", 0.00],
|
|
["stock", 0],
|
|
["is_show", ""],
|
|
["is_obsolete", ""],
|
|
["is_long_term_valid", ""],
|
|
["valid_time", []],
|
|
|
|
]);
|
|
$this->validate($data, 'addon\hygl\app\validate\coupons\Coupons.add');
|
|
|
|
$data['valid_from'] = 0;
|
|
$data['valid_until'] = 0;
|
|
if (!$data['is_long_term_valid']){
|
|
//不是长期有效
|
|
if (empty($data['valid_time'][0]) || empty($data['valid_time'][1])){
|
|
return fail('有效期不能为空');
|
|
}else{
|
|
$data['valid_from'] = strtotime($data['valid_time'][0]);
|
|
$data['valid_until'] = strtotime($data['valid_time'][1]);
|
|
}
|
|
}
|
|
|
|
$id = (new CouponsService())->add($data);
|
|
return success('ADD_SUCCESS', ['id' => $id]);
|
|
}
|
|
|
|
/**
|
|
* 优惠券编辑
|
|
* @param $id 优惠券id
|
|
* @return \think\Response
|
|
*/
|
|
public function edit(int $id){
|
|
$data = $this->request->params([
|
|
["name", ""],
|
|
["nominal_value", 0.00],
|
|
["stock", 0],
|
|
["is_show", ""],
|
|
["is_obsolete", ""],//是否作废1=是
|
|
["is_long_term_valid", ""],
|
|
["valid_time", []],
|
|
|
|
]);
|
|
$this->validate($data, 'addon\hygl\app\validate\coupons\Coupons.edit');
|
|
|
|
$data['valid_from'] = 0;
|
|
$data['valid_until'] = 0;
|
|
if (!$data['is_long_term_valid']){
|
|
//不是长期有效
|
|
if (empty($data['valid_time'][0]) || empty($data['valid_time'][1])){
|
|
return fail('有效期不能为空');
|
|
}else{
|
|
$data['valid_from'] = strtotime($data['valid_time'][0]);
|
|
$data['valid_until'] = strtotime($data['valid_time'][1]);
|
|
}
|
|
}
|
|
unset($data['valid_time']);
|
|
|
|
(new CouponsService())->edit($id, $data);
|
|
return success('EDIT_SUCCESS');
|
|
}
|
|
|
|
/**
|
|
* 优惠券删除
|
|
* @param $id 优惠券id
|
|
* @return \think\Response
|
|
*/
|
|
public function del(int $id){
|
|
(new CouponsService())->del($id);
|
|
return success('DELETE_SUCCESS');
|
|
}
|
|
|
|
|
|
}
|
|
|