Kaynağa Gözat

信息发布

moonsflyer 5 ay önce
ebeveyn
işleme
49c1f2ee6d

+ 114 - 0
app/adminapi/controller/info/InfoController.php

@@ -0,0 +1,114 @@
+<?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\info;
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\banner\BannerLists;
+use app\adminapi\lists\info\InfoLists;
+use app\adminapi\validate\info\InfoValidate;
+use app\adminapi\logic\info\InfoLogic;
+
+use app\adminapi\logic\banner\BannerLogic;
+use app\adminapi\validate\banner\BannerValidate;
+
+class InfoController extends BaseAdminController
+{
+    /**
+     * @notes 添加宣传信息
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/14 3:04
+     */
+    public function add()
+    {
+        $params = (new InfoValidate())->post()->goCheck('add');
+        (new InfoLogic())->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 InfoLists());
+    }
+
+    /**
+     * @notes 删除宣传信息
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2021/7/14 7:07
+     */
+    public function del()
+    {
+        $params = (new InfoValidate())->post()->goCheck('del');
+        (new InfoLogic())->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 InfoValidate())->post()->goCheck('edit');
+        (new InfoLogic())->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 InfoValidate())->post()->goCheck('status');
+        (new InfoLogic())->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 InfoValidate())->goCheck('detail');
+        $result = (new InfoLogic())->detail($params);
+        return $this->success('信息详情获取成功',$result,1,0);
+    }
+}

+ 82 - 0
app/adminapi/lists/info/InfoLists.php

@@ -0,0 +1,82 @@
+<?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\info;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\Banner;
+use app\common\model\Info;
+use app\common\model\InfoCategory;
+
+
+class InfoLists 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']];
+        }
+        if (isset($params['name']) && $params['name'] != '') {
+            $where[] = ['neme', '%like%', $params['name']];
+        }
+        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 = Info::where($this->setSearch())
+            ->field('id,type,cid,title,synopsis,image,address,phone,latitude,longitude,sort,is_show,create_time,update_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 Info::where($this->setSearch())->count();
+    }
+}

+ 126 - 0
app/adminapi/logic/info/InfoLogic.php

@@ -0,0 +1,126 @@
+<?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\info;
+
+
+use app\common\enum\DefaultEnum;
+use app\common\enum\YesNoEnum;
+use app\common\model\GoodsBrand;
+use app\common\model\Banner;
+use app\common\model\Info;
+class InfoLogic
+{
+    /**
+     * @notes 添加信息
+     * @param $params
+     * @return bool
+     * @author ljj
+     * @date 2021/7/14 5:00
+     */
+    public function add($params)
+    {
+        $Info= new Info;
+        $Info->type = $params['type'];
+        $Info->cid = $params['cid'] ?? '';
+        $Info->title = $params['title'] ?? '';
+        $Info->synopsis = $params['synopsis'] ?? '';
+        $Info->image = $params['image'] ?? '';
+        $Info->address = $params['address'] ?? '';
+        $Info->phone = $params['phone'] ?? '';
+        $Info->latitude = $params['latitude'] ?? '';
+        $Info->longitude = $params['longitude'] ?? '';
+        $Info->content = $params['content'] ?? '';
+        $Info->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 1;
+        $Info->is_show = $params['is_show'] ?? YesNoEnum::YES;
+        return $Info->save();
+    }
+
+    /**
+     * @notes 删除信息
+     * @param $params
+     * @return bool
+     * @author ljj
+     * @date 2021/7/15 10:37
+     */
+    public function del($params)
+    {
+        return Info::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)
+    {
+        $Info = Info::find($params['id']);
+        $Info->type = $params['type'];
+        $Info->cid = $params['cid'] ?? '';
+        $Info->title = $params['title'] ?? '';
+        $Info->synopsis = $params['synopsis'] ?? '';
+        $Info->image = $params['image'] ?? '';
+        $Info->address = $params['address'] ?? '';
+        $Info->phone = $params['phone'] ?? '';
+        $Info->latitude = $params['latitude'] ?? '';
+        $Info->longitude = $params['longitude'] ?? '';
+        $Info->content = $params['content'] ?? '';
+        $Info->sort = (isset($params['sort']) && !empty($params['sort'])) ? $params['sort'] : 1;
+        $Info->is_show = $params['is_show'] ?? YesNoEnum::YES;
+        return $Info->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)
+    {
+        $Info = Info::find($params['id']);
+        $Info->is_show = $params['status'];
+        return $Info->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 Info::find($params['id'])->toArray();
+    }
+}

+ 68 - 0
app/adminapi/validate/info/InfoValidate.php

@@ -0,0 +1,68 @@
+<?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\info;
+
+
+use app\common\model\GoodsBrand;
+use app\common\validate\BaseValidate;
+
+class InfoValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'type' => 'require|in:1,2,3,4,5,6,7,8',
+        'title' => 'require',
+        'image'=> 'require',
+        'is_show' => 'in:0,1',
+        'sort' => 'number',
+    ];
+
+    protected $message = [
+        'id.require' => '信息id不能为空',
+        'title.require' => '标题不能为空',
+        'image.require' => '封面图不能为空',
+    ];
+
+    public function sceneAdd()
+    {
+        return $this->only(['type','title','image','sort']);
+    }
+
+    public function sceneDel()
+    {
+        return $this->only(['id']);
+    }
+
+    public function sceneEdit()
+    {
+        return $this->only(['id','type','title','image']);
+    }
+
+    public function sceneStatus()
+    {
+        return $this->only(['id','is_show']);
+    }
+
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}