diff --git a/app/data/controller/ShopTruckCompany.php b/app/data/controller/ShopTruckCompany.php index a92b5525d..90fc3dc83 100644 --- a/app/data/controller/ShopTruckCompany.php +++ b/app/data/controller/ShopTruckCompany.php @@ -3,7 +3,6 @@ namespace app\data\controller; use app\data\service\TruckService; -use app\store\service\OpenCuciService; use think\admin\Controller; use think\admin\service\SystemService; use think\exception\HttpResponseException; @@ -75,7 +74,10 @@ class ShopTruckCompany extends Controller */ public function state() { - $this->_save($this->table); + $this->_save($this->table, $this->_vali([ + 'status.in:0,1' => '状态值范围异常!', + 'status.require' => '状态值不能为空!', + ])); } /** diff --git a/app/data/controller/ShopTruckTemplate.php b/app/data/controller/ShopTruckTemplate.php index b7988756f..a360aca69 100644 --- a/app/data/controller/ShopTruckTemplate.php +++ b/app/data/controller/ShopTruckTemplate.php @@ -5,10 +5,9 @@ namespace app\data\controller; use app\data\service\TruckService; use think\admin\Controller; use think\admin\extend\CodeExtend; -use think\admin\extend\DataExtend; /** - * 配送运费模板管理 + * 邮费模板管理 * Class ShopTruckTemplate * @package app\data\controller */ @@ -31,12 +30,14 @@ class ShopTruckTemplate extends Controller public function index() { $this->title = '快递邮费配置'; - $query = $this->_query($this->table)->like('name'); + $query = $this->_query($this->table); + $query->like('code,name')->dateBetween('create_at'); $query->where(['deleted' => 0])->order('sort desc,id desc')->page(); } /** * 添加配送邮费模板 + * @auth true * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException @@ -44,7 +45,20 @@ class ShopTruckTemplate extends Controller public function add() { $this->title = '添加配送邮费模板'; - $this->_form($this->table, 'form'); + $this->_form($this->table, 'form', 'code'); + } + + /** + * 编辑配送邮费模板 + * @auth true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function edit() + { + $this->title = '编辑配送邮费模板'; + $this->_form($this->table, 'form', 'code'); } /** @@ -61,41 +75,38 @@ class ShopTruckTemplate extends Controller } } - public function region() + /** + * 表单结果处理 + * @param boolean $result + */ + protected function _form_result($result) { - $this->citys = TruckService::instance()->region(2); - $this->fetch('form_region'); + if ($result && $this->request->isPost()) { + $this->success('邮费模板保存成功!', 'javascript:history.back()'); + } } /** - * 修改快递模板 + * 启用或禁用邮费模板 * @auth true * @throws \think\db\exception\DbException */ - public function edit() + public function state() { - [$list, $idxs, $post] = [[], [], $this->request->post()]; - foreach (array_keys($post) as $key) if (stripos($key, 'order_reduction_state_') !== false) { - $idxs[] = str_replace('order_reduction_state_', '', $key); - } - foreach (array_unique($idxs) as $index) if (!empty($post["rule_{$index}"])) $list[] = [ - 'rule' => ',' . join(',', $post["rule_{$index}"]) . ',', - // 订单满减配置 - 'order_reduction_state' => $post["order_reduction_state_{$index}"], - 'order_reduction_price' => $post["order_reduction_price_{$index}"], - // 首件邮费配置 - 'first_number' => $post["first_number_{$index}"], - 'first_price' => $post["first_price_{$index}"], - // 首件邮费配置 - 'next_number' => $post["next_number_{$index}"], - 'next_price' => $post["next_price_{$index}"], - // 默认邮费规则 - 'is_default' => $post["is_default_{$index}"], - ]; - if (empty($list)) $this->error('请配置有效的邮费规则'); - $this->app->db->name($this->table)->where('1=1')->delete(); - $this->app->db->name($this->table)->insertAll($list); - $this->success('邮费规则配置成功!'); + $this->_save($this->table, $this->_vali([ + 'status.in:0,1' => '状态值范围异常!', + 'status.require' => '状态值不能为空!', + ]), 'code'); + } + + /** + * 删除邮费模板 + * @auth true + * @throws \think\db\exception\DbException + */ + public function remove() + { + $this->_delete($this->table, 'code'); } } \ No newline at end of file diff --git a/app/data/view/shop_truck_template/form.html b/app/data/view/shop_truck_template/form.html index 2fdfd3b5f..80f226428 100644 --- a/app/data/view/shop_truck_template/form.html +++ b/app/data/view/shop_truck_template/form.html @@ -2,7 +2,7 @@ {block name="content"}
-
+
@@ -83,6 +86,7 @@
+
@@ -104,6 +108,22 @@ $rootScope.rules = []; $rootScope.city = {subs: []}; $rootScope.citys = angular.fromJson(_data) || []; + /*! 生成待提交的数据 */ + $rootScope.getRuleData = function () { + var data = []; + $rootScope.rules.forEach(function (rule) { + var item = {city: [], rule: rule.rule}; + rule.city.forEach(function (province) { + var citys = []; + province.subs.forEach(function (city) { + citys.push(city.name) + }); + item.city.push({name: province.name, subs: citys}) + }); + if (item.city.length > 0) data.push(item); + }); + return data; + }; /*! 默认显示城市 */ $rootScope.citys.forEach(function (item) { delete item.id, delete item.pid; @@ -196,16 +216,18 @@ if (item.show) item.status = !!province.status; }); }; + /*! 显示区域选择器 */ $rootScope.showDialog = function () { layui.layer.open({ - type: 1, shade: false, area: '800px', title: '选择配送区域', + type: 1, shade: false, area: '800px', title: '区域选择器', content: $('#RegionDialog').removeClass('layui-hide'), end: function () { $('#RegionDialog').addClass('layui-hide'); $rootScope.SetRuleItem(); } }); }; - $rootScope.$watch('citys', function () { + /*! 实时生成规则数据 */ + $rootScope.setRuleData = function () { /*! 合并当前操作数据到缓存 */ var _province_cache = {}, _city_cache = {}; $rootScope.rule.city.forEach(function (province) { @@ -238,7 +260,27 @@ if (province.subs.length > 0) provinces.push(province); } $rootScope.rule.city = provinces; - }, true); + } + /*! 数据变化监听处理 */ + $rootScope.$watch('citys', $rootScope.setRuleData, true); + /*! 默认数据显示处理 */ + var defaultItems = angular.fromJson($('[name="default"]').val() || '[]') || []; + defaultItems.forEach(function (item) { + $rootScope.rule = angular.fromJson(angular.toJson(_rule)); + $rootScope.rule.rule = item.rule; + $rootScope.rules.push($rootScope.rule); + item.city.forEach(function (province) { + province.subs.forEach(function (city) { + $rootScope.citys.forEach(function (_item) { + _item.subs.forEach(function (_city) { + if (_city.name === city) _city.status = true; + }); + }); + }); + }); + $rootScope.setRuleData(); + $rootScope.SetRuleItem(); + }); } }); diff --git a/app/data/view/shop_truck_template/form_item.html b/app/data/view/shop_truck_template/form_item.html deleted file mode 100644 index 2ea51412c..000000000 --- a/app/data/view/shop_truck_template/form_item.html +++ /dev/null @@ -1,55 +0,0 @@ -
- - - {$group|default='邮费规则分组'} - - - - {if $group neq '默认邮费模板'} - - - - - {else} - - {/if} - -
- -
订单总金额满足条件时将减免该订单的所有邮费(请谨慎配置)
- -
- -
- -
- -
-
- -
-
- 根据配送目的地的省份进行运费计算邮费(不在规则内的将使用默认邮费规则) -
- -
-
首件(个)
-
运费(元)
-
续件(个)
-
续费(元)
- - - - -
-
- -
\ No newline at end of file diff --git a/app/data/view/shop_truck_template/form_region.html b/app/data/view/shop_truck_template/form_region.html deleted file mode 100644 index e1195be88..000000000 --- a/app/data/view/shop_truck_template/form_region.html +++ /dev/null @@ -1,98 +0,0 @@ -
-
-
-
-
-
- 全选 - 取消 -
-
-
-
- - {{x.name}} -
-
-
-
-
-
-
- 全选 - 取消 - -
-
- -
-
-
-
{{items}}
-
-
- - -
-
-
- - - - diff --git a/app/data/view/shop_truck_template/index.html b/app/data/view/shop_truck_template/index.html index 91ec61e1b..f0b7c3307 100644 --- a/app/data/view/shop_truck_template/index.html +++ b/app/data/view/shop_truck_template/index.html @@ -24,8 +24,10 @@ + 模板编号 模板名称 - 创建时间 + 使用状态 + 创建时间 @@ -41,19 +43,21 @@ + {$vo.code|default=''} {$vo.name|default=''} - {$vo.create_at|format_datetime} + {if $vo.status eq 0}已禁用{elseif $vo.status eq 1}使用中{/if} + {$vo.create_at|format_datetime} - 编 辑 + 编 辑 - 禁 用 + 禁 用 - 启 用 + 启 用 - 删 除 + 删 除 diff --git a/app/data/view/shop_truck_template/index_search.html b/app/data/view/shop_truck_template/index_search.html index d7c0b0756..10e847c8a 100644 --- a/app/data/view/shop_truck_template/index_search.html +++ b/app/data/view/shop_truck_template/index_search.html @@ -2,15 +2,15 @@ 条件搜索