作者 何书鹏

优惠券修改

@@ -4,6 +4,8 @@ namespace app\admin\controller; @@ -4,6 +4,8 @@ namespace app\admin\controller;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
6 use think\Db; 6 use think\Db;
  7 +use think\exception\PDOException;
  8 +use think\exception\ValidateException;
7 9
8 /** 10 /**
9 * 优惠券 11 * 优惠券
@@ -70,4 +72,56 @@ class Coupon extends Backend @@ -70,4 +72,56 @@ class Coupon extends Backend
70 } 72 }
71 return $this->view->fetch(); 73 return $this->view->fetch();
72 } 74 }
  75 +
  76 + /**
  77 + * 注册设置
  78 + */
  79 + public function register_set($ids = null)
  80 + {
  81 + $row = $this->model->get($ids);
  82 + if (!$row) {
  83 + $this->error(__('No Results were found'));
  84 + }
  85 + $adminIds = $this->getDataLimitAdminIds();
  86 + if (is_array($adminIds)) {
  87 + if (!in_array($row[$this->dataLimitField], $adminIds)) {
  88 + $this->error(__('You have no permission'));
  89 + }
  90 + }
  91 + if ($this->request->isPost()) {
  92 + $params = $this->request->post("row/a");
  93 + if ($params) {
  94 + $params = $this->preExcludeFields($params);
  95 + $result = false;
  96 + Db::startTrans();
  97 + try {
  98 + //是否采用模型验证
  99 + if ($this->modelValidate) {
  100 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  101 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  102 + $row->validateFailException(true)->validate($validate);
  103 + }
  104 + $result = $row->allowField(true)->save($params);
  105 + Db::commit();
  106 + } catch (ValidateException $e) {
  107 + Db::rollback();
  108 + $this->error($e->getMessage());
  109 + } catch (PDOException $e) {
  110 + Db::rollback();
  111 + $this->error($e->getMessage());
  112 + } catch (Exception $e) {
  113 + Db::rollback();
  114 + $this->error($e->getMessage());
  115 + }
  116 + if ($result !== false) {
  117 + $this->success();
  118 + } else {
  119 + $this->error(__('No rows were updated'));
  120 + }
  121 + }
  122 + $this->error(__('Parameter %s can not be empty', ''));
  123 + }
  124 + $this->view->assign("row", $row);
  125 + return $this->view->fetch();
  126 + }
73 } 127 }
@@ -42,27 +42,6 @@ @@ -42,27 +42,6 @@
42 <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):''}"> 42 <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):''}">
43 </div> 43 </div>
44 </div> 44 </div>
45 - <div class="form-group">  
46 - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_switch')}:</label>  
47 - <div class="col-xs-12 col-sm-8">  
48 - <input id="c-register_send_switch" name="row[register_send_switch]" type="hidden" value="{$row.register_send_switch|htmlentities}">  
49 - <a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-register_send_switch" data-yes="1" data-no="0" >  
50 - <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>  
51 - </a>  
52 - </div>  
53 - </div>  
54 - <div class="form-group">  
55 - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_starttime')}:</label>  
56 - <div class="col-xs-12 col-sm-8">  
57 - <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):''}">  
58 - </div>  
59 - </div>  
60 - <div class="form-group">  
61 - <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_endtime')}:</label>  
62 - <div class="col-xs-12 col-sm-8">  
63 - <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):''}">  
64 - </div>  
65 - </div>  
66 <div class="form-group layer-footer"> 45 <div class="form-group layer-footer">
67 <label class="control-label col-xs-12 col-sm-2"></label> 46 <label class="control-label col-xs-12 col-sm-2"></label>
68 <div class="col-xs-12 col-sm-8"> 47 <div class="col-xs-12 col-sm-8">
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_switch')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-register_send_switch" name="row[register_send_switch]" type="hidden" value="{$row.register_send_switch|htmlentities}">
  7 + <a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-register_send_switch" data-yes="1" data-no="0" >
  8 + <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>
  9 + </a>
  10 + </div>
  11 + </div>
  12 + <div class="form-group">
  13 + <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_starttime')}:</label>
  14 + <div class="col-xs-12 col-sm-8">
  15 + <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):''}">
  16 + </div>
  17 + </div>
  18 + <div class="form-group">
  19 + <label class="control-label col-xs-12 col-sm-2">{:__('Register_send_endtime')}:</label>
  20 + <div class="col-xs-12 col-sm-8">
  21 + <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):''}">
  22 + </div>
  23 + </div>
  24 + <div class="form-group layer-footer">
  25 + <label class="control-label col-xs-12 col-sm-2"></label>
  26 + <div class="col-xs-12 col-sm-8">
  27 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  28 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  29 + </div>
  30 + </div>
  31 +</form>
@@ -65,7 +65,7 @@ class Notify extends Api @@ -65,7 +65,7 @@ class Notify extends Api
65 if ($user['invite_user_id'] > 0 && $user['invite_status'] != 1) { 65 if ($user['invite_user_id'] > 0 && $user['invite_status'] != 1) {
66 $user->invite_status = '1'; 66 $user->invite_status = '1';
67 $user->isUpdate()->save(); 67 $user->isUpdate()->save();
68 - $coupon = Db::name('coupon')->find(); 68 + $coupon = Db::name('coupon')->where('id',1)->find();
69 if ($coupon['endtime'] > time()){ 69 if ($coupon['endtime'] > time()){
70 $data = []; 70 $data = [];
71 $time = time(); 71 $time = time();
@@ -128,7 +128,7 @@ class User extends Api @@ -128,7 +128,7 @@ class User extends Api
128 if ($userid){ 128 if ($userid){
129 $third->isUpdate(false)->save(['openid'=>$wxapi['openid'],'user_id'=>$userid,'session_key'=>$wxapi['session_key']]); 129 $third->isUpdate(false)->save(['openid'=>$wxapi['openid'],'user_id'=>$userid,'session_key'=>$wxapi['session_key']]);
130 // 注册送优惠券 130 // 注册送优惠券
131 - $coupon = Db::name('coupon')->find(); 131 + $coupon = Db::name('coupon')->where('id',3)->find();
132 $time = time(); 132 $time = time();
133 if($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']){ 133 if($coupon['register_send_switch'] == '1' && $time >= $coupon['register_send_starttime'] && $time <= $coupon['register_send_endtime']){
134 UserCoupon::create([ 134 UserCoupon::create([
@@ -597,7 +597,7 @@ class User extends Api @@ -597,7 +597,7 @@ class User extends Api
597 public function inviteReward() 597 public function inviteReward()
598 { 598 {
599 $model = new \app\api\model\User(); 599 $model = new \app\api\model\User();
600 - $coupon = Db::name('coupon')->field('price,full_price,endtime')->find(); 600 + $coupon = Db::name('coupon')->where('id',1)->field('price,full_price,endtime')->find();
601 $coupon['endtime'] = date('Y年m月d日',$coupon['endtime']); 601 $coupon['endtime'] = date('Y年m月d日',$coupon['endtime']);
602 $coupon['rule'] = Config::get('site.invite_rule'); 602 $coupon['rule'] = Config::get('site.invite_rule');
603 $coupon['user_list'] = $model 603 $coupon['user_list'] = $model
@@ -22,6 +22,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -22,6 +22,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
22 url: $.fn.bootstrapTable.defaults.extend.index_url, 22 url: $.fn.bootstrapTable.defaults.extend.index_url,
23 pk: 'id', 23 pk: 'id',
24 sortName: 'id', 24 sortName: 'id',
  25 + sortOrder: 'asc',
25 search:false, 26 search:false,
26 showSearch:false, 27 showSearch:false,
27 showExport:false, 28 showExport:false,
@@ -37,7 +38,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -37,7 +38,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
37 {field: 'days', title: __('Days')}, 38 {field: 'days', title: __('Days')},
38 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 39 {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
39 {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 40 {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
40 - {field: 'register_send_switch', title: __('Register_send_switch'), searchList: {"0":__('Register_send_switch 0'),"1":__('Register_send_switch 1')}, formatter: Table.api.formatter.toggle}, 41 + {field: 'register_send_switch', title: __('Register_send_switch'), searchList: {"0":__('Register_send_switch 0'),"1":__('Register_send_switch 1')}, formatter: Table.api.formatter.status},
41 {field: 'register_send_starttime', title: __('Register_send_starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 42 {field: 'register_send_starttime', title: __('Register_send_starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
42 {field: 'register_send_endtime', title: __('Register_send_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 43 {field: 'register_send_endtime', title: __('Register_send_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
43 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, 44 {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 @@ -47,7 +48,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
47 text: '发送优惠券', 48 text: '发送优惠券',
48 classname: 'btn btn-info btn-xs btn-dialog', 49 classname: 'btn btn-info btn-xs btn-dialog',
49 icon: 'fa fa-plus', 50 icon: 'fa fa-plus',
50 - url: 'coupon/send_coupon?coupon_id={ids}' 51 + url: 'coupon/send_coupon?coupon_id={ids}',
  52 + visible: function (row){
  53 + return row.type == '2' ? true : false;
  54 + }
  55 + },
  56 + {
  57 + name: 'register_set',
  58 + text: '注册设置',
  59 + classname: 'btn btn-primary btn-xs btn-dialog',
  60 + icon: 'fa fa-registered',
  61 + url: 'coupon/register_set?ids={ids}',
  62 + visible: function (row){
  63 + return row.type == '3' ? true : false;
  64 + }
51 } 65 }
52 ] 66 ]
53 } 67 }
@@ -67,6 +81,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -67,6 +81,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
67 send_coupon: function () { 81 send_coupon: function () {
68 Controller.api.bindevent(); 82 Controller.api.bindevent();
69 }, 83 },
  84 + register_set: function () {
  85 + Controller.api.bindevent();
  86 + },
70 api: { 87 api: {
71 bindevent: function () { 88 bindevent: function () {
72 Form.api.bindevent($("form[role=form]")); 89 Form.api.bindevent($("form[role=form]"));