Jelajahi Sumber

地址管理

moonsflyer 8 bulan lalu
induk
melakukan
96449d6012

+ 111 - 0
app/adminapi/controller/asset/AssetAreaController.php

@@ -0,0 +1,111 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\controller\asset;
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\asset\AssetLists;
+use app\adminapi\lists\asset\AssetAreaLists;
+use app\adminapi\logic\article\ArticleLogic;
+use app\adminapi\logic\notice\NoticeLogic;
+use app\adminapi\validate\article\ArticleValidate;
+use app\adminapi\validate\asset\AssetValidate;
+use app\adminapi\validate\asset\AssetAreaValidate;
+use app\adminapi\validate\notice\NoticeValidate;
+
+/**
+ * 资产地址控制器
+ * Class NoticeController
+ * @package app\adminapi\controller\notice
+ */
+class AssetAreaController extends BaseAdminController
+{
+//    public array $notNeedLogin = ['getAssetData'];
+    /**
+     * @notes 查看资产列表
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2021/12/29 9:55
+     */
+    public function lists()
+    {
+        return $this->dataLists(new AssetAreaLists());
+    }
+
+    /**
+     * @notes  添加资产
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/22 9:57
+     */
+    public function add()
+    {
+        $params = (new AssetAreaValidate())->post()->goCheck('add');
+        AssetAreaLists::add($params);
+        return $this->success('添加成功', [], 1, 1);
+    }
+    /**
+     * @notes  编辑资产
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/22 10:12
+     */
+    public function edit()
+    {
+        $params = (new AssetAreaValidate())->post()->goCheck('edit');
+        $result = AssetAreaLists::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(AssetAreaLists::getError());
+    }
+
+    /**
+     * @notes  删除资讯
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/22 10:17
+     */
+    public function delete()
+    {
+        $params = (new AssetAreaValidate())->post()->goCheck('delete');
+        AssetAreaLists::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+    /**
+     * @notes  资产详情
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/22 10:15
+     */
+    public function detail()
+    {
+        $params = (new AssetAreaValidate())->goCheck('detail');
+        $result = AssetAreaLists::detail($params);
+        return $this->data($result);
+    }
+
+    /**
+     * @notes 获取资产数据
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2022/3/29 11:18
+     */
+    public function getAssetAreaData()
+    {
+        $result = AssetAreaLists::getAssetData();
+        return $this->success('查询成功', $result, 1, 1);
+    }
+}

+ 169 - 0
app/adminapi/lists/asset/AssetAreaLists.php

@@ -0,0 +1,169 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\asset;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\enum\asset\AssetEnum;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\article\Article;
+use app\common\model\notice\NoticeSetting;
+use app\common\model\asset\AssetInfo;
+use app\common\model\asset\AssetArea;
+use app\common\service\FileService;
+
+/**
+ * 资产地址管理
+ * Class AssetLists
+ * @package app\adminapi\lists\asset
+ */
+class AssetAreaLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+    /**
+     * @notes 搜索条件
+     * @return \string[][]
+     * @author
+     * @date 2025/04/12 2:21 下午
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => [ 'lease_status'],
+            '%like%'=>['name'],
+        ];
+    }
+
+    /**
+     * @notes 资产信息列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/2/16 3:18 下午
+     */
+    public function lists(): array
+    {
+
+        $lists = (new AssetArea())->field('id,title,create_time')
+            ->where($this->searchWhere)
+            ->limit($this->limitOffset, $this->limitLength)
+            ->Order('id desc')
+            ->select()
+            ->toArray();
+
+        return $lists;
+    }
+
+    /**
+     * @notes 资产信息数量
+     * @return int
+     * @author ljj
+     * @date 2022/2/16 3:18 下午
+     */
+    public function count(): int
+    {
+        return (new AssetArea())->where($this->searchWhere)->count();
+    }
+
+    /**
+     * @notes  添加资产
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/22 9:57
+     */
+    public static function add(array $params)
+    {
+        AssetArea::create([
+            'title' => $params['title']
+        ]);
+    }
+
+    /**
+     * @notes  编辑资产
+     * @param array $params
+     * @return bool
+     * @author heshihu
+     * @date 2022/2/22 10:12
+     */
+    public static function edit(array $params) : bool
+    {
+        try {
+            AssetArea::update([
+                'id' => $params['id'],
+                'title' => $params['title'],
+            ]);
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * @notes  删除资产
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/22 10:17
+     */
+    public static function delete(array $params)
+    {
+        AssetArea::destroy($params['id']);
+    }
+
+    /**
+     * @notes  查看资产详情
+     * @param $params
+     * @return array
+     * @author heshihu
+     * @date 2022/2/22 10:15
+     */
+    public static function detail($params) : array
+    {
+        return AssetArea::findOrEmpty($params['id'])->toArray();
+    }
+    public static function getAssetData():array
+    {
+        $where = [] ;
+
+        $where[]=['status','=',1];
+        $assetList = AssetInfo::where($where)->field('lease_status,count(id) total_number')->append(['lease_status_desc'])->group('lease_status')->select()->toArray();
+        $all_lease_status = AssetEnum::LEASE_STATTUS_SCENE;
+        $lease_satus = array_column($assetList,'lease_status');
+        $diff_lease_satus = array_diff($all_lease_status, $lease_satus);
+        if(!empty($diff_lease_satus)){
+            foreach($diff_lease_satus as $dv){
+                $pushData['lease_status_desc'] = AssetEnum::getLeaseStatusDesc($dv);
+                $pushData['lease_status'] = $dv;
+                $pushData['total_number'] = 0;
+
+                $assetList[]=$pushData;
+            }
+        }
+        $totalNumber = sumValues($assetList,'total_number');
+        $leave_unused = 0;
+        foreach($assetList as $av){
+            if($av['lease_status'] == 1){
+                $leave_unused = $av['total_number'];
+            }
+        }
+
+        $unused_rate = $totalNumber?round(($leave_unused/$totalNumber*100),2):100;
+        $return_data['leave_unused_num'] = $leave_unused;
+        $return_data['unused_rate'] = $unused_rate;
+        $return_data['asset_list'] = $assetList;
+
+        return $return_data;
+    }
+}

+ 91 - 0
app/adminapi/validate/asset/AssetAreaValidate.php

@@ -0,0 +1,91 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\asset;
+
+use app\common\validate\BaseValidate;
+use app\common\model\asset\AssetArea;
+/**
+ * 资产地址管理验证
+ * Class ArticleValidate
+ * @package app\adminapi\validate\article
+ */
+class AssetAreaValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require|checkAssetInfo',
+        'title' => 'require|length:1,50',
+    ];
+
+    protected $message = [
+        'id.require' => '资产地址id必传',
+        'title.require' => '地址名称不能为空',
+        'title.length' => '地址名称长度须在1-55位字符',
+    ];
+
+    /**
+     * @notes  添加场景
+     * @return ArticleValidate
+     * @author heshihu
+     * @date 2022/2/22 9:57
+     */
+    public function sceneAdd()
+    {
+        return $this->remove(['id'])
+            ->remove('id','require|checkAssetInfo');
+    }
+
+    /**
+     * @notes  详情场景
+     * @return ArticleValidate
+     * @author heshihu
+     * @date 2022/2/22 10:15
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+    public function sceneEdit()
+    {
+    }
+
+    /**
+     * @notes  删除场景
+     * @return ArticleValidate
+     * @author heshihu
+     * @date 2022/2/22 10:17
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * @notes  检查指定地址是否存在
+     * @param $value
+     * @return bool|string
+     * @author heshihu
+     * @date 2022/2/22 10:11
+     */
+    public function checkAssetInfo($value)
+    {
+        $article = AssetArea::findOrEmpty($value);
+        if ($article->isEmpty()) {
+            return '地址不存在';
+        }
+        return true;
+    }
+
+}

+ 28 - 0
app/common/model/asset/AssetArea.php

@@ -0,0 +1,28 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\asset;
+
+
+use app\common\enum\DefaultEnum;
+use app\common\model\BaseModel;
+use think\model\concern\SoftDelete;
+
+class AssetArea extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+}