moonsflyer 5 месяцев назад
Родитель
Сommit
1b70e70f54

+ 111 - 0
app/adminapi/controller/banner/BannerController.php

@@ -0,0 +1,111 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop100%开源免费商用商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | 商业版本务必购买商业授权,以免引起法律纠纷
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshopTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\controller\banner;
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\banner\BannerLists;
+use app\adminapi\logic\goods\GoodsBrandLogic;
+use app\adminapi\logic\banner\BannerLogic;
+use app\adminapi\validate\banner\BannerValidate;
+
+class BannerController extends BaseAdminController
+{
+    /**
+     * @notes 添加信息轮播图
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/14 3:04
+     */
+    public function add()
+    {
+        $params = (new BannerValidate())->post()->goCheck('add');
+        (new BannerLogic())->add($params);
+        return $this->success('添加轮播图成功',[],1,1);
+    }
+
+    /**
+     * @notes 查看轮播图
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/14 5:41
+     */
+    public function lists()
+    {
+        return $this->dataLists(new BannerLists());
+    }
+
+    /**
+     * @notes 删除商品品牌
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/14 7:07
+     */
+    public function del()
+    {
+        $params = (new BannerValidate())->post()->goCheck('del');
+        (new BannerLogic())->del($params);
+        return $this->success('删除成功',[],1,1);
+    }
+
+    /**
+     * @notes 编辑轮播图
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/15 10:55
+     */
+    public function edit()
+    {
+        $params = (new BannerValidate())->post()->goCheck('edit');
+        (new BannerLogic())->edit($params);
+        return $this->success('修改成功',[],1,1);
+    }
+
+    /**
+     * @notes 修改轮播图状态
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2021/7/15 11:42
+     */
+    public function status()
+    {
+        $params = (new BannerValidate())->post()->goCheck('status');
+        (new BannerLogic())->status($params);
+        return $this->success('状态修改成功',[],1,1);
+    }
+
+    /**
+     * @notes 查看轮播图详情
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2021/7/19 4:46 下午
+     */
+    public function detail()
+    {
+        $params = (new BannerValidate())->goCheck('detail');
+        $result = (new BannerLogic())->detail($params);
+        return $this->success('轮播图详情获取成功',$result,1,0);
+    }
+}

+ 78 - 0
app/adminapi/lists/banner/BannerLists.php

@@ -0,0 +1,78 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\banner;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\Banner;
+
+
+class BannerLists extends BaseAdminDataLists
+{
+    /**
+     * @notes 搜索条件
+     * @return array
+     * @author ljj
+     * @date 2022/3/30 5:12 下午
+     */
+    public function setSearch(): array
+    {
+        $where = [];
+        $params = $this->params;
+
+        if (isset($params['type']) && $params['type'] != '') {
+            $where[] = ['type', '=', $params['type']];
+        }
+
+        return $where;
+    }
+
+    /**
+     * @notes 轮播图列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function lists(): array
+    {
+        $lists = Banner::where($this->setSearch())
+            ->field('id,type,image,status,sort,create_time')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->append(['status_desc','type_desc'])
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+
+        return $lists;
+    }
+
+    /**
+     * @notes 轮播图数量
+     * @return int
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function count(): int
+    {
+        return Banner::where($this->setSearch())->count();
+    }
+}

+ 109 - 0
app/adminapi/logic/banner/BannerLogic.php

@@ -0,0 +1,109 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop100%开源免费商用商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | 商业版本务必购买商业授权,以免引起法律纠纷
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshopTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\banner;
+
+
+use app\common\enum\DefaultEnum;
+use app\common\enum\YesNoEnum;
+use app\common\model\GoodsBrand;
+use app\common\model\Banner;
+class BannerLogic
+{
+    /**
+     * @notes 添加轮播图
+     * @param $params
+     * @return bool
+     * @author ljj
+     * @date 2021/7/14 5:00
+     */
+    public function add($params)
+    {
+        $banner = new Banner;
+        $banner->type = $params['type'];
+        $banner->image = $params['image'] ?? '';
+        $banner->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 1;
+        $banner->status = $params['status'] ?? YesNoEnum::YES;
+        return $banner->save();
+    }
+
+    /**
+     * @notes 删除轮播图
+     * @param $params
+     * @return bool
+     * @author ljj
+     * @date 2021/7/15 10:37
+     */
+    public function del($params)
+    {
+        return Banner::destroy($params['id']);
+    }
+
+    /**
+     * @notes 编辑轮播图
+     * @param $params
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2021/7/15 11:05
+     */
+    public function edit($params)
+    {
+        $banner = Banner::find($params['id']);
+        $banner->type = $params['type'];
+        $banner->image = $params['image'] ?? '';
+        $banner->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 1;
+        $banner->status = $params['status'] ?? YesNoEnum::YES;
+        return $banner->save();
+    }
+
+    /**
+     * @notes 修改轮播图状态
+     * @param $params
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2021/7/15 11:41
+     */
+    public function status($params)
+    {
+        $Banner = Banner::find($params['id']);
+        $Banner->status = $params['status'];
+        return $Banner->save();
+    }
+
+    /**
+     * @notes 查看轮播图详情
+     * @param $params
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2021/7/19 4:45 下午
+     */
+    public function detail($params)
+    {
+        return Banner::find($params['id'])->toArray();
+    }
+}

+ 67 - 0
app/adminapi/validate/banner/BannerValidate.php

@@ -0,0 +1,67 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop100%开源免费商用商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | 商业版本务必购买商业授权,以免引起法律纠纷
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshopTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\banner;
+
+
+use app\common\model\GoodsBrand;
+use app\common\validate\BaseValidate;
+
+class BannerValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'type' => 'require|in:1,2,3',
+        'image' => 'require',
+        'status' => 'in:0,1',
+        'sort' => 'number',
+    ];
+
+    protected $message = [
+        'id.require' => '轮播图id不能为空',
+        'image.require' => '轮播图不能为空',
+    ];
+
+    public function sceneAdd()
+    {
+        return $this->only(['type','image','sort']);
+    }
+
+    public function sceneDel()
+    {
+        return $this->only(['id']);
+    }
+
+    public function sceneEdit()
+    {
+        return $this->only(['id','type','image']);
+    }
+
+    public function sceneStatus()
+    {
+        return $this->only(['id','is_show'])
+            ->remove('id','checkDel');
+    }
+
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 18 - 0
app/common/enum/YesNoEnum.php

@@ -67,6 +67,24 @@ class YesNoEnum
         }
         return $data[$value];
     }
+    /**
+     * @notes 获取显示隐藏状态
+     * @param bool $value
+     * @return string|string[]
+     * @author ljj
+     * @date 2021/7/31 6:05 下午
+     */
+    public static function getStatusDesc($value = true)
+    {
+        $data = [
+            self::YES => '显示',
+            self::NO => '隐藏'
+        ];
+        if ($value === true) {
+            return $data;
+        }
+        return $data[$value];
+    }
 
     /**
      * @notes 获取启用停用状态

+ 73 - 0
app/common/model/Banner.php

@@ -0,0 +1,73 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop100%开源免费商用商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | 商业版本务必购买商业授权,以免引起法律纠纷
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshopTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model;
+
+use app\common\enum\YesNoEnum;
+use app\common\service\FileService;
+use think\model\concern\SoftDelete;
+
+class Banner extends BaseModel
+{
+    use SoftDelete;
+    protected $deleteTime = 'delete_time';
+
+    /**
+     * @notes 一对多关联商品模型
+     * @return \think\model\relation\HasMany
+     * @author ljj
+     * @date 2021/7/15 10:37
+     */
+    public function goods()
+    {
+        return $this->hasMany(Goods::class,'brand_id','id');
+    }
+
+    /**
+     * @notes 状态获取器
+     * @param $value
+     * @param $data
+     * @return string
+     * @author ljj
+     * @date 2021/7/31 3:26 下午
+     */
+    public function getStatusDescAttr($value, $data)
+    {
+        return YesNoEnum::getStatusDesc($data['status']);
+    }
+
+    /**
+     * @notes 类型获取器
+     * @param $value
+     * @param $data
+     * @return string
+     * @author ljj
+     * @date 2021/7/31 3:26 下午
+     */
+    public function getTypeDescAttr($value, $data)
+    {
+        $datas = [
+            1 => '自然风光',
+            2 => '酒店',
+            3 => '餐饮',
+        ];
+
+        return $datas[$data['type']];
+    }
+}