柳建 преди 11 месеца
родител
ревизия
3c86abaf77
променени са 3 файла, в които са добавени 95 реда и са изтрити 2 реда
  1. 38 0
      application/admin/controller/auth/Admin.php
  2. 30 0
      application/admin/view/auth/admin/changemoney.html
  3. 27 2
      public/assets/js/backend/auth/admin.js

+ 38 - 0
application/admin/controller/auth/Admin.php

@@ -32,6 +32,7 @@ class Admin extends Backend
     {
         parent::_initialize();
         $this->model = model('Admin');
+        $this->moneyLogModel = new \app\common\model\MoneyLog;
 
         $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
         $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
@@ -113,7 +114,44 @@ class Admin extends Backend
         }
         return $this->view->fetch();
     }
+    /**
+     * 添加
+     */
+    public function changemoney($ids)
+    {
+        $row = $this->model->get(['id' => $ids]);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        if (!in_array($row->id, $this->childrenAdminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if ($this->request->isPost()) {
 
+            $money = $this->request->post("money");
+
+            if ($money) {
+                Db::startTrans();
+                try {
+                    $before= $row->money;
+                    $row->money= bcadd($row->money,$money,7);
+                    $row->save();
+                    $moenylog=['user_id'=>$row->id,'money' =>$money,'before' =>$before, 'after' => $row->money , 'memo' => 'changemoney'];
+                    $this->moneyLogModel->save($moenylog);
+                    Db::commit();
+                } catch (\Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                $this->success();
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+
+        $this->view->assign("row", $row);
+
+        return $this->view->fetch();
+    }
     /**
      * 添加
      */

+ 30 - 0
application/admin/view/auth/admin/changemoney.html

@@ -0,0 +1,30 @@
+<form id="edit-form" class="form-horizontal form-ajax" role="form" data-toggle="validator" method="POST" action="">
+
+
+    <div class="form-group">
+        <label  class="control-label col-xs-12 col-sm-2">{:__('Username')}:</label>
+        <div class="col-xs-12 col-sm-4">
+        {$row.username|htmlentities}
+        </div>
+
+        <label  class="control-label col-xs-12 col-sm-2">{:__('当前余额')}:</label>
+        <div class="col-xs-12 col-sm-4">
+            {$row.money}
+
+        </div>
+    </div>
+    <div class="form-group">
+        <label for="mobile" class="control-label col-xs-12 col-sm-4">*{:__('增加金额量')}(负数为减少):</label>
+        <div class="col-xs-12 col-sm-6">
+            <input type="text" class="form-control" id="mobile" name="money" value="0" data-rule="money" />
+        </div>
+    </div>
+
+    <div class="form-group hidden 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-primary btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 27 - 2
public/assets/js/backend/auth/admin.js

@@ -38,10 +38,32 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'mobile', title: __('Mobile')},
                         {field: 'status', title: __("Status"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                         {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
-                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
+                        {field: 'operate', title: __('Operate'), table: table,
+
+                            buttons: [
+                                {
+                                    name: 'detail',
+                                    text: __('修改金额'),
+                                    title: __('修改金额'),
+                                    classname: 'btn btn-xs btn-primary btn-dialog',
+                                    icon: 'fa fa-list',
+                                    url: 'auth/admin/changemoney',
+                                    callback: function (data) {
+                                        Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
+                                    },
+                                    visible: function (row) {
+                                        //返回true时按钮显示,返回false隐藏
+                                        return true;
+                                    }
+                                },
+                            ],
+
+
+                            events: Table.api.events.operate, formatter: function (value, row, index) {
                                 if(row.id == Config.admin.id){
                                     return '';
                                 }
+
                                 return Table.api.formatter.operate.call(this, value, row, index);
                             }}
                     ]
@@ -56,7 +78,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         },
         edit: function () {
             Form.api.bindevent($("form[role=form]"));
-        }
+        },
+        changemoney: function () {
+            Form.api.bindevent($("form[role=form]"));
+        },
     };
     return Controller;
 });