AssetLists.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\asset;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\lists\ListsSearchInterface;
  17. use app\common\model\article\Article;
  18. use app\common\model\notice\NoticeSetting;
  19. use app\common\model\asset\AssetInfo;
  20. use app\common\service\FileService;
  21. /**
  22. * 资产管理
  23. * Class AssetLists
  24. * @package app\adminapi\lists\asset
  25. */
  26. class AssetLists extends BaseAdminDataLists implements ListsSearchInterface
  27. {
  28. /**
  29. * @notes 搜索条件
  30. * @return \string[][]
  31. * @author
  32. * @date 2025/04/12 2:21 下午
  33. */
  34. public function setSearch(): array
  35. {
  36. return [
  37. '=' => ['name', 'status']
  38. ];
  39. }
  40. /**
  41. * @notes 资产信息列表
  42. * @return array
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @author ljj
  47. * @date 2022/2/16 3:18 下午
  48. */
  49. public function lists(): array
  50. {
  51. $lists = (new AssetInfo())->field('id,name,address,images,contacts,mobile,area,content,status,lease_status,create_time,sort')
  52. ->append(['status_desc','lease_status_desc'])
  53. ->where($this->searchWhere)
  54. ->limit($this->limitOffset, $this->limitLength)
  55. ->Order('sort desc')
  56. ->select()
  57. ->toArray();
  58. return $lists;
  59. }
  60. /**
  61. * @notes 资产信息数量
  62. * @return int
  63. * @author ljj
  64. * @date 2022/2/16 3:18 下午
  65. */
  66. public function count(): int
  67. {
  68. return (new AssetInfo())->where($this->searchWhere)->count();
  69. }
  70. /**
  71. * @notes 添加资产
  72. * @param array $params
  73. * @author heshihu
  74. * @date 2022/2/22 9:57
  75. */
  76. public static function add(array $params)
  77. {
  78. AssetInfo::create([
  79. 'name' => $params['name'],
  80. 'images' => $params['images'] ?? '',
  81. 'address' => $params['address'] ?? '',
  82. 'contacts' => $params['contacts']?? '', // 联系人
  83. 'mobile' => $params['mobile'] ?? '',
  84. 'area' => $params['area'] ?? '',
  85. 'content' => $params['content'] ?? '',
  86. // 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
  87. 'status' => $params['status'] ?? 1,
  88. 'sort' => $params['sort'] ?? 0, // 排序
  89. ]);
  90. }
  91. /**
  92. * @notes 编辑资产
  93. * @param array $params
  94. * @return bool
  95. * @author heshihu
  96. * @date 2022/2/22 10:12
  97. */
  98. public static function edit(array $params) : bool
  99. {
  100. try {
  101. AssetInfo::update([
  102. 'id' => $params['id'],
  103. 'name' => $params['name'],
  104. 'images' => $params['images'],
  105. 'address' => $params['address'],
  106. 'contacts' => $params['contacts'],
  107. 'mobile' => $params['mobile'],
  108. 'area' => $params['area'] ?? '',
  109. 'content' => $params['content'] ?? '',
  110. 'status' => $params['status'] ?? 1,
  111. 'sort' => $params['sort'] ?? 0,
  112. 'content' => $params['content'] ?? '',
  113. ]);
  114. return true;
  115. } catch (\Exception $e) {
  116. self::setError($e->getMessage());
  117. return false;
  118. }
  119. }
  120. /**
  121. * @notes 删除资产
  122. * @param array $params
  123. * @author heshihu
  124. * @date 2022/2/22 10:17
  125. */
  126. public static function delete(array $params)
  127. {
  128. AssetInfo::destroy($params['id']);
  129. }
  130. /**
  131. * @notes 查看资产详情
  132. * @param $params
  133. * @return array
  134. * @author heshihu
  135. * @date 2022/2/22 10:15
  136. */
  137. public static function detail($params) : array
  138. {
  139. return AssetInfo::findOrEmpty($params['id'])->append(['status_desc','lease_status_desc'])->toArray();
  140. }
  141. }