Kirin 3 rokov pred
rodič
commit
b412f09547

+ 86 - 0
app/admin/controller/user/User.php

@@ -969,4 +969,90 @@ class User extends AuthController
         else
             Json::fail('修改失败');
     }
+
+
+    /**
+     * 会员分组页面
+     * @return string
+     */
+    public function member_grade()
+    {
+        return $this->fetch();
+    }
+
+    /**
+     * 分组列表
+     */
+    public function gradeList()
+    {
+        $where = Util::getMore([
+            ['page', 1],
+            ['limit', 20],
+        ]);
+        return Json::successlayui(MemberGrade::getList($where));
+    }
+
+    /**
+     * 添加/修改分组页面
+     * @param int $id
+     * @return string
+     */
+    public function addGrade($id = 0)
+    {
+        $group = MemberGrade::get($id);
+        $f = array();
+        if (!$group) {
+            $f[] = Form::input('name', '名称', '')->required();
+            $f[] = Form::radio('type', '类型', '')->setOptions([['value' => 1, 'label' => '个人会员'], ['value' => 2, 'label' => '企业会员']])->required();
+            $f[] = Form::number('year', '持续年份', '')->required();
+            $f[] = Form::number('grade', '级别', '')->required();
+            $f[] = Form::input('give_ticket', '赠送核销券', '');
+            $f[] = Form::number('give_num', '赠送数量', '');
+        } else {
+            $f[] = Form::input('name', '名称', $group['name'])->required();
+            $f[] = Form::radio('type', '类型', (string)$group['type'])->setOptions([['value' => 1, 'label' => '个人会员'], ['value' => 2, 'label' => '企业会员']])->required();
+            $f[] = Form::number('year', '持续年份', $group['year'])->required();
+            $f[] = Form::number('grade', '级别', $group['grade'])->required();
+            $f[] = Form::input('give_ticket', '赠送核销券', $group['give_ticket']);
+            $f[] = Form::number('give_num', '赠送数量', $group['give_num']);
+        }
+        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('saveGrade', array('id' => $id)));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 添加/修改
+     * @param int $id
+     */
+    public function saveGrade($id = 0)
+    {
+        $data = Util::postMore([
+            ['name', ''],
+            ['type', ''],
+            ['year', ''],
+            ['grade', ''],
+            ['give_ticket', ''],
+            ['give_num', ''],
+        ]);
+        if ($id) {
+            if (MemberGrade::where('id', '<>', $id)->where('grade', $data['grade'])->where('type', $data['type'])->find()) {
+                return Json::fail('同类型不能存在相同级别!');
+            }
+            if (MemberGrade::where('id', $id)->update($data)) {
+                return Json::success('修改成功');
+            } else {
+                return Json::fail('修改失败或者您没有修改什么!');
+            }
+        } else {
+            if (MemberGrade::where('grade', $data['grade'])->where('type', $data['type'])->find()) {
+                return Json::fail('同类型不能存在相同级别!');
+            }
+            if ($res = MemberGrade::create($data)) {
+                return Json::success('保存成功', ['id' => $res->id]);
+            } else {
+                return Json::fail('保存失败!');
+            }
+        }
+    }
 }

+ 52 - 0
app/admin/view/user/user/member_grade.php

@@ -0,0 +1,52 @@
+{extend name="public/container"}
+{block name="head_top"}
+
+{/block}
+{block name="content"}
+<div class="layui-fluid" style="background: #fff;margin-top: -10px;">
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <!--                <div class="layui-card-header">门店列表</div>-->
+                <div class="layui-card-body">
+                    <div class="layui-btn-container">
+                        <button class="layui-btn layui-btn-sm"
+                                onclick="$eb.createModalFrame(this.innerText,'{:Url('addGrade')}',{h:250,w:720})">添加级别
+                        </button>
+                    </div>
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+
+                    <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='edit'>
+                            修改
+                        </button>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    layList.tableList('List', "{:Url('gradeList')}", function () {
+        return [
+            {field: 'id', title: 'ID', sort: true, event: 'id', width: '20%'},
+            {field: 'type', title: '类型', width: '10%'},
+            {field: 'name', title: '名称', width: '20%'},
+            {field: 'year', title: '持续年份', width: '20%'},
+            {field: 'price', title: '价格', width: '15%'},
+            {field: 'right', title: '操作', align: 'center', toolbar: '#act'},
+        ];
+    });
+    //点击事件绑定
+    layList.tool(function (event, data, obj) {
+        switch (event) {
+            case 'edit':
+                $eb.createModalFrame(data.name + '-编辑', layList.U({a: 'addGrade', q: {id: data.id}}), {h: 250, w: 720});
+                break;
+        }
+    })
+</script>
+{/block}

+ 10 - 0
app/models/member/MemberGrade.php

@@ -41,4 +41,14 @@ class MemberGrade extends BaseModel
 
     use ModelTrait;
 
+    public static function getList($where)
+    {
+
+        $data = self::page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
+            $item['type'] = ($item['type'] == 1 ? '个人会员' : '企业会员');
+        });
+        $count = $data->count();
+        return compact('count', 'data');
+    }
+
 }