浏览代码

奖池礼物的增删改查优化

lizhen_gitee 1 年之前
父节点
当前提交
60eb9a0a5a

+ 76 - 1
application/admin/controller/egg/Gift.php

@@ -54,10 +54,12 @@ class Gift extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             $list = $this->model
+                    ->field('*,count(gift.id) as gift_number')
                     ->with(['eggjackpot'])
                     ->where($where)
                     ->order($sort, $order)
-                    ->paginate($limit);
+                    ->group('gift.Jackpot_id,gift.gift_id')
+                    ->paginate();
 
             $totalMoney = $this->model->with(['eggjackpot'])->where($where)->sum('price');
             foreach ($list as $row) {
@@ -114,4 +116,77 @@ class Gift extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 编辑
+     */
+    public function newedit(){
+        $gift_id    = input('gift_id');
+        $jackpot_id = input('jackpot_id');
+        $info = Db::name('egg_gift')->field('*,count(id) as number')->where('gift_id',$gift_id)->where('Jackpot_id',$jackpot_id)->find();
+
+        if ($this->request->isPost()) {
+            $number     = $this->request->post('number',0,'intval');
+            if($number <= 0){
+                $this->error('请填写正确的数量');
+            }
+
+            $gift_info = Db::name('gift')->where('id',$gift_id)->find();
+            if(empty($gift_info)){
+                $this->error('不存在的礼物');
+            }
+            $jackpot_info = Db::name('egg_jackpot')->where('id',$jackpot_id)->find();
+            if(empty($jackpot_info)){
+                $this->error('不存在的奖池');
+            }
+
+            $data_all = [];
+
+            for($i=1;$i<=$number;$i++){
+                $one = [
+                    'gift_id' => $gift_id,
+                    'image'   => $gift_info['image'],
+                    'special' => $gift_info['special'],
+                    'gift_name' => $gift_info['name'],
+                    'Jackpot_id' => $jackpot_id,
+                    'prize_no' => 0,
+                    'price' => $gift_info['price'],
+                    'is_use' => 0,
+                    'starttime' => $jackpot_info['starttime'],
+                ];
+                $data_all[] = $one;
+            }
+
+            Db::startTrans();
+            //全删
+            $info = Db::name('egg_gift')->where('gift_id',$gift_id)->where('Jackpot_id',$jackpot_id)->delete();
+            if(!$info){
+                Db::rollback();
+                $this->error('操作失败');
+            }
+            //重新写入
+            $rs = Db::name('egg_gift')->insertAll($data_all);
+            if(!$rs){
+                Db::rollback();
+                $this->error('操作失败');
+            }
+            Db::commit();
+
+            $this->success('修改完成');
+        }
+
+        $this->view->assign('row',$info);
+        return $this->view->fetch();
+    }
+
+    /**
+     * 删除
+     */
+    public function newdel(){
+        $gift_id    = input('gift_id');
+        $jackpot_id = input('jackpot_id');
+        $info = Db::name('egg_gift')->where('gift_id',$gift_id)->where('Jackpot_id',$jackpot_id)->delete();
+
+        $this->success('删除完成');
+    }
+
 }

+ 3 - 1
application/admin/view/egg/gift/index.html

@@ -9,7 +9,7 @@
                         <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('egg/gift/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('egg/gift/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('egg/gift/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                         <!--<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('egg/gift/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
                          <!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('egg/gift/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>-->
                         <a href="javascript:;" class="btn btn-default" style="font-size:14px;color:dodgerblue;">
                             <span class="extend">
@@ -30,6 +30,8 @@
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                            data-operate-edit="{:$auth->check('egg/gift/edit')}" 
                            data-operate-del="{:$auth->check('egg/gift/del')}" 
+                           data-operate-newdel="{:$auth->check('egg/gift/newdel')}"
+                           data-operate-newedit="{:$auth->check('egg/gift/newedit')}"
                            width="100%">
                     </table>
                 </div>

+ 32 - 0
application/admin/view/egg/gift/newedit.html

@@ -0,0 +1,32 @@
+<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">{:__('Gift_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-gift_id" data-rule="required" data-source="gift/gift/index" disabled class="form-control selectpage"  type="text" value="{$row.gift_id|htmlentities}">
+        </div>
+    </div>
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Jackpot_id')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-Jackpot_id" data-rule="required" data-source="egg/Jackpot/index" disabled class="form-control selectpage"  type="text" value="{$row.Jackpot_id|htmlentities}">
+        </div>
+    </div>
+
+    <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-number" data-rule="required" class="form-control" name="number" type="text" value="{$row.number|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>

+ 38 - 5
public/assets/js/backend/egg/gift.js

@@ -8,7 +8,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     index_url: 'egg/gift/index' + location.search,
                     add_url: 'egg/gift/add',
 //                    edit_url: 'egg/gift/edit',
-                    del_url: 'egg/gift/del',
+//                    del_url: 'egg/gift/del',
                     multi_url: 'egg/gift/multi',
                     import_url: 'egg/gift/import',
                     table: 'egg_gift',
@@ -38,16 +38,43 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'eggjackpot.name', title: __('Eggjackpot.name'), operate: 'LIKE'},
 //                        {field: 'eggjackpot.type', title: __('Eggjackpot.type'), searchList: {"1":__('Eggjackpot.type 1'),"2":__('Eggjackpot.type 2'),"3":__('Eggjackpot.type 3')}, formatter: Table.api.formatter.normal},
                         {field: 'gift_id', title: __('Gift_id')},
+                        {field: 'gift_name', title: __('Gift_name'), operate: 'LIKE'},
+                        {field: 'gift_number', title: '数量', operate: false},
+
                         {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
 //                        {field: 'special', title: __('Special'), operate: 'LIKE'},
-                        {field: 'gift_name', title: __('Gift_name'), operate: 'LIKE'},
 
 //                        {field: 'prize_no', title: __('Prize_no')},
                         {field: 'price', title: __('Price')},
-                        {field: 'is_use', title: __('Is_use'), searchList: {"1":__('Is_use 1'),"0":__('Is_use 0')}, formatter: Table.api.formatter.normal},
-                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+//                        {field: 'is_use', title: __('Is_use'), searchList: {"1":__('Is_use 1'),"0":__('Is_use 0')}, formatter: Table.api.formatter.normal},
+//                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
 //                        {field: 'starttime', title: __('Starttime'), 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'),
+                            buttons:[
+                                {
+                                    name:'newedit',
+                                    text:'编辑',
+                                    title:'编辑',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-dialog',
+                                    url:function(row){
+                                        return 'egg/gift/newedit/jackpot_id/' + row.Jackpot_id + '/gift_id/' + row.gift_id + '?dialog=1';
+                                    },
+                                    target:'_self',
+                                },
+                                {
+                                    name:'newdel',
+                                    text:'删除',
+                                    title:'删除',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-ajax',
+                                    url:function(row){
+                                        return 'egg/gift/newdel/jackpot_id/' + row.Jackpot_id + '/gift_id/' + row.gift_id + '?dialog=1';
+                                    },
+                                    target:'_self',
+                                }
+                            ],
+                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                     ]
                 ]
             });
@@ -61,6 +88,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         edit: function () {
             Controller.api.bindevent();
         },
+        newedit: function () {
+            Controller.api.bindevent();
+        },
+        newdel: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));