正在显示
12 个修改的文件
包含
426 行增加
和
3 行删除
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\controller\mobile\package; | ||
4 | + | ||
5 | +use app\common\controller\Backend; | ||
6 | +use think\Db; | ||
7 | + | ||
8 | +/** | ||
9 | + * 企业套餐规格管理 | ||
10 | + * | ||
11 | + * @icon fa fa-circle-o | ||
12 | + */ | ||
13 | +class PackageSpec extends Backend | ||
14 | +{ | ||
15 | + | ||
16 | + /** | ||
17 | + * PackageSpec模型对象 | ||
18 | + * @var \app\admin\model\mobile\package\PackageSpec | ||
19 | + */ | ||
20 | + protected $model = null; | ||
21 | + | ||
22 | + public function _initialize() | ||
23 | + { | ||
24 | + parent::_initialize(); | ||
25 | + $this->model = new \app\admin\model\mobile\package\PackageSpec; | ||
26 | + $this->view->assign("isTopList", $this->model->getIsTopList()); | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 | ||
31 | + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | ||
32 | + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | ||
33 | + */ | ||
34 | + | ||
35 | + | ||
36 | + /** | ||
37 | + * 查看 | ||
38 | + */ | ||
39 | + public function index() | ||
40 | + { | ||
41 | + //当前是否为关联查询 | ||
42 | + $this->relationSearch = false; | ||
43 | + //设置过滤方法 | ||
44 | + $this->request->filter(['strip_tags', 'trim']); | ||
45 | + if ($this->request->isAjax()) | ||
46 | + { | ||
47 | + //如果发送的来源是Selectpage,则转发到Selectpage | ||
48 | + if ($this->request->request('keyField')) | ||
49 | + { | ||
50 | + return $this->selectpage(); | ||
51 | + } | ||
52 | + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | ||
53 | + $total = $this->model | ||
54 | + ->where('package_id',$this->request->request('package_id')) | ||
55 | + ->where($where) | ||
56 | + ->order($sort, $order) | ||
57 | + ->count(); | ||
58 | + | ||
59 | + $list = $this->model | ||
60 | + ->where('package_id',$this->request->request('package_id')) | ||
61 | + ->where($where) | ||
62 | + ->order($sort, $order) | ||
63 | + ->limit($offset, $limit) | ||
64 | + ->select(); | ||
65 | + | ||
66 | + foreach ($list as $row) { | ||
67 | + $row->visible(['id','name','current_price','original_price','people_num','is_top']); | ||
68 | + | ||
69 | + } | ||
70 | + $list = collection($list)->toArray(); | ||
71 | + $result = array("total" => $total, "rows" => $list); | ||
72 | + | ||
73 | + return json($result); | ||
74 | + } | ||
75 | + return $this->view->fetch(); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * 添加 | ||
80 | + */ | ||
81 | + public function add() | ||
82 | + { | ||
83 | + $package_id = $this->request->request('package_id'); | ||
84 | + if ($this->request->isPost()) { | ||
85 | + $params = $this->request->post("row/a"); | ||
86 | + if ($params) { | ||
87 | + $params = $this->preExcludeFields($params); | ||
88 | + | ||
89 | + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | ||
90 | + $params[$this->dataLimitField] = $this->auth->id; | ||
91 | + } | ||
92 | + | ||
93 | + $params['package_id'] = $package_id; | ||
94 | + $result = false; | ||
95 | + Db::startTrans(); | ||
96 | + try { | ||
97 | + //是否采用模型验证 | ||
98 | + if ($this->modelValidate) { | ||
99 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
100 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | ||
101 | + $this->model->validateFailException(true)->validate($validate); | ||
102 | + } | ||
103 | + $result = $this->model->allowField(true)->save($params); | ||
104 | + Db::commit(); | ||
105 | + } catch (ValidateException $e) { | ||
106 | + Db::rollback(); | ||
107 | + $this->error($e->getMessage()); | ||
108 | + } catch (PDOException $e) { | ||
109 | + Db::rollback(); | ||
110 | + $this->error($e->getMessage()); | ||
111 | + } catch (Exception $e) { | ||
112 | + Db::rollback(); | ||
113 | + $this->error($e->getMessage()); | ||
114 | + } | ||
115 | + if ($result !== false) { | ||
116 | + $this->success(); | ||
117 | + } else { | ||
118 | + $this->error(__('No rows were inserted')); | ||
119 | + } | ||
120 | + } | ||
121 | + $this->error(__('Parameter %s can not be empty', '')); | ||
122 | + } | ||
123 | + return $this->view->fetch(); | ||
124 | + } | ||
125 | +} |
1 | +<?php | ||
2 | + | ||
3 | +return [ | ||
4 | + 'Id' => 'id', | ||
5 | + 'Package_id' => '企业套餐ID', | ||
6 | + 'Name' => '规格名称', | ||
7 | + 'Current_price' => '当前价格', | ||
8 | + 'Original_price' => '原始价格', | ||
9 | + 'People_num' => '套餐限制人数', | ||
10 | + 'Is_top' => '是否顶配', | ||
11 | + 'Is_top 0' => '否', | ||
12 | + 'Is_top 1' => '是', | ||
13 | + 'Createtime' => '创建时间', | ||
14 | + 'Updatetime' => '修改时间' | ||
15 | +]; |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\model\mobile\package; | ||
4 | + | ||
5 | +use think\Model; | ||
6 | + | ||
7 | + | ||
8 | +class PackageSpec extends Model | ||
9 | +{ | ||
10 | + | ||
11 | + | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | + // 表名 | ||
16 | + protected $name = 'mobile_package_spec'; | ||
17 | + | ||
18 | + // 自动写入时间戳字段 | ||
19 | + protected $autoWriteTimestamp = 'int'; | ||
20 | + | ||
21 | + // 定义时间戳字段名 | ||
22 | + protected $createTime = 'createtime'; | ||
23 | + protected $updateTime = 'updatetime'; | ||
24 | + protected $deleteTime = false; | ||
25 | + | ||
26 | + // 追加属性 | ||
27 | + protected $append = [ | ||
28 | + 'is_top_text' | ||
29 | + ]; | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | + public function getIsTopList() | ||
34 | + { | ||
35 | + return ['0' => __('Is_top 0'), '1' => __('Is_top 1')]; | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + public function getIsTopTextAttr($value, $data) | ||
40 | + { | ||
41 | + $value = $value ? $value : (isset($data['is_top']) ? $data['is_top'] : ''); | ||
42 | + $list = $this->getIsTopList(); | ||
43 | + return isset($list[$value]) ? $list[$value] : ''; | ||
44 | + } | ||
45 | + | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | +} |
1 | +<?php | ||
2 | + | ||
3 | +namespace app\admin\validate\mobile\package; | ||
4 | + | ||
5 | +use think\Validate; | ||
6 | + | ||
7 | +class PackageSpec extends Validate | ||
8 | +{ | ||
9 | + /** | ||
10 | + * 验证规则 | ||
11 | + */ | ||
12 | + protected $rule = [ | ||
13 | + ]; | ||
14 | + /** | ||
15 | + * 提示消息 | ||
16 | + */ | ||
17 | + protected $message = [ | ||
18 | + ]; | ||
19 | + /** | ||
20 | + * 验证场景 | ||
21 | + */ | ||
22 | + protected $scene = [ | ||
23 | + 'add' => [], | ||
24 | + 'edit' => [], | ||
25 | + ]; | ||
26 | + | ||
27 | +} |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <div class="form-group"> | 15 | <div class="form-group"> |
16 | <label class="control-label col-xs-12 col-sm-2">{:__('Secret_ids')}:</label> | 16 | <label class="control-label col-xs-12 col-sm-2">{:__('Secret_ids')}:</label> |
17 | <div class="col-xs-12 col-sm-8"> | 17 | <div class="col-xs-12 col-sm-8"> |
18 | - <input id="c-secret_ids" data-rule="required" data-field="title" data-source="mobile/secret/index" data-multiple="true" class="form-control selectpage" name="row[secret_ids]" type="text" value=""> | 18 | + <input id="c-secret_ids" data-rule="required" data-field="title" data-source="mobile/secret/secret/index" data-multiple="true" class="form-control selectpage" name="row[secret_ids]" type="text" value=""> |
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
21 | <div class="form-group"> | 21 | <div class="form-group"> |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | <div class="form-group"> | 15 | <div class="form-group"> |
16 | <label class="control-label col-xs-12 col-sm-2">{:__('Secret_ids')}:</label> | 16 | <label class="control-label col-xs-12 col-sm-2">{:__('Secret_ids')}:</label> |
17 | <div class="col-xs-12 col-sm-8"> | 17 | <div class="col-xs-12 col-sm-8"> |
18 | - <input id="c-secret_ids" data-rule="required" data-field="title" data-source="mobile/secret/index" data-multiple="true" class="form-control selectpage" name="row[secret_ids]" type="text" value="{$row.secret_ids|htmlentities}"> | 18 | + <input id="c-secret_ids" data-rule="required" data-field="title" data-source="mobile/secret/secret/index" data-multiple="true" class="form-control selectpage" name="row[secret_ids]" type="text" value="{$row.secret_ids|htmlentities}"> |
19 | </div> | 19 | </div> |
20 | </div> | 20 | </div> |
21 | <div class="form-group"> | 21 | <div class="form-group"> |
1 | +<form id="add-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">{:__('Package_id')}:</label>--> | ||
5 | +<!-- <div class="col-xs-12 col-sm-8">--> | ||
6 | +<!-- <input id="c-package_id" data-rule="required" data-source="package/index" class="form-control selectpage" name="row[package_id]" type="text" value="">--> | ||
7 | +<!-- </div>--> | ||
8 | +<!-- </div>--> | ||
9 | + <div class="form-group"> | ||
10 | + <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label> | ||
11 | + <div class="col-xs-12 col-sm-8"> | ||
12 | + <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value=""> | ||
13 | + </div> | ||
14 | + </div> | ||
15 | + <div class="form-group"> | ||
16 | + <label class="control-label col-xs-12 col-sm-2">{:__('Current_price')}:</label> | ||
17 | + <div class="col-xs-12 col-sm-8"> | ||
18 | + <input id="c-current_price" data-rule="required" class="form-control" step="0.01" name="row[current_price]" type="number" value="0.00"> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + <div class="form-group"> | ||
22 | + <label class="control-label col-xs-12 col-sm-2">{:__('Original_price')}:</label> | ||
23 | + <div class="col-xs-12 col-sm-8"> | ||
24 | + <input id="c-original_price" data-rule="required" class="form-control" step="0.01" name="row[original_price]" type="number" value="0.00"> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | + <div class="form-group"> | ||
28 | + <label class="control-label col-xs-12 col-sm-2">{:__('People_num')}:</label> | ||
29 | + <div class="col-xs-12 col-sm-8"> | ||
30 | + <input id="c-people_num" data-rule="required" class="form-control" name="row[people_num]" type="number" value="0"> | ||
31 | + </div> | ||
32 | + </div> | ||
33 | + <div class="form-group"> | ||
34 | + <label class="control-label col-xs-12 col-sm-2">{:__('Is_top')}:</label> | ||
35 | + <div class="col-xs-12 col-sm-8"> | ||
36 | + | ||
37 | + <select id="c-is_top" data-rule="required" class="form-control selectpicker" name="row[is_top]"> | ||
38 | + {foreach name="isTopList" item="vo"} | ||
39 | + <option value="{$key}" {in name="key" value="0"}selected{/in}>{$vo}</option> | ||
40 | + {/foreach} | ||
41 | + </select> | ||
42 | + | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + <div class="form-group layer-footer"> | ||
46 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
47 | + <div class="col-xs-12 col-sm-8"> | ||
48 | + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button> | ||
49 | + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> | ||
50 | + </div> | ||
51 | + </div> | ||
52 | +</form> |
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">{:__('Package_id')}:</label>--> | ||
5 | +<!-- <div class="col-xs-12 col-sm-8">--> | ||
6 | +<!-- <input id="c-package_id" data-rule="required" data-source="package/index" class="form-control selectpage" name="row[package_id]" type="text" value="{$row.package_id|htmlentities}">--> | ||
7 | +<!-- </div>--> | ||
8 | +<!-- </div>--> | ||
9 | + <div class="form-group"> | ||
10 | + <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label> | ||
11 | + <div class="col-xs-12 col-sm-8"> | ||
12 | + <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}"> | ||
13 | + </div> | ||
14 | + </div> | ||
15 | + <div class="form-group"> | ||
16 | + <label class="control-label col-xs-12 col-sm-2">{:__('Current_price')}:</label> | ||
17 | + <div class="col-xs-12 col-sm-8"> | ||
18 | + <input id="c-current_price" data-rule="required" class="form-control" step="0.01" name="row[current_price]" type="number" value="{$row.current_price|htmlentities}"> | ||
19 | + </div> | ||
20 | + </div> | ||
21 | + <div class="form-group"> | ||
22 | + <label class="control-label col-xs-12 col-sm-2">{:__('Original_price')}:</label> | ||
23 | + <div class="col-xs-12 col-sm-8"> | ||
24 | + <input id="c-original_price" data-rule="required" class="form-control" step="0.01" name="row[original_price]" type="number" value="{$row.original_price|htmlentities}"> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | + <div class="form-group"> | ||
28 | + <label class="control-label col-xs-12 col-sm-2">{:__('People_num')}:</label> | ||
29 | + <div class="col-xs-12 col-sm-8"> | ||
30 | + <input id="c-people_num" data-rule="required" class="form-control" name="row[people_num]" type="number" value="{$row.people_num|htmlentities}"> | ||
31 | + </div> | ||
32 | + </div> | ||
33 | + <div class="form-group"> | ||
34 | + <label class="control-label col-xs-12 col-sm-2">{:__('Is_top')}:</label> | ||
35 | + <div class="col-xs-12 col-sm-8"> | ||
36 | + | ||
37 | + <select id="c-is_top" data-rule="required" class="form-control selectpicker" name="row[is_top]"> | ||
38 | + {foreach name="isTopList" item="vo"} | ||
39 | + <option value="{$key}" {in name="key" value="$row.is_top"}selected{/in}>{$vo}</option> | ||
40 | + {/foreach} | ||
41 | + </select> | ||
42 | + | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + <div class="form-group layer-footer"> | ||
46 | + <label class="control-label col-xs-12 col-sm-2"></label> | ||
47 | + <div class="col-xs-12 col-sm-8"> | ||
48 | + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button> | ||
49 | + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button> | ||
50 | + </div> | ||
51 | + </div> | ||
52 | +</form> |
1 | +<div class="panel panel-default panel-intro"> | ||
2 | + {:build_heading()} | ||
3 | + | ||
4 | + <div class="panel-body"> | ||
5 | + <div id="myTabContent" class="tab-content"> | ||
6 | + <div class="tab-pane fade active in" id="one"> | ||
7 | + <div class="widget-body no-padding"> | ||
8 | + <div id="toolbar" class="toolbar"> | ||
9 | + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> | ||
10 | + <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('mobile/package/package_spec/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> | ||
11 | + <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('mobile/package/package_spec/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> | ||
12 | + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('mobile/package/package_spec/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> | ||
13 | + | ||
14 | + | ||
15 | + </div> | ||
16 | + <table id="table" class="table table-striped table-bordered table-hover table-nowrap" | ||
17 | + data-operate-edit="{:$auth->check('mobile/package/package_spec/edit')}" | ||
18 | + data-operate-del="{:$auth->check('mobile/package/package_spec/del')}" | ||
19 | + width="100%"> | ||
20 | + </table> | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + | ||
24 | + </div> | ||
25 | + </div> | ||
26 | +</div> |
@@ -31,7 +31,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | @@ -31,7 +31,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | ||
31 | {field: 'current_price', title: __('Current_price'), operate:'BETWEEN'}, | 31 | {field: 'current_price', title: __('Current_price'), operate:'BETWEEN'}, |
32 | {field: 'buy_num_virtual', title: __('Buy_num_virtual')}, | 32 | {field: 'buy_num_virtual', title: __('Buy_num_virtual')}, |
33 | {field: 'buy_num_real', title: __('Buy_num_real')}, | 33 | {field: 'buy_num_real', title: __('Buy_num_real')}, |
34 | - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | 34 | + //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮 |
35 | + { | ||
36 | + field: 'operate', | ||
37 | + title: __('Operate'), | ||
38 | + table: table, | ||
39 | + events: Table.api.events.operate, | ||
40 | + buttons: [ | ||
41 | + { | ||
42 | + name: 'spec', | ||
43 | + text: '规格管理', | ||
44 | + title: '规格管理', | ||
45 | + classname: 'btn btn-xs btn-primary btn-dialog', | ||
46 | + icon: 'fa fa-list', | ||
47 | + url: 'mobile/package/package_spec?package_id={id}', | ||
48 | + } | ||
49 | + ], | ||
50 | + formatter: Table.api.formatter.operate | ||
51 | + } | ||
35 | ] | 52 | ] |
36 | ] | 53 | ] |
37 | }); | 54 | }); |
1 | +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { | ||
2 | + | ||
3 | + var Controller = { | ||
4 | + index: function () { | ||
5 | + // 初始化表格参数配置 | ||
6 | + Table.api.init({ | ||
7 | + extend: { | ||
8 | + index_url: 'mobile/package/package_spec/index' + location.search, | ||
9 | + add_url: 'mobile/package/package_spec/add' + location.search, | ||
10 | + edit_url: 'mobile/package/package_spec/edit', | ||
11 | + del_url: 'mobile/package/package_spec/del', | ||
12 | + multi_url: 'mobile/package/package_spec/multi', | ||
13 | + table: 'mobile_package_spec', | ||
14 | + } | ||
15 | + }); | ||
16 | + | ||
17 | + var table = $("#table"); | ||
18 | + | ||
19 | + // 初始化表格 | ||
20 | + table.bootstrapTable({ | ||
21 | + url: $.fn.bootstrapTable.defaults.extend.index_url, | ||
22 | + pk: 'id', | ||
23 | + sortName: 'id', | ||
24 | + columns: [ | ||
25 | + [ | ||
26 | + {checkbox: true}, | ||
27 | + {field: 'id', title: __('Id')}, | ||
28 | + {field: 'name', title: __('Name')}, | ||
29 | + {field: 'current_price', title: __('Current_price'), operate:'BETWEEN'}, | ||
30 | + {field: 'original_price', title: __('Original_price'), operate:'BETWEEN'}, | ||
31 | + {field: 'people_num', title: __('People_num')}, | ||
32 | + {field: 'is_top', title: __('Is_top'), searchList: {"0":__('Is_top 0'),"1":__('Is_top 1')}, formatter: Table.api.formatter.normal}, | ||
33 | + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | ||
34 | + ] | ||
35 | + ] | ||
36 | + }); | ||
37 | + | ||
38 | + // 为表格绑定事件 | ||
39 | + Table.api.bindevent(table); | ||
40 | + }, | ||
41 | + add: function () { | ||
42 | + Controller.api.bindevent(); | ||
43 | + }, | ||
44 | + edit: function () { | ||
45 | + Controller.api.bindevent(); | ||
46 | + }, | ||
47 | + api: { | ||
48 | + bindevent: function () { | ||
49 | + $(document).on("change", "#c-is_top", function () { | ||
50 | + if($(this).val() == '1'){ | ||
51 | + $('#c-people_num').val(999999); | ||
52 | + } | ||
53 | + }); | ||
54 | + Form.api.bindevent($("form[role=form]")); | ||
55 | + } | ||
56 | + } | ||
57 | + }; | ||
58 | + return Controller; | ||
59 | +}); |
-
请 注册 或 登录 后发表评论