diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 16da83c..94471e2 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -6,6 +6,7 @@ use app\model\Account; use app\model\Coupon as CouponModel; use app\model\CouponBill; use app\model\CouponMain; +use app\model\CouponType as CouponTypeModel; use app\model\Deduction; use app\model\Redpack; use app\model\Business as BusinessModel; @@ -559,6 +560,8 @@ class Coupon extends Base } } + + //验证通过 不管是商家还是工作人员 都可以发布优惠券 $couponMain = [ "name" => $data['name'] ?? '', @@ -596,6 +599,12 @@ class Coupon extends Base return $this->json(4001, $usingRuleValidate->getError()); } + //检查类型 + if(CouponTypeModel::checkType($couponMain['type']) !== true){ + return $this->json(4001, '优惠券类型不存在'); + } + + //验证通过 $couponMain['business_type'] = $account->business['type']; $couponMain['business_name'] = $account->business['business_name']; @@ -689,6 +698,10 @@ class Coupon extends Base return $this->json(4001, $usingRuleValidate->getError()); } + //检查类型 + if(CouponTypeModel::checkType($couponMainData['type']) !== true){ + return $this->json(4001, '优惠券类型不存在'); + } //验证通过 Db::startTrans(); diff --git a/app/controller/manager/Category.php b/app/controller/manager/Category.php index f76f670..bc6ebdc 100644 --- a/app/controller/manager/Category.php +++ b/app/controller/manager/Category.php @@ -2,6 +2,7 @@ namespace app\controller\manager; +use app\repository\BusinessRepository; use app\repository\CmsRepository; use app\model\Log; use app\model\Category as CategoryModel; @@ -53,16 +54,7 @@ class Category extends Base Db::startTrans(); try { - $oldPath = $info['path'] ?? ''; - $item['path'] = CategoryModel::getPath($item['pid']); $info->save($item); - - //刷新所有路径 - $oldPath = $oldPath.','.$id; - $newPath = $item['path'].','.$id; - if ($oldPath != $newPath) { - CategoryModel::refreshPath(); - } Db::commit(); return $this->json(); } catch (ValidateException $e) { @@ -123,8 +115,13 @@ class Category extends Base $ids = $this->request->param('ids/a', []); if(!empty(CategoryModel::findOne([["pid","in",$ids]]))){ - return $this->json(5001,"该栏目还有下级 不能删除"); + return $this->json(4001,"该栏目还有下级,不能删除"); } + $business = BusinessRepository::getInstance()->findOneByWhere([["type","in",$ids]]); + if(!empty($business)){ + return $this->json(4001,"该栏目还有商家存在,不能删除"); + } + CategoryModel::destroy($ids); return $this->json(); } diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index fab87a6..df9e81a 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -5,6 +5,7 @@ namespace app\controller\manager; use app\exception\RepositoryException; use app\model\CouponMain; +use app\model\CouponType as CouponTypeModel; use app\model\Business as BusinessModel; use app\model\Member as MemberModel; use app\repository\BusinessRepository; @@ -197,6 +198,10 @@ class Coupon extends Base } } + //检查类型 + if(CouponTypeModel::checkType($data['type']) !== true){ + return $this->json(4001, '优惠券类型不存在'); + } $data['business_type'] = $business['type']; @@ -206,11 +211,8 @@ class Coupon extends Base $data['business_circle_id'] = $business['business_circle_id']; - $type = CouponRepository::getInstance()->getCouponTypeAll(); - $type = array_column($type->toArray(), null, "id"); - if (!isset($type[$data['type']])) { - return $this->json(4001, '优惠券类型不存在'); - } + + $data['commission_agency'] = input("item.commission_agency/d", 0); $data['commission_admin'] = input("item.commission_admin/d", 0); $data['commission_consumer'] = input("item.commission_consumer/d", 0); @@ -294,6 +296,12 @@ class Coupon extends Base if (empty($business)) { return $this->json(4001, '商家不存在'); } + + //检查类型 + if(CouponTypeModel::checkType($data['type']) !== true){ + return $this->json(4001, '优惠券类型不存在'); + } + //更新经纬度 $data['business_type'] = $business['type']; $data['business_name'] = $business['business_name']; @@ -339,4 +347,6 @@ class Coupon extends Base } + + } \ No newline at end of file diff --git a/app/controller/manager/CouponType.php b/app/controller/manager/CouponType.php new file mode 100644 index 0000000..7e86e62 --- /dev/null +++ b/app/controller/manager/CouponType.php @@ -0,0 +1,143 @@ +json(4001, '记录不存在'); + } + + if ($this->request->isPost()) { + $item = input('post.'); + $validate = $this->validateByApi($item, [ + 'name|标题' => 'require|max:100|unique:coupon_type,name,'.$id, + ]); + + if ($validate !== true) { + return $validate; + } + + Db::startTrans(); + try { + $info->save($item); + Db::commit(); + return $this->json(); + } catch (ValidateException $e) { + Db::rollback(); + return $this->json(4001, $e->getError()); + } + } + + $this->data['item'] = $info; + + return $this->view(); + } + + /** + * 添加 + * + * @return Json|View + * @throws Exception + */ + public function add() + { + if ($this->request->isPost()) { + $item = input('post.'); + $validate = $this->validateByApi($item, [ + 'name|标题' => 'require|max:100', + ]); + + if ($validate !== true) { + return $validate; + } + try { + CouponTypeModel::create($item); + return $this->json(); + } catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } + } + + return $this->view(); + } + + + /** + * 删除 + * @return Json + */ + public function del() + { + if (!$this->request->isPost()) { + return $this->json(4000, '非法请求'); + } + + $ids = $this->request->param('ids/a', []); + + $couponMain = CouponMain::findOne([["type","in",$ids]]); + if(!empty($couponMain)){ + return $this->json(4001,"该优惠券绑定了该类型,不能删除"); + } + + CouponTypeModel::destroy($ids); + return $this->json(); + } + + /** + * 列表 + * + * @return Json|View + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function index() + { + if ($this->request->isPost()) { + $menus = CouponTypeModel::getList(); + $res = [ + 'code' => 0, + 'msg' => 'success', + 'count' => $menus->count(), + 'data' => $menus->toArray(), + ]; + return json($res); + } + return $this->view(); + } + +} \ No newline at end of file diff --git a/app/model/CouponType.php b/app/model/CouponType.php index 31a487d..85d3db6 100644 --- a/app/model/CouponType.php +++ b/app/model/CouponType.php @@ -2,6 +2,7 @@ namespace app\model; +use app\repository\CouponRepository; use think\Collection; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; @@ -14,5 +15,28 @@ use think\db\exception\ModelNotFoundException; */ class CouponType extends Base { + /** + * 获取全部列表 + * + * @return Collection + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function getList() + { + return self::field('id,name')->order('id', 'desc')->select(); + } + /** + * 检查类型 + * */ + public static function checkType($valueData){ + $type = CouponRepository::getInstance()->getCouponTypeAll(); + $type = array_column($type->toArray(), null, "id"); + if (!isset($type[$valueData])) { + return false; + } + return true; + } } \ No newline at end of file diff --git a/public/static/manager/js/category.js b/public/static/manager/js/category.js index 7f2832f..08173c8 100644 --- a/public/static/manager/js/category.js +++ b/public/static/manager/js/category.js @@ -32,7 +32,7 @@ layui.use(['laytpl', 'treeTable','jquery', 'form', 'miniTab', 'xmSelect'], funct cols: [[ {type: 'checkbox'}, {field: 'name', minWidth: 200, title: '名称'}, - {field: 'commision', width: 80, align: 'center', title: '默认佣金', edit: 'text'}, + // {field: 'commision', width: 80, align: 'center', title: '默认佣金', edit: 'text'}, {templet: '#menu-operate', width: 150, align: 'center', title: '操作'} ]], done: function () { diff --git a/public/static/manager/js/coupon_type.js b/public/static/manager/js/coupon_type.js new file mode 100644 index 0000000..b3580c2 --- /dev/null +++ b/public/static/manager/js/coupon_type.js @@ -0,0 +1,184 @@ +layui.use(['laytpl', 'treeTable','jquery', 'form', 'miniTab', 'xmSelect'], function () { + let $ = layui.jquery, + form = layui.form, + treeTable = layui.treeTable, + layer = layui.layer, + miniTab = layui.miniTab, + xmSelect = layui.xmSelect; + + let modifyUrl = $('#row-modify').data('url'); + + /**** index begin ***/ + //index页面 + if ($('.location-index-page').length > 0) { + miniTab.listen(); + + // 渲染表格 + let listUrl = $('#menu-table').data('url'); + let insTb = treeTable.render({ + elem: '#menu-table', + toolbar: '#toolbar-tpl', + defaultToolbar: [], + method: 'POST', + skin: 'line', + url: listUrl, + page: false, + tree: false, + cols: [[ + {type: 'checkbox'}, + {field: 'name', minWidth: 200, title: '名称'}, + // {field: 'commision', width: 80, align: 'center', title: '默认佣金', edit: 'text'}, + {templet: '#menu-operate', width: 150, align: 'center', title: '操作'} + ]], + done: function () { + } + }); + + //监听单元格编辑 + treeTable.on('edit(menu-table)', function(obj){ + $.post(modifyUrl, {id: obj.data.id, field: obj.field, value: obj.value}, function (res) { + layer.msg(res.msg) + if (res.code === 0) { + insTb.refresh(); + } + }) + + }); + + //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 + treeTable.on('toolbar(menu-table)', function (obj) { + let layEvent = obj.event; + + if (layEvent === 'expand') { + insTb.expandAll(); + return false; + } + + if (layEvent === 'fold') { + insTb.foldAll(); + return false; + } + + if (layEvent === 'del') { + let selected = insTb.checkStatus(false); + let ids = []; + let url = $(obj.elem.context).data('href') + $.each(selected, function (index, val) { + ids.push(val.id); + }) + + del(url, ids); + return false; + } + + if (layEvent === 'add') { + let url = $(obj.elem.context).data('href'); + let title = $(obj.elem.context).data('title'); + let index = layer.open({ + title: title, + type: 2, + shade: 0.2, + maxmin: true, + shadeClose: true, + area: ['100%', '100%'], + content: url, + }); + $(window).on("resize", function () { + layer.full(index); + }); + return false; + } + }); + + //刷新 + $('body').on('click', '[data-table-refresh]', function () { + insTb.refresh(); + }); + + //删除 + function del(url, ids) { + let index = layer.confirm('确认删除吗?', { + btn: ['确认','取消'], //按钮 + title: '操作提示', + }, function() { + $.post(url, {ids: ids}, function (res) { + layer.msg(res.msg) + if (res.code === 0) { + insTb.refresh(); + } + }) + }, function(){ + layer.close(index) + return false; + }); + } + + //监听工具条 + treeTable.on('tool(menu-table)', function (obj) { + let data = obj.data; + let layEvent = obj.event; + let url = $(obj.tr.context).data('href'); + let title = $(obj.tr.context).data('title'); + + if (layEvent === 'del') { + let ids = [data.id]; + del(url, ids); + return false; + } + + if (layEvent === 'edit') { + let index = layer.open({ + title: title, + type: 2, + shade: 0.2, + maxmin: true, + shadeClose: true, + area: ['100%', '100%'], + content: url, + }); + + $(window).on("resize", function () { + layer.full(index); + }); + return false; + } + }); + } + /*** index end ***/ + + + // add和edit页面 + if ($('.location-operate-page').length > 0) { + let parentMenu = $('#parent-menu'); + let menuList = parentMenu.data('menu') ? parentMenu.data('menu') : []; + xmSelect.render({ + el: '#parent-menu', + paging: false, + autoRow: true, + radio: true, + clickClose: true, + name: 'pid', + tips: '请选择上级分类', + direction: 'auto', + height: 'auto', + model: { + icon: 'hidden', + }, + prop: { + name: 'name', + value: 'id', + }, + tree: { + show: true, + strict: false, + clickCheck: true, + expandedKeys: true, + clickExpand: false + }, + theme: { + color: '#1e84ff', + }, + data: menuList + }); + } +}); \ No newline at end of file diff --git a/public/static/manager/js/get_addredss.js b/public/static/manager/js/get_addredss.js index 5ccb104..2d22d4b 100644 --- a/public/static/manager/js/get_addredss.js +++ b/public/static/manager/js/get_addredss.js @@ -22,11 +22,13 @@ function getAddress(lat,lng,obj){ // console.log(address) $(obj).text(data.result.address + address); } else { - alert("位置获取错误,请联系管理员!") + console.log(data) + alert("位置获取错误,可能用户信息不完整") } }, - error: function () { - alert("位置获取错误,请联系管理员!") + error: function (e) { + console.log(e) + alert("位置获取错误,map服务出错") } }); } diff --git a/view/manager/business/business_detail.html b/view/manager/business/business_detail.html index 200c73d..b3f97f5 100644 --- a/view/manager/business/business_detail.html +++ b/view/manager/business/business_detail.html @@ -20,8 +20,8 @@