From 0fbd584ac07464dcb77a68cfeef708966e49ef5f Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Wed, 6 Apr 2022 11:24:04 +0800 Subject: [PATCH] setter --- app/controller/api/Consumer.php | 39 +++++- app/controller/manager/Slide.php | 133 ++++++++++++++++++++- app/model/Base.php | 17 +++ public/static/manager/js/slide.js | 9 +- view/manager/slide/agency_poster.html | 55 +++++++++ view/manager/slide/agency_poster_add.html | 69 +++++++++++ view/manager/slide/agency_poster_edit.html | 69 +++++++++++ view/manager/slide/index.html | 2 +- 8 files changed, 386 insertions(+), 7 deletions(-) create mode 100644 view/manager/slide/agency_poster.html create mode 100644 view/manager/slide/agency_poster_add.html create mode 100644 view/manager/slide/agency_poster_edit.html diff --git a/app/controller/api/Consumer.php b/app/controller/api/Consumer.php index dfe90fc..f25d273 100644 --- a/app/controller/api/Consumer.php +++ b/app/controller/api/Consumer.php @@ -2,7 +2,9 @@ namespace app\controller\api; use app\model\CouponMain; +use app\model\Member; use app\model\Slide; +use app\model\Business; use app\repository\AccountRepository; use app\repository\BusinessRepository; use app\repository\CouponRepository; @@ -180,10 +182,45 @@ class Consumer extends Base public function advertisement() { $repo = OperationRepository::getInstance(); - $whereMap = []; + $orders = ['sort'=>'asc']; $page = input("page/d",1); $size = input("size/d",1000); + + $couponId = input("coupon_id/d",0); + $coupon = CouponRepository::getInstance()->findById($couponId, [], function ($q) { + return $q->with([ + "business" => function ($q) { + $q->field("code,id,business_name,business_subtitle,is_assign,agency_code"); + } + ]); + }); + if(empty($coupon)){ + return $this->json(4001,"优惠券不存在"); + } + if(!isset($coupon->business)||empty($coupon->business)){ + return $this->json(4001,"优惠券商家不存在"); + } + + //如果优惠券所属商家指派了渠道商 + if ($coupon->business->is_assign == Business::COMMON_ON && !empty($coupon->business->agency_code)) { + $agency = Member::findOne([["business_code","=",$coupon->business->agency_code]]); + if(empty($agency)){ + $awhereMap = []; + $awhereMap[] = ['position', '=', Slide::advertisement]; + $awhereMap[] = ['agency_id', '=', $agency["id"]]; + $list = $repo->slideList($awhereMap, ["id","title","src as image","url","url_type as type"], $page, $size, function ($q){ + return $q->withAttr("image",function ($value){ + return $this->request->domain() . $value; + }); + }, $orders); + + return $this->json(1,"ok",$list["list"]); + } + } + + + $whereMap = []; $whereMap[] = ['position', '=', Slide::advertisement]; $list = $repo->slideList($whereMap, ["id","title","src as image","url","url_type as type"], $page, $size, function ($q){ return $q->withAttr("image",function ($value){ diff --git a/app/controller/manager/Slide.php b/app/controller/manager/Slide.php index 9f20e17..7b4cc3a 100644 --- a/app/controller/manager/Slide.php +++ b/app/controller/manager/Slide.php @@ -3,6 +3,7 @@ namespace app\controller\manager; use app\model\Log; +use app\model\Slide as MSlide; use app\repository\CmsRepository; use app\repository\OperationRepository; use app\validate\Slide as VSlide; @@ -89,7 +90,9 @@ class Slide extends Base $page = $this->request->param('page/d', 1); $size = $this->request->param('size/d', 30); - $whereMap = []; + $whereMap = [ + ['agency_id', '=', 0] + ]; $orders = ['sort'=>'asc']; if (!empty($position)) { $whereMap[] = ['position', '=', $position]; @@ -274,4 +277,132 @@ class Slide extends Base } + /** + * 编辑 + * + * @return Json|View + * @throws DbException + * @throws ModelNotFoundException + */ + public function agencyPosterEdit() + { + $id = $this->request->param('id/d', 0); + + if (!$slide = OperationRepository::getInstance()->findSlideById($id)) { + return $this->json(4001, '数据不存在'); + } + + if ($this->request->isPost()) { + $item = input('post.item/a'); + $item["position"] = MSlide::advertisement; + $validate = new VSlide(); + if (!$validate->scene('slide')->check($item)) { + return $this->json(4002, $validate->getError()); + } + + unset($item['id']); + OperationRepository::getInstance()->updateSlide($item, $id); + return $this->json(); + } + + $this->data['item'] = $slide; + $this->data['id'] = $id; + + return $this->view(); + } + + /** + * 添加 + * + * @return View|Json + */ + public function agencyPosterAdd() + { + $repo = OperationRepository::getInstance(); + + if ($this->request->isPost()) { + $item = input('post.item/a'); + $item["position"] = MSlide::advertisement; + $item["agency_id"] = $this->auth["user_id"]; + $validate = new VSlide(); + if (!$validate->scene('slide')->check($item)) { + return $this->json(4002, $validate->getError()); + } + + $item['type'] = $item['type'] ?? 'img'; + $repo->createSlide($item); + return $this->json(); + } + + $this->data['positionsJson'] = $this->xmSelectPositionsJson(); + return $this->view(); + } + + /** + * 轮播图列表 + * + * @return Json|View + * @throws Exception + */ + public function agencyPoster() + { + $repo = OperationRepository::getInstance(); + if ($this->request->isPost()) { + $position = MSlide::advertisement; + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 30); + + $whereMap = [ + ['agency_id', '=', $this->auth["user_id"]], + ['position', '=', $position] + ]; + $orders = ['sort'=>'asc']; + $list = $repo->slideList($whereMap, [], $page, $size, null, $orders); + return $this->json(0, 'success', $list); + } + return $this->view(); + } + + /** + * 排序 + * @return Json + */ + public function agencyPosterSort() + { + if (!$this->request->isPost()) { + return $this->json(4000, '非法请求'); + } + try { + $id = $this->request->param('id/d', 0); + $sort = $this->request->param('sort/d', 0); + OperationRepository::getInstance()->updateSlide(['sort'=>$sort], $id); + } catch (Exception $e) { + return $this->json(4001, '排序失败'); + } + return $this->json(); + } + + /** + * 删除 + * @return Json + */ + public function agencyPosterDel() + { + if (!$this->request->isPost()) { + return $this->json(4000, '非法请求'); + } + + $ids = $this->request->param('ids/a', []); + if (empty($ids)) { + $ids[] = $this->request->param('id/d', 0); + $ids = array_filter($ids); + } + + if (count($ids)) { + OperationRepository::getInstance()->deleteSlides($ids); + Log::write(get_class(), 'del', '删除了轮播图,涉及到的ID为:'.implode(',', $ids)); + } + return $this->json(); + } + } \ No newline at end of file diff --git a/app/model/Base.php b/app/model/Base.php index 91af862..3838982 100644 --- a/app/model/Base.php +++ b/app/model/Base.php @@ -324,6 +324,23 @@ class Base extends Model + /** + * 刷新路径 + * + * @param int $pid + * @param array $data 默认全部 若data不为空 至少包含[id,path, $pidField] + * @param string $pidField 父级ID字段名 默认 pid + * @throws Exception + */ + public static function refreshPath(int $pid = 0, array $data = [], string $pidField = 'pid') + { + $data = !empty($data) ? $data : self::column('id,path,'.$pidField); + $updateAllPaths = []; + self::recursionPath($pid, $data, $updateAllPaths); + + (new static())->saveAll($updateAllPaths); + } + /** * 获取递归最新路径 * diff --git a/public/static/manager/js/slide.js b/public/static/manager/js/slide.js index 111c5f5..c63bcba 100644 --- a/public/static/manager/js/slide.js +++ b/public/static/manager/js/slide.js @@ -13,6 +13,7 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function // 渲染表格 let listUrl = $('#table-container').data('url'); + let sort = $('#table-container-sort').data('url'); let insTb = table.render({ elem: '#table-container', toolbar: '#toolbar-tpl', @@ -43,11 +44,11 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function {field: 'id', width: 80, title: 'ID'}, {field: 'title', minWidth: 200, title: '标题'}, {templet: '#row-cover', minWidth:150, title: '轮播图', style: 'height: 90px;'}, - {field: 'url', minWidth: 250, title: '跳转链接'}, - {field: 'position', minWidth: 150, title: '位置标识'}, + {field: 'url', title: '跳转链接'}, + {field: 'position', title: '位置标识'}, {field: 'created_at', width: 170, title: '创建时间'}, {field: 'sort', width: 80, title: '排序', edit: 'text'}, - {templet: '#row-operate', minWidth: 150, field: 'right', align: 'center', title: '操作', fixed: 'right'} + {templet: '#row-operate', minWidth: 150, align: 'center', title: '操作',} ]], done: function () { Tools.setInsTb(insTb); @@ -70,7 +71,7 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function table.on('edit(table-container)', function (obj) { let id = obj.data.id; if (obj.field == 'sort') { - $.ajax('/manager/slide/sort', { + $.ajax(sort, { data: { "sort": obj.value, "id": id diff --git a/view/manager/slide/agency_poster.html b/view/manager/slide/agency_poster.html new file mode 100644 index 0000000..9bc23f6 --- /dev/null +++ b/view/manager/slide/agency_poster.html @@ -0,0 +1,55 @@ +{layout name="manager/layout" /} + + +