moonsflyer 3 ماه پیش
والد
کامیت
702b3eaf3f

+ 106 - 0
app/adminapi/controller/AreaController.php

@@ -0,0 +1,106 @@
+<?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;
+
+use app\adminapi\validate\ArticleValidate;
+use app\adminapi\logic\ArticleLogic;
+use app\adminapi\validate\AreaValidate;
+use app\adminapi\logic\AreaLogic;
+class AreaController extends BaseAdminController
+{
+    /**
+     * @notes 地区列表
+     * @return \think\response\Json
+     * @author Tab
+     * @date 2021/7/14 9:33
+     */
+    public function lists()
+    {
+        return $this->dataLists();
+    }
+
+    /**
+     * @notes 添加地区信息
+     * @return \think\response\Json
+     * @author Tab
+     * @date 2021/7/13 15:49
+     */
+    public function add()
+    {
+        $params = (new AreaValidate())->post()->goCheck('add');
+        AreaLogic::add($params);
+        return $this->success('添加成功',[],1,1);
+    }
+
+    /**
+     * @notes 查看地区信息
+     * @return \think\response\Json
+     * @author Tab
+     * @date 2021/7/13 16:53
+     */
+    public function detail()
+    {
+        $params = (new AreaValidate())->goCheck('detail');
+        $result = AreaLogic::detail($params);
+        return $this->data($result);
+    }
+
+    /** 编辑地区
+     * @notes
+     * @return \think\response\Json
+     * @author Tab
+     * @date 2021/7/14 9:20
+     */
+    public function edit()
+    {
+        $params = (new AreaValidate())->post()->goCheck('edit');
+        AreaLogic::edit($params);
+        return $this->success('编辑成功',[],1,1);
+    }
+
+    /**
+     * @notes 删除地区信息
+     * @return \think\response\Json
+     * @author Tab
+     * @date 2021/7/14 9:24
+     */
+    public function delete()
+    {
+        $params = (new AreaValidate())->post()->goCheck('delete');
+        AreaLogic::delete($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 Tab
+     * @date 2021/7/14 11:36
+     */
+    public function isShow()
+    {
+        $params = (new AreaValidate())->post()->goCheck('show');
+        AreaLogic::isShow($params);
+        return $this->success('修改成功',[],1,1);
+    }
+}

+ 103 - 0
app/adminapi/lists/AreaLists.php

@@ -0,0 +1,103 @@
+<?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\lists;
+
+use app\common\lists\ListsExcelInterface;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\Article;
+use app\common\model\ArticleCategory;
+use app\common\model\SpecialArea;
+
+class AreaLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
+{
+    /**
+     * @notes 设置导出字段
+     * @return string[]
+     * @author Tab
+     * @date 2021/7/30 15:37
+     */
+    public function setExcelFields(): array
+    {
+        return [
+            'title' => '标题',
+            'cid_desc' => '分类',
+            'is_show_desc' => '文章状态',
+            'visit' => '浏览量',
+            'sort' => '排序',
+            'create_time' => '创建时间',
+        ];
+    }
+
+    /**
+     * @notes 设置默认表名
+     * @return string
+     * @author Tab
+     * @date 2021/7/30 15:37
+     */
+    public function setFileName(): string
+    {
+        return '地址列表';
+    }
+
+    /**
+     * @notes 设置搜索
+     * @return \string[][]
+     * @author Tab
+     * @date 2021/7/14 9:48
+     */
+    public function setSearch(): array
+    {
+        return [
+            '%like%' => ['name']
+        ];
+    }
+
+    /**
+     * @notes  地区列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author Tab
+     * @date 2021/7/14 9:48
+     */
+    public function lists(): array
+    {
+
+        $lists = SpecialArea::field('id,name,free_shipping_money,shipping_fee,is_show,is_show as is_show_desc,sort,create_time')
+            ->where($this->searchWhere)
+            ->order('sort desc,id desc')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes 地区总记录数
+     * @return int
+     * @author Tab
+     * @date 2021/7/14 9:48
+     */
+    public function count(): int
+    {
+        return SpecialArea::where($this->searchWhere)->count();
+    }
+}

+ 112 - 0
app/adminapi/logic/AreaLogic.php

@@ -0,0 +1,112 @@
+<?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;
+
+use app\common\enum\ArticleEnum;
+use app\common\enum\DefaultEnum;
+use app\common\enum\YesNoEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\Article;
+use app\common\model\SpecialArea;
+use app\common\service\FileService;
+
+class AreaLogic extends BaseLogic
+{
+    /**
+     * @notes 添加地区
+     * @param $params
+     * @author Tab
+     * @date 2021/7/13 15:59
+     */
+    public static function add($params)
+    {
+
+        $data = [
+            'name' => $params['name'],
+            'free_shipping_money' => $params['free_shipping_money']??0,
+            'shipping_fee' => $params['shipping_fee'] ?? 0,
+            'sort' => $params['sort'] ?? 0,
+            'is_show' => $params['is_show'] ?? YesNoEnum::YES,
+            'create_time' => time(),
+        ];
+
+        SpecialArea::create($data);
+    }
+
+    /**
+     * @notes 查看文章/帮助详情
+     * @param $params
+     * @return array
+     * @author Tab
+     * @date 2021/7/13 16:53
+     */
+    public static function detail($params)
+    {
+        return SpecialArea::field('id,name,free_shipping_money,shipping_fee,sort,is_show,is_show as is_show_desc')->findOrEmpty($params['id'])->toArray();
+    }
+
+    /**
+     * @notes 编辑地区信息
+     * @param $params
+     * @author Tab
+     * @date 2021/7/14 9:21
+     */
+    public static function edit($params)
+    {
+
+        $data = [
+            'id' => $params['id'],
+            'name' => $params['name'],
+            'free_shipping_money' => $params['free_shipping_money']??0,
+            'shipping_fee' => $params['shipping_fee'] ?? 0,
+            'sort' => $params['sort'] ?? 0,
+            'is_show' => $params['is_show'] ?? YesNoEnum::YES,
+        ];
+
+        SpecialArea::update($data);
+    }
+
+    /**
+     * @notes 删除地区信息
+     * @param $params
+     * @author Tab
+     * @date 2021/7/14 9:23
+     */
+    public static function delete($params)
+    {
+        SpecialArea::destroy($params['id']);
+    }
+
+    /**
+     * @notes 修改是否显示状态
+     * @param $params
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author Tab
+     * @date 2021/7/14 11:36
+     */
+    public static function isShow($params)
+    {
+        $area = SpecialArea::find($params['id']);
+        $area->is_show = $area->getData('is_show') ? 0: 1;
+        $area->save();
+    }
+}

+ 102 - 0
app/adminapi/validate/AreaValidate.php

@@ -0,0 +1,102 @@
+<?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;
+
+use app\common\model\SpecialArea;
+use app\common\validate\BaseValidate;
+
+class AreaValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'name' => 'require|checkName',
+        'is_show' => 'in:0,1',
+    ];
+
+    protected $message = [
+        'name.require' => '地区名称不能为空',
+        'is_show.in' => '是否显示类型错误',
+    ];
+
+    /**
+     * @notes 添加地区
+     * @return AreaValidate
+     * @author Tab
+     * @date 2021/7/22 17:06
+     */
+    public function sceneAdd()
+    {
+        return $this->remove('id', 'require');
+    }
+
+    /**
+     * @notes 获取地区场景
+     * @return AreaValidate
+     * @author Tab
+     * @date 2021/7/22 17:06
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * @notes 删除地区
+     * @return AreaValidate
+     * @author Tab
+     * @date 2021/7/22 17:06
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * @notes 显示或隐藏场景
+     * @return AreaValidate
+     * @author Tab
+     * @date 2021/7/22 17:07
+     */
+    public function sceneShow()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * @notes 校验地区名称
+     * @param $value
+     * @return bool|string
+     * @author Tab
+     * @date 2021/7/22 17:08
+     */
+    public function checkName($value,$rule,$data)
+    {
+
+        $where[]=['name','=',$value];
+        if(isset($data['id'])){
+            $where[]=['id','<>',$data['id']];
+        }
+        $area = SpecialArea::where($where)->findOrEmpty();
+        if(!$area->isEmpty()) {
+            return '地区名称已存在';
+        }
+        return true;
+    }
+}

+ 41 - 0
app/common/model/SpecialArea.php

@@ -0,0 +1,41 @@
+<?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 think\model\concern\SoftDelete;
+
+class SpecialArea extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+    /**
+     * @notes 显示状态获取器
+     * @param $value
+     * @return string
+     * @author Tab
+     * @date 2021/7/30 15:34
+     */
+    public function getIsShowDescAttr($value)
+    {
+        return $value ? '显示' : '隐藏';
+    }
+}