作者 何书鹏

发送优惠券

... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 优惠券
... ... @@ -35,6 +36,38 @@ class Coupon extends Backend
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 发送优惠券
*/
public function send_coupon()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$user_ids = $params['user_ids'];
empty($user_ids) && $this->error('请选择用户');
$coupon_id = $this->request->get('coupon_id');
empty($coupon_id) && $this->error('请选择优惠券');
$coupon = $this->model->where('id',$coupon_id)->field('id,name,price,full_price,days')->find();
$add_data = [];
$time = time();
foreach(explode(',',$user_ids) as $user_id){
$add_data[] = [
'user_id' => $user_id,
'coupon_id' => $coupon['id'],
'name' => $coupon['name'],
'price' => $coupon['price'],
'full_price' => $coupon['full_price'],
'endtime' => $time+$coupon['days']*86400,
'createtime' => $time,
];
}
Db::name('user_coupon')->insertAll($add_data);
$this->success();
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace app\admin\controller\litestore;
use app\api\model\User;
use app\api\model\RiderOrder;
use app\common\controller\Backend;
... ... @@ -27,6 +28,8 @@ class Litestoreorder extends Backend
$this->view->assign("freightStatusList", $this->model->getFreightStatusList());
$this->view->assign("receiptStatusList", $this->model->getReceiptStatusList());
$this->view->assign("orderStatusList", $this->model->getOrderStatusList());
$riderList = User::where('rider','2')->column('nickname','id');
$this->assignConfig("riderList", $riderList);
}
/**
... ... @@ -67,11 +70,12 @@ class Litestoreorder extends Backend
->select();
foreach ($list as $row) {
$row->visible(['id','order_no','total_price','pay_price','pay_status','pay_time','express_price','freight_status','freight_time','receipt_time','order_status','updatetime']);
$row->visible(['id','order_no','total_price','pay_price','pay_status','pay_time','express_price','freight_status','freight_time','receipt_time','order_status','rider_user_id','updatetime']);
$row->visible(['address']);
$row->getRelation('address')->visible(['name']);
$row->visible(['rider']);
$row->getRelation('rider')->visible(['nickname']);
$row->rider_user_id = $row->rider_user_id > 0 ? $row->rider_user_id : '';
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
... ... @@ -109,7 +113,7 @@ class Litestoreorder extends Backend
}
// 快捷匹配骑手
public function render(){
public function rider(){
if($this->request->isPost())
{
$id = input('get.ids');
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('选择用户')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_ids" data-rule="required" data-source="user/user/index" data-field="nickname" data-multiple="true" class="form-control selectpage" name="row[user_ids]" 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>
... ...
... ... @@ -37,7 +37,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'days', title: __('Days')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [
{
name: 'send_coupon',
text: '发送优惠券',
classname: 'btn btn-info btn-xs btn-dialog',
icon: 'fa fa-plus',
url: 'coupon/send_coupon?coupon_id={ids}'
}
]
}
]
]
});
... ... @@ -51,6 +61,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit: function () {
Controller.api.bindevent();
},
send_coupon: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
... ...
... ... @@ -43,6 +43,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
field: 'rider.nickname',
title: __('选择配送骑手'),
table: table,
operate: false,
events: Table.api.events.operate,
buttons: [
{
... ... @@ -51,7 +52,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
title: __('选择配送骑手'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-fighter-jet',
url: 'litestore/litestoreorder/render?ids={ids}',
url: 'litestore/litestoreorder/rider?ids={ids}',
callback: function (data) {
Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
... ... @@ -65,7 +66,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
],
formatter: Table.api.formatter.buttons
},
{field: 'rider.nickname', title: __('骑手')},
{field: 'rider_user_id', title: __('骑手'), searchList: Config.riderList, operate: 'IN', formatter: Table.api.formatter.flag},
{field: 'operate', title: __('Operate'), table: table, buttons: [
{name: 'send', text: __('view'), icon: 'fa fa-eye', classname: 'btn btn-xs btn-warning btn-dialog chakan', url: 'litestore/litestoreorder/detail'},
], events: Table.api.events.operate, formatter: Table.api.formatter.operate}
... ... @@ -116,7 +117,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
Controller.api.bindevent();
},
render: function () {
rider: function () {
Controller.api.bindevent();
},
api: {
... ...