作者 jinglong
1 个管道 的构建 通过 耗费 7 秒

增加优惠券后台和接口

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 品牌优惠券管理
*
* @icon fa fa-circle-o
*/
class Bcoupon extends Backend
{
/**
* Coupon模型对象
* @var \app\admin\model\Coupon
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Coupon;
$this->assign('c_type',['无门槛','有门槛']);
$this->assign('r_type',['满减券','折扣券']);
$this->assign('coupon_type',['减少券','折扣券']);
$this->assign('is_new',['否','是']);
//品牌
$res = Db::name('btype')->field('id,name,address')->select();
$arr = [];
foreach($res as $value){
$arr[$value['id']] = $value['name'].'------'.$value['address'];
}
$this->assign('btype',$arr);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['btype'])
->where($where)
->where('type',1)
->order($sort, $order)
->count();
$list = $this->model
->with(['btype'])
->where($where)
->where('type',1)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('btype')->visible(['name','address']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$row->end_time = date('Y-m-d H:i:s',$row->end_time);
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
... ... @@ -3,9 +3,12 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 优惠券管理
* 全场优惠券管理
*
* @icon fa fa-circle-o
*/
... ... @@ -24,6 +27,8 @@ class Coupon extends Backend
$this->model = new \app\admin\model\Coupon;
$this->assign('c_type',['无门槛','有门槛']);
$this->assign('r_type',['满减券','折扣券']);
$this->assign('coupon_type',['减少券','折扣券']);
$this->assign('is_new',['否','是']);
}
/**
... ... @@ -53,18 +58,20 @@ class Coupon extends Backend
$total = $this->model
->where($where)
->where('type',0)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->where('type',0)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','c_type','type','reduce','discount','coupon_number','createtime']);
$row->visible(['id','c_type','is_new','type','reduce','discount','coupon_number','createtime','coupon_type','end_time','coupon_name']);
}
$list = collection($list)->toArray();
... ... @@ -74,4 +81,148 @@ class Coupon extends Backend
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$row->end_time = date('Y-m-d H:i:s',$row->end_time);
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 商品优惠券管理
*
* @icon fa fa-circle-o
*/
class Gcoupon extends Backend
{
/**
* Coupon模型对象
* @var \app\admin\model\Coupon
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Coupon;
$this->assign('c_type',['无门槛','有门槛']);
$this->assign('r_type',['满减券','折扣券']);
$this->assign('coupon_type',['减少券','折扣券']);
$this->assign('is_new',['否','是']);
//品牌
$res = Db::name('goods')->field('id,name')->useSoftDelete('deletetime')->select();
$arr = [];
foreach($res as $value){
$arr[$value['id']] = $value['name'];
}
$this->assign('goods',$arr);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['goods'])
->where($where)
->where('coupon.type',2)
->order($sort, $order)
->count();
$list = $this->model
->with(['goods'])
->where($where)
->where('coupon.type',2)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->getRelation('goods')->visible(['name']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
$params['end_time'] = strtotime($params['end_time']);
//无门槛,有门槛
if($params['c_type'] == 0){
//无门槛
if($params['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($params['full_reduce']);
unset($params['discount']);
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($params['full_reduce']);
unset($params['reduce']);
}
}else{
//有门槛
if($params['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($params['discount']);
}else{
//折扣券,去掉减少金额字段,
unset($params['reduce']);
}
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$row->end_time = date('Y-m-d H:i:s',$row->end_time);
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'ID',
'Bg_name' => '品牌名称',
'Bg_address' => '品牌产地',
'Is_new' => '新人专享',
'Bg_id' => '品牌分类',
'Coupon_name' => '优惠券名称',
'C_type' => '优惠券类型',
'Coupon_type' => '优惠类型',
'Full_reduce' => '满减金额',
'Reduce' => '减少金额',
'Discount' => '折扣(折)',
'Coupon_number' => '优惠券数量',
'End_time' => '有效期',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
... ... @@ -3,10 +3,14 @@
return [
'Id' => 'ID',
'C_type' => '优惠券类型',
'Coupon_type' => '优惠类型',
'Is_new' => '新人专享',
'Full_reduce' => '满减金额',
'Coupon_name' => '优惠券名称',
'Reduce' => '减少金额',
'Discount' => '折扣',
'Discount' => '折扣(折)',
'Coupon_number' => '优惠券数量',
'End_time' => '有效期',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
<?php
return [
'Id' => 'ID',
'Goods' => '商品名称',
'Bg_id' => '品牌分类',
'Is_new' => '新人专享',
'C_type' => '优惠券类型',
'Coupon_name' => '优惠券名称',
'Coupon_type' => '优惠类型',
'Full_reduce' => '满减金额',
'Reduce' => '减少金额',
'Discount' => '折扣(折)',
'Coupon_number' => '优惠券数量',
'End_time' => '有效期',
'Createtime' => '创建时间',
'Updatetime' => '更新时间'
];
... ...
... ... @@ -27,9 +27,18 @@ class Coupon extends Model
protected $append = [
];
public function btype()
{
return $this->belongsTo('Btype', 'bg_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
//商品优惠券
public function goods()
{
return $this->belongsTo('Goods', 'bg_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
... ...
<?php
namespace app\admin\model;
use think\Model;
class Rcoupon extends Model
{
// 表名
protected $name = 'rcoupon';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
... ...
<style>
.full_reduce{
display: none;
}
.discount{
display: none;
}
</style>
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="1">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[is_new]', $is_new, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Bg_id')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[bg_id]', $btype, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, null, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, null, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="range(1~10)" class="form-control" name="row[discount]" type="number" value="1">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_number')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_number" data-rule="required" class="form-control" name="row[coupon_number]" type="number" value="0">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
\ No newline at end of file
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="1">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="{$row.coupon_name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[is_new]', $is_new, $row.is_new, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Bg_id')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[bg_id]', $btype, $row.bg_id, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, $row.c_type, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, $row.coupon_type, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="{$row.full_reduce|htmlentities}">
</div>
</div>
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="{$row.reduce|htmlentities}">
</div>
</div>
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="required" class="form-control" name="row[discount]" type="number" value="{$row.discount|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_number')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_number" data-rule="required" class="form-control" name="row[coupon_number]" type="number" value="{$row.coupon_number|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{$row.end_time|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
var c_type_value = $('.c_type').children('option:selected').val();
c_type(c_type_value);
var coupon_type_value = $('.coupon_type').children('option:selected').val();
coupon_type(coupon_type_value);
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
//优惠券类型
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('bcoupon/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('bcoupon/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('bcoupon/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('bcoupon/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
<!--<div class="dropdown btn-group {:$auth->check('bcoupon/multi')?'':'hide'}">-->
<!--<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
<!--<ul class="dropdown-menu text-left" role="menu">-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
<!--</ul>-->
<!--</div>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('bcoupon/edit')}"
data-operate-del="{:$auth->check('bcoupon/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
<style>
.full_reduce{
display: none;
}
.discount{
display: none;
}
</style>
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="0">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[is_new]', $is_new, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, null, ['class'=>'form-control ', 'required'=>''])}
{:build_select('row[c_type]', $c_type, null, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, null, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group">
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group">
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="required range(0~10)" class="form-control" name="row[discount]" type="number" value="0">
<input id="c-discount" data-rule="range(1~10)" class="form-control" name="row[discount]" type="number" value="1">
</div>
</div>
<div class="form-group">
... ... @@ -31,11 +57,9 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2"></label>
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<h4>优惠券分:无门槛,有门槛,默认初始都为0,根据需求自行填写;</h4>
<h5>无门槛:满减金额默认0.00,填写减少金额或者折扣</h5>
<h5>有门槛:满减金额必填项(不为0.00),填写减少金额或者折扣</h5>
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
... ... @@ -46,3 +70,40 @@
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
\ No newline at end of file
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="0">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-c_type" data-rule="required" class="form-control" name="row[c_type]" type="number" value="{$row.c_type|htmlentities}">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="{$row.coupon_name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-type" data-rule="required" class="form-control" name="row[type]" type="number" value="{$row.type|htmlentities}">
{:build_select('row[is_new]', $is_new, $row.is_new, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, $row.c_type, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, $row.coupon_type, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="{$row.full_reduce|htmlentities}">
</div>
</div>
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="{$row.reduce|htmlentities}">
</div>
</div>
<div class="form-group">
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="required" class="form-control" name="row[discount]" type="number" value="{$row.discount|htmlentities}">
... ... @@ -30,6 +48,12 @@
<input id="c-coupon_number" data-rule="required" class="form-control" name="row[coupon_number]" type="number" value="{$row.coupon_number|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{$row.end_time|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ... @@ -38,3 +62,47 @@
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
var c_type_value = $('.c_type').children('option:selected').val();
c_type(c_type_value);
var coupon_type_value = $('.coupon_type').children('option:selected').val();
coupon_type(coupon_type_value);
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
//优惠券类型
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
... ...
<style>
.full_reduce{
display: none;
}
.discount{
display: none;
}
</style>
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="2">
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[is_new]', $is_new, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[bg_id]', $goods, null, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, null, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, null, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="0.00">
</div>
</div>
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="range(1~10)" class="form-control" name="row[discount]" type="number" value="1">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_number')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_number" data-rule="required" class="form-control" name="row[coupon_number]" type="number" value="0">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
\ No newline at end of file
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<input name="row[type]" type="hidden" value="2">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_name" class="form-control" data-rule="required" name="row[coupon_name]" type="text" value="{$row.coupon_name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_new')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[is_new]', $is_new, $row.is_new, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[bg_id]', $goods, $row.bg_id, ['class'=>'form-control', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('C_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[c_type]', $c_type, $row.c_type, ['class'=>'form-control c_type', 'required'=>''])}
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_type')}:</label>
<div class="col-xs-12 col-sm-8">
{:build_select('row[coupon_type]', $coupon_type, $row.coupon_type, ['class'=>'form-control coupon_type', 'required'=>''])}
</div>
</div>
<div class="form-group full_reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Full_reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-full_reduce" class="form-control" step="0.01" name="row[full_reduce]" type="number" value="{$row.full_reduce|htmlentities}">
</div>
</div>
<div class="form-group reduce">
<label class="control-label col-xs-12 col-sm-2">{:__('Reduce')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-reduce" class="form-control" step="0.01" name="row[reduce]" type="number" value="{$row.reduce|htmlentities}">
</div>
</div>
<div class="form-group discount">
<label class="control-label col-xs-12 col-sm-2">{:__('Discount')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-discount" data-rule="required" class="form-control" name="row[discount]" type="number" value="{$row.discount|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Coupon_number')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-coupon_number" data-rule="required" class="form-control" name="row[coupon_number]" type="number" value="{$row.coupon_number|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('End_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[end_time]" type="text" value="{$row.end_time|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
$(function(){
var c_type_value = $('.c_type').children('option:selected').val();
c_type(c_type_value);
var coupon_type_value = $('.coupon_type').children('option:selected').val();
coupon_type(coupon_type_value);
//无门槛,有门槛
$('.c_type').change(function(){
var t_value = $(this).children('option:selected').val();//这就是selected的值
c_type(t_value);
});
//减少券,折扣券
$('.coupon_type').change(function(){
var coupon_value = $(this).children('option:selected').val();//这就是selected的值
coupon_type(coupon_value);
})
});
//优惠券类型
function c_type(t_value){
if(t_value == 0){
//无门槛,不显示
$('.full_reduce').css('display','none');
}else{
//有门槛,显示
$('.full_reduce').css('display','block');
}
}
//优惠类型
function coupon_type(coupon_value){
if(coupon_value == 0){
//减少券,减少金额显示,折扣金额隐藏
$('.reduce').css('display','block');
$('.discount').css('display','none');
}else{
//折扣券,折扣金额显示,减少金额隐藏
$('.reduce').css('display','none');
$('.discount').css('display','block');
}
}
</script>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('gcoupon/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('gcoupon/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('gcoupon/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('gcoupon/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
<!--<div class="dropdown btn-group {:$auth->check('gcoupon/multi')?'':'hide'}">-->
<!--<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
<!--<ul class="dropdown-menu text-left" role="menu">-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
<!--<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
<!--</ul>-->
<!--</div>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('gcoupon/edit')}"
data-operate-del="{:$auth->check('gcoupon/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -69,6 +69,37 @@ class Common
}
/**
* 查找多条数据
* @ApiInternal
*/
public static function selectWhereOrData($table,$where,$where1,$field,$order='id desc'){
$res = Db::name($table)
->where($where)
->whereOr($where1)
->field($field)
->order($order)
->select();
return $res;
}
/**
* 查找多条数据
* @ApiInternal
*/
public static function selectWherePageData($table,$where,$field,$page,$limit='',$order='id desc'){
if($limit == ''){
$limit = config('verify.limit');
}
$res = Db::name($table)
->where($where)
->field($field)
->page($page,$limit)
->order($order)
->select();
return $res;
}
/**
* 查找多条数据(软删除)
* @ApiInternal
*/
... ... @@ -162,11 +193,13 @@ class Common
}
/**
* 查询总
* 查询总
* @ApiInternal
*/
public static function count($table,$where){
$limit = config('verify.limit');
public static function count($table,$where,$limit=''){
if($limit == ''){
$limit = config('verify.limit');
}
$count = Db::name($table)
->where($where)
->count();
... ... @@ -174,7 +207,18 @@ class Common
}
/**
* 查询总条数(软删除)
* 查询总条数
* @ApiInternal
*/
public static function count_count($table,$where){
$count = Db::name($table)
->where($where)
->count();
return $count;
}
/**
* 查询总页数(软删除)
* @ApiInternal
*/
public static function countSoft($table,$where){
... ... @@ -203,6 +247,7 @@ class Common
}
}else{
if($is_news == 1){
//旧人
$where['is_new'] = 0;
}
$res = Common::selectSoftWherePageData('goods',$where,'id,image,name,tag,style,sale_price,expense_price,is_new',$page,$limit,$order);
... ...
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Validate;
/**
* 优惠券接口
*/
class Coupons extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $uid = '';
public function _initialize()
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
}
/**
* @ApiTitle (领券中心)
* @ApiSummary (领券中心)
* @ApiMethod (GET)
* @ApiRoute (/api/coupons/couponCenterList)
*
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575365883",
"data": {
"data": [
{
"id": 2,//优惠券id
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_name": "全场优惠券",//优惠券名称
"coupon_number": 100,//优惠券剩余数量(0:领光了)
"type": "全场通用"//优惠券用途
},
{
"id": 11,
"coupon_tag": "无门槛",
"coupon_price": "¥100",
"coupon_tag1": "无门槛",
"is_receive": 0,
"coupon_name": "品牌箱包优惠券",
"coupon_number": 100,
"type": "部分品牌可用"
},
],
"total_page": 1//总页码
}
})
*/
public function couponCenterList(){
if($this->request->isGet()){
$page = $this->request->get('page');
$rule = config('verify.page');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$flag = config('verify.flag');
$where = ['is_new'=>$flag[0],'coupon_number'=>['<>',0],'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$limit = config('verify.goods_limit');
$data = Common::selectWherePageData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number',$page,$limit,'c_type asc,coupon_type desc');
$res = [];
$arr = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '无门槛';
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '无门槛';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满减券';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}
}
$res[$key]['is_receive'] = 0;//未领取
if(in_array($value['id'],$receive_s)){
$res[$key]['is_receive'] = 1;//已领取
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['coupon_number'] = $value['coupon_number'];//优惠券剩余数量
//全场,品牌,商品
if($value['type'] == 0){
$res[$key]['type'] = '全场通用';
}else if($value['type'] == 1){
$res[$key]['type'] = '部分品牌可用';
}else{
$res[$key]['type'] = '部分商品可用';
}
}
$arr['data'] = $res;
//总页数
$arr['total_page'] = Common::count('coupon',$where,$limit);
$this->success('成功',$arr);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (品牌优惠券)
* @ApiSummary (品牌优惠券)
* @ApiMethod (GET)
* @ApiRoute (/api/coupons/brandCouponList)
*
* @ApiParams (name="b_id", type="inter", required=true, description="品牌分类id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575367045",
"data": [
{
"id": 5,优惠券id
"coupon_number": 100,//优惠券剩余数量(0:显示领光了)
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_tag": "无门槛",//优惠券(无门槛或满减金额)
"coupon_price": "¥100"//(折扣或减少金额)
},
{
"id": 11,
"coupon_number": 100,
"is_receive": 0,
"coupon_tag": "无门槛",
"coupon_price": "¥100"
}
]
})
*/
public function brandCouponList(){
if($this->request->isGet()){
$b_id = $this->request->get('b_id');
$rule = config('verify.brand_detail');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['b_id'=>$b_id])) {
$this->error($validate->getError());
}
$flag = config('verify.flag');
$where = ['is_new'=>$flag[0],'type'=>$flag[1],'bg_id'=>$b_id,'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$data = Common::selectWhereData('coupon',$where,'id,c_type,coupon_type,full_reduce,reduce,discount,coupon_number','c_type asc,coupon_type desc');
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
$res[$key]['coupon_number'] = $value['coupon_number'];
$res[$key]['is_receive'] = 0;//未领取
if(in_array($value['id'],$receive_s)){
$res[$key]['is_receive'] = 1;//已领取
}
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (商品优惠券)
* @ApiSummary (商品优惠券)
* @ApiMethod (GET)
* @ApiRoute (/api/coupons/goodsCouponList)
*
* @ApiParams (name="goods_id", type="inter", required=true, description="商品id")
* @ApiParams (name="is_flag", type="inter", required=true, description="优惠券标识(0:未使用,1:已使用,2:已过期)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575372162",
"data": [
{
"id": 2,//优惠券id
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"coupon_name": "全场优惠券",//优惠券名称
"end_time": "2020.1.31",//优惠券有效期
"type": "全场通用"//优惠券用途
},
{
"id": 10,
"coupon_tag": "折扣券",
"coupon_price": "9.5折",
"coupon_tag1": "满2000可用",
"coupon_name": "商品优惠券",
"end_time": "2020.1.31",
"type": "商品可用"
}
]
})
*/
public function goodsCouponList(){
if($this->request->isGet()){
$goods_id = $this->request->get('goods_id');
$is_flag = $this->request->get('is_flag');
$rule = config('verify.goods_coupon');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['goods_id'=>$goods_id,'is_flag'=>$is_flag])) {
$this->error($validate->getError());
}
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$type = config('verify.type');
$flag = config('verify.flag');
//不显示没有库存的优惠券
$where = ['is_new'=>$flag[0],'type'=>$type[2],'bg_id'=>$goods_id,'coupon_number'=>['<>',0]];
if($is_flag == 0){
//未使用
$where['id'] = ['not in',$receive_s];
$where['end_time'] = ['>',time()];
}else if($is_flag == 1){
//已使用
$where['id'] = ['in',$receive_s];
$where['end_time'] = ['>',time()];
}else{
//已过期
$where['end_time'] = ['<',time()];
}
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '无门槛';
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '无门槛';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满减券';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
$res[$key]['type'] = '商品可用';
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -43,6 +43,7 @@ class Goods extends Api
"expense_price": 0,//运费(0:显示包运费标签)
"is_collection": 0,//是否收藏(0:否,1:是)
"is_new_tag": 0//新人价格标签(0:不显示,1:显示)
"is_use_number": 0//优惠券可领取数量
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
... ... @@ -128,10 +129,22 @@ class Goods extends Api
}else{
$res['is_new_tag'] = 0;//不用显示新人价标签(新人价标签商品不会出来)
}
unset($res['is_new']);
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$type = config('verify.type');
$flag = config('verify.flag');
$where = ['id'=>['not in',$receive_s],'is_new'=>$flag[0],'type'=>$type[2],'bg_id'=>$goods_id,'end_time'=>['>',time()]];
$coupon_number = Common::count_count('coupon',$where);
$res['is_use_number'] = $coupon_number;
//浏览商品增加次数
$goodsModel = new \app\admin\model\Goods();
$goodsModel->where(['id'=>$goods_id])->setInc('hots',1);
unset($res['is_new']);
}
$this->success('成功',$res);
}else{
... ...
... ... @@ -2,6 +2,8 @@
namespace app\api\controller;
use app\admin\model\Coupon;
use app\admin\model\Rcoupon;
use app\admin\model\Record;
use app\common\controller\Api;
use think\Validate;
... ... @@ -10,7 +12,7 @@ use think\Validate;
*/
class News extends Api
{
protected $noNeedLogin = ['newsGoodsList'];
protected $noNeedLogin = ['newsCouponList','newsGoodsList'];
protected $noNeedRight = ['*'];
protected $uid = '';
public function _initialize()
... ... @@ -20,6 +22,144 @@ class News extends Api
}
/**
* @ApiTitle (领取优惠券)
* @ApiSummary (领取优惠券)
* @ApiMethod (POST)
* @ApiRoute (/api/news/receiveAllCoupon)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="coupon_id", type="string", required=true, description="优惠券id(多个以逗号隔开)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575358991",
"data": null
})
*/
public function receiveAllCoupon(){
if($this->request->isPost()){
$coupon_id = $this->request->post('coupon_id');
$rule = config('verify.receive_coupon');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['coupon_id'=>$coupon_id])) {
$this->error($validate->getError());
}
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$coupon_id_s = explode(',',$coupon_id);
$arr = [];
$k = 0;
foreach($coupon_id_s as $value){
$k+=0;
if(!in_array($value,$receive_s)){
$arr[$k]['c_id'] = $value;
$arr[$k]['uid'] = $this->uid;
$k++;
}
}
$r_couponModel = new Rcoupon();
$res = $r_couponModel->saveAll($arr);
if($res){
//减优惠券数量
$couponModel = new Coupon();
$couponModel->whereIn('id',$coupon_id_s)->setDec('coupon_number',1);
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (新人专享礼包)
* @ApiSummary (新人专享礼包)
* @ApiMethod (GET)
* @ApiRoute (/api/news/newsCouponList)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575352892",
"data":[
{
"id": 4,//优惠券id
"is_receive": 0,//是否领取(0:否,1:是)
"coupon_tag": "无门槛",//优惠券(无门槛或满减金额)
"coupon_price": "8.5折"//(折扣或减少金额)
},
{
"id": 2,
"coupon_tag": "无门槛",
"coupon_price": "¥300"
},
{
"id": 1,
"coupon_tag": "满1000可用",
"coupon_price": "¥200"
}
]
})
*/
public function newsCouponList(){
if($this->request->isGet()){
$flag = config('verify.flag');
$where = ['is_new'=>$flag[1],'coupon_number'=>['<>',0],'end_time'=>['>',time()]];
//查询已经领取过
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid],'id,c_id');
$receive_s = array_column($receive,'c_id');
$data = Common::selectWhereData('coupon',$where,'id,c_type,coupon_type,full_reduce,reduce,discount','c_type asc,coupon_type desc');
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
$res[$key]['is_receive'] = 0;//未领取
if(in_array($value['id'],$receive_s)){
$res[$key]['is_receive'] = 1;//已领取
}
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '满'.$value['full_reduce'].'可用';
$res[$key]['coupon_price'] = $value['discount'].'折';
}
}
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (新人特惠商品列表)
* @ApiSummary (新人特惠商品列表)
* @ApiMethod (GET)
... ...
... ... @@ -123,6 +123,7 @@ class Pay extends Api
* @ApiParams (name="goods_number", type="string", required=true, description="商品数量(多个以逗号隔开,如:10,10,10)")
* @ApiParams (name="style", type="string", required=true, description="商品款式(多个以逗号隔开,如:‘款式1,款式2,款式3’)")
* @ApiParams (name="leave_message", type="string", required=false, description="留言")
* @ApiParams (name="coupon_id", type="inter", required=true, description="优惠券id")
*
* @ApiParams (name="total_goods_price", type="inter", required=true, description="商品总金额")
* @ApiParams (name="discount_price", type="inter", required=true, description="优惠金额")
... ...
... ... @@ -318,5 +318,129 @@ class User extends Api
}
}
/**
* @ApiTitle (我的优惠券)
* @ApiSummary (我的优惠券)
* @ApiMethod (GET)
* @ApiRoute (/api/user/myCouponList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="goods_id", type="string", required=false, description="商品id(多个以逗号隔开,如:1,3,4)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1575372162",
"data": [
{
"id": 2,//优惠券id
"coupon_tag": "无门槛",//优惠券(无门槛,折扣券,满减券)
"coupon_price": "¥300",//(折扣或减少金额)
"coupon_tag1": "无门槛",优惠券(无门槛,满多少可用)
"coupon_name": "全场优惠券",//优惠券名称
"end_time": "2020.1.31",//优惠券有效期
"type": "全场通用"//优惠券用途
},
{
"id": 10,
"coupon_tag": "折扣券",
"coupon_price": "9.5折",
"coupon_tag1": "满2000可用",
"coupon_name": "商品优惠券",
"end_time": "2020.1.31",
"type": "商品可用"
}
]
})
*/
public function myCouponList(){
if($this->request->isGet()){
$goods_id = $this->request->get('goods_id');
//查询已经领取过
$flag = config('verify.flag');
$type = config('verify.type');
$receive = Common::selectWhereData('rcoupon',['uid'=>$this->uid,'is_use'=>$flag[0]],'id,c_id');
$receive_s = array_column($receive,'c_id');
if($goods_id){
$goods_id_s = explode(',',$goods_id);
//查询商品所属品牌id
$res1 = Common::selectSoftWhereData('goods',['id'=>['in',$goods_id_s],'type'=>$flag[1],],'id,t_id');
$b_id_s = array_unique(array_values(array_column($res1,'t_id')));
//包含品牌中的商品
$time = time();
$where2['id'] = ['in',$receive_s];
$where2['end_time'] = ['>',$time];
$where2['bg_id'] = ['in',$b_id_s];
$where2['type'] = $type[1];
//普通商品
$where1['id'] = ['in',$receive_s];
$where1['end_time'] = ['>',$time];
$where1['bg_id'] = ['in',$goods_id_s];
$where1['type'] = $type[2];
$data = Common::selectWhereOrData('coupon',$where1,$where2,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
}else{
$where['id'] = ['in',$receive_s];
$data = Common::selectWhereData('coupon',$where,'id,type,coupon_name,c_type,coupon_type,full_reduce,reduce,discount,coupon_number,end_time','c_type asc,coupon_type desc');
}
$res = [];
foreach($data as $key=>$value){
$res[$key]['id'] = $value['id'];
//无门槛,有门槛
if($value['c_type'] == 0){
//无门槛
if($value['coupon_type'] == 0){
//减少券,去掉满减金额,折扣字段,
unset($value['full_reduce']);
unset($value['discount']);
$res[$key]['coupon_tag'] = '无门槛';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '无门槛';
}else{
//折扣券,去掉满减金额,减少金额字段,
unset($value['full_reduce']);
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '无门槛';
}
}else{
//有门槛
if($value['coupon_type'] == 0){
//减少券,去掉折扣字段,
unset($value['discount']);
$res[$key]['coupon_tag'] = '满减券';
$res[$key]['coupon_price'] = '¥'.$value['reduce'];
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}else{
//折扣券,去掉减少金额字段,
unset($value['reduce']);
$res[$key]['coupon_tag'] = '折扣券';
$res[$key]['coupon_price'] = $value['discount'].'折';
$res[$key]['coupon_tag1'] = '满'.$value['full_reduce'].'可用';
}
}
$res[$key]['coupon_name'] = $value['coupon_name'];//优惠券名称
$res[$key]['end_time'] = date('Y.n.j',$value['end_time']);//优惠券有效期
//全场,品牌,商品
if($value['type'] == 0){
$res[$key]['type'] = '全场通用';
}else if($value['type'] == 1){
$res[$key]['type'] = '部分品牌可用';
}else{
$res[$key]['type'] = '部分商品可用';
}
}
$this->success('成功',$res);
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -25,6 +25,8 @@ return [
// 'flag' => [0,1,2,3],//0:普通,1:推荐,2:设计师作品,3:新人特惠
'flag' => [0,1],//0:否,1:是
'status' => [0,1,2,3],//0:待付款,1:待发货,2:待收货,3:已完成
//优惠券类型
'type' => [0,1,2],//0:全场,1:品牌,2:商品
//分页数
'limit' => 10,
//商品分页
... ... @@ -174,6 +176,7 @@ return [
'price' => 'require',
'goods_number' => 'require',
'style' => 'require',
'coupon_id' => 'require|number',
'total_goods_price' => 'require|number',
'discount_price' => 'require|number',
'total_expense_price'=> 'require|number',
... ... @@ -187,6 +190,8 @@ return [
'price.require' => '商品价格不能为空',
'goods_number.require' => '商品数量不能为空',
'style.require' => '商品款式不能为空',
'coupon_id.require' => '优惠券id不能为空',
'coupon_id.number' => '优惠券id必须是数字',
'total_goods_price.require' => '商品总金额不能为空',
'total_goods_price.number' => '商品总金额必须为数字',
'discount_price.require' => '优惠金额不能为空',
... ... @@ -206,4 +211,26 @@ return [
'pay_order_sn.require' => '支付订单号不能为空',
]
],
//一键领取优惠券
'receive_coupon' => [
'rule' => [
'coupon_id' => 'require',
],
'msg' => [
'coupon_id.require' => '优惠券id不能为空',
]
],
//商品优惠券
'goods_coupon' => [
'rule' => [
'goods_id' => 'require|number',
'is_flag' => 'require|number',
],
'msg' => [
'goods_id.require' => '商品id不能为空',
'goods_id.number' => '商品id必须为数字',
'is_flag.require' => '优惠券标识不能为空',
'is_flag.number' => '优惠券标识必须为数字',
]
],
];
\ No newline at end of file
... ...
此 diff 太大无法显示。
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'bcoupon/index' + location.search,
add_url: 'bcoupon/add',
edit_url: 'bcoupon/edit',
del_url: 'bcoupon/del',
multi_url: 'bcoupon/multi',
table: 'bcoupon',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'coupon_name', title: __('Coupon_name')},
{field: 'btype.name', title: __('Bg_name')},
{field: 'btype.address', title: __('Bg_address')},
{field: 'c_type', title: __('C_type'),searchList: {0: __('无门槛'), 1: __('有门槛')},formatter:
function(value,row,index){
if (row.c_type === 0)
{
return '<span style="color:green">无门槛</span>';
}else if (row.c_type === 1)
{
return '<span style="color:red">有门槛</span>';
}
}
},
{field: 'coupon_type', title: __('coupon_type'),searchList: {0: __('减少券'), 1: __('折扣券')},formatter:
function(value,row,index){
if (row.coupon_type === 0)
{
return '<span style="color:green">减少券</span>';
}else if (row.coupon_type === 1)
{
return '<span style="color:red">折扣券</span>';
}
}
},
// {field: 'type', title: __('Type')},
{field: 'reduce', title: __('Reduce'), operate:'BETWEEN',formatter:
function(value,row){
if (row.reduce === 0)
{
return '--';
}else{
return row.reduce;
}
}
},
{field: 'discount', title: __('Discount'),formatter:
function(value,row){
if (row.discount === 0)
{
return '--';
}else{
return row.discount;
}
}
},
{field: 'coupon_number', title: __('coupon_number')},
{field: 'is_new', title: __('Is_new'),formatter: Table.api.formatter.label,searchList: {0: __('否'), 1: __('是')}},
{field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -25,11 +25,53 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'c_type', title: __('C_type')},
{field: 'coupon_name', title: __('Coupon_name')},
{field: 'c_type', title: __('C_type'),searchList: {0: __('无门槛'), 1: __('有门槛')},formatter:
function(value,row,index){
if (row.c_type === 0)
{
return '<span style="color:green">无门槛</span>';
}else if (row.c_type === 1)
{
return '<span style="color:red">有门槛</span>';
}
}
},
{field: 'coupon_type', title: __('Coupon_type'),searchList: {0: __('减少券'), 1: __('折扣券')},formatter:
function(value,row,index){
if (row.coupon_type === 0)
{
return '<span style="color:green">减少券</span>';
}else if (row.coupon_type === 1)
{
return '<span style="color:red">折扣券</span>';
}
}
},
// {field: 'type', title: __('Type')},
{field: 'reduce', title: __('Reduce'), operate:'BETWEEN'},
{field: 'discount', title: __('Discount')},
{field: 'reduce', title: __('Reduce'), operate:'BETWEEN',formatter:
function(value,row){
if (row.reduce === 0)
{
return '--';
}else{
return row.reduce;
}
}
},
{field: 'discount', title: __('Discount'),formatter:
function(value,row){
if (row.discount === 0)
{
return '--';
}else{
return row.discount;
}
}
},
{field: 'coupon_number', title: __('Coupon_number')},
{field: 'is_new', title: __('Is_new'),formatter: Table.api.formatter.label,searchList: {0: __('否'), 1: __('是')}},
{field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'gcoupon/index' + location.search,
add_url: 'gcoupon/add',
edit_url: 'gcoupon/edit',
del_url: 'gcoupon/del',
multi_url: 'gcoupon/multi',
table: 'gcoupon',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'coupon_name', title: __('Coupon_name')},
{field: 'goods.name', title: __('Goods')},
{field: 'c_type', title: __('C_type'),searchList: {0: __('无门槛'), 1: __('有门槛')},formatter:
function(value,row,index){
if (row.c_type === 0)
{
return '<span style="color:green">无门槛</span>';
}else if (row.c_type === 1)
{
return '<span style="color:red">有门槛</span>';
}
}
},
{field: 'coupon_type', title: __('coupon_type'),searchList: {0: __('减少券'), 1: __('折扣券')},formatter:
function(value,row,index){
if (row.coupon_type === 0)
{
return '<span style="color:green">减少券</span>';
}else if (row.coupon_type === 1)
{
return '<span style="color:red">折扣券</span>';
}
}
},
// {field: 'type', title: __('Type')},
{field: 'reduce', title: __('Reduce'), operate:'BETWEEN',formatter:
function(value,row){
if (row.reduce === 0)
{
return '--';
}else{
return row.reduce;
}
}
},
{field: 'discount', title: __('Discount'),formatter:
function(value,row){
if (row.discount === 0)
{
return '--';
}else{
return row.discount;
}
}
},
{field: 'coupon_number', title: __('coupon_number')},
{field: 'is_new', title: __('Is_new'),formatter: Table.api.formatter.label,searchList: {0: __('否'), 1: __('是')}},
{field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...