diff --git a/application/admin/controller/Coupon.php b/application/admin/controller/Coupon.php index ed772d1..18ce50f 100644 --- a/application/admin/controller/Coupon.php +++ b/application/admin/controller/Coupon.php @@ -4,6 +4,8 @@ namespace app\admin\controller; use app\common\controller\Backend; use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 优惠券 @@ -70,4 +72,56 @@ class Coupon extends Backend } return $this->view->fetch(); } + + /** + * 注册设置 + */ + public function register_set($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); + } + $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', '')); + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } } diff --git a/application/admin/view/coupon/edit.html b/application/admin/view/coupon/edit.html index d7c3a45..6ceb35a 100644 --- a/application/admin/view/coupon/edit.html +++ b/application/admin/view/coupon/edit.html @@ -42,27 +42,6 @@ <input id="c-endtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[endtime]" type="text" value="{:$row.endtime?datetime($row.endtime):''}"> </div> </div> - <div class="form-group"> - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_switch')}:</label> - <div class="col-xs-12 col-sm-8"> - <input id="c-register_send_switch" name="row[register_send_switch]" type="hidden" value="{$row.register_send_switch|htmlentities}"> - <a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-register_send_switch" data-yes="1" data-no="0" > - <i class="fa fa-toggle-on text-success {eq name="$row.register_send_switch" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i> - </a> - </div> - </div> - <div class="form-group"> - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_starttime')}:</label> - <div class="col-xs-12 col-sm-8"> - <input id="c-register_send_starttime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[register_send_starttime]" type="text" value="{:$row.register_send_starttime?datetime($row.register_send_starttime):''}"> - </div> - </div> - <div class="form-group"> - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_endtime')}:</label> - <div class="col-xs-12 col-sm-8"> - <input id="c-register_send_endtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[register_send_endtime]" type="text" value="{:$row.register_send_endtime?datetime($row.register_send_endtime):''}"> - </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"> diff --git a/application/admin/view/coupon/register_set.html b/application/admin/view/coupon/register_set.html new file mode 100644 index 0000000..d3a2c19 --- /dev/null +++ b/application/admin/view/coupon/register_set.html @@ -0,0 +1,31 @@ +<form id="edit-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">{:__('Register_send_switch')}:</label> + <div class="col-xs-12 col-sm-8"> + <input id="c-register_send_switch" name="row[register_send_switch]" type="hidden" value="{$row.register_send_switch|htmlentities}"> + <a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-register_send_switch" data-yes="1" data-no="0" > + <i class="fa fa-toggle-on text-success {eq name="$row.register_send_switch" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i> + </a> + </div> + </div> + <div class="form-group"> + <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_starttime')}:</label> + <div class="col-xs-12 col-sm-8"> + <input id="c-register_send_starttime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[register_send_starttime]" type="text" value="{:$row.register_send_starttime?datetime($row.register_send_starttime):''}"> + </div> + </div> + <div class="form-group"> + <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_endtime')}:</label> + <div class="col-xs-12 col-sm-8"> + <input id="c-register_send_endtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[register_send_endtime]" type="text" value="{:$row.register_send_endtime?datetime($row.register_send_endtime):''}"> + </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> diff --git a/application/api/controller/Notify.php b/application/api/controller/Notify.php index 8d5d887..e843b16 100644 --- a/application/api/controller/Notify.php +++ b/application/api/controller/Notify.php @@ -65,7 +65,7 @@ class Notify extends Api if ($user['invite_user_id'] > 0 && $user['invite_status'] != 1) { $user->invite_status = '1'; $user->isUpdate()->save(); - $coupon = Db::name('coupon')->find(); + $coupon = Db::name('coupon')->where('id',1)->find(); if ($coupon['endtime'] > time()){ $data = []; $time = time(); diff --git a/application/api/controller/User.php b/application/api/controller/User.php index fd73d9c..072ad54 100644 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -128,7 +128,7 @@ class User extends Api if ($userid){ $third->isUpdate(false)->save(['openid'=>$wxapi['openid'],'user_id'=>$userid,'session_key'=>$wxapi['session_key']]); // 注册送优惠券 - $coupon = Db::name('coupon')->find(); + $coupon = Db::name('coupon')->where('id',3)->find(); $time = time(); if($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']){ UserCoupon::create([ @@ -597,7 +597,7 @@ class User extends Api public function inviteReward() { $model = new \app\api\model\User(); - $coupon = Db::name('coupon')->field('price,full_price,endtime')->find(); + $coupon = Db::name('coupon')->where('id',1)->field('price,full_price,endtime')->find(); $coupon['endtime'] = date('Y年m月d日',$coupon['endtime']); $coupon['rule'] = Config::get('site.invite_rule'); $coupon['user_list'] = $model diff --git a/public/assets/js/backend/coupon.js b/public/assets/js/backend/coupon.js index 8d2ba9f..88f76ea 100644 --- a/public/assets/js/backend/coupon.js +++ b/public/assets/js/backend/coupon.js @@ -22,6 +22,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', + sortOrder: 'asc', search:false, showSearch:false, showExport:false, @@ -37,7 +38,7 @@ 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: 'register_send_switch', title: __('Register_send_switch'), searchList: {"0":__('Register_send_switch 0'),"1":__('Register_send_switch 1')}, formatter: Table.api.formatter.toggle}, + {field: 'register_send_switch', title: __('Register_send_switch'), searchList: {"0":__('Register_send_switch 0'),"1":__('Register_send_switch 1')}, formatter: Table.api.formatter.status}, {field: 'register_send_starttime', title: __('Register_send_starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'register_send_endtime', title: __('Register_send_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, @@ -47,7 +48,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin text: '发送优惠券', classname: 'btn btn-info btn-xs btn-dialog', icon: 'fa fa-plus', - url: 'coupon/send_coupon?coupon_id={ids}' + url: 'coupon/send_coupon?coupon_id={ids}', + visible: function (row){ + return row.type == '2' ? true : false; + } + }, + { + name: 'register_set', + text: '注册设置', + classname: 'btn btn-primary btn-xs btn-dialog', + icon: 'fa fa-registered', + url: 'coupon/register_set?ids={ids}', + visible: function (row){ + return row.type == '3' ? true : false; + } } ] } @@ -67,6 +81,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin send_coupon: function () { Controller.api.bindevent(); }, + register_set: function () { + Controller.api.bindevent(); + }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]"));