AssetAreaLists.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\enum\asset\AssetEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\article\Article;
  19. use app\common\model\notice\NoticeSetting;
  20. use app\common\model\asset\AssetInfo;
  21. use app\common\model\asset\AssetArea;
  22. use app\common\service\FileService;
  23. /**
  24. * 资产地址管理
  25. * Class AssetLists
  26. * @package app\adminapi\lists\asset
  27. */
  28. class AssetAreaLists extends BaseAdminDataLists implements ListsSearchInterface
  29. {
  30. /**
  31. * @notes 搜索条件
  32. * @return \string[][]
  33. * @author
  34. * @date 2025/04/12 2:21 下午
  35. */
  36. public function setSearch(): array
  37. {
  38. return [
  39. '=' => [ 'lease_status'],
  40. '%like%'=>['name'],
  41. ];
  42. }
  43. /**
  44. * @notes 资产信息列表
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @author ljj
  50. * @date 2022/2/16 3:18 下午
  51. */
  52. public function lists(): array
  53. {
  54. $lists = (new AssetArea())->field('id,title,create_time')
  55. ->where($this->searchWhere)
  56. ->limit($this->limitOffset, $this->limitLength)
  57. ->Order('id desc')
  58. ->select()
  59. ->toArray();
  60. return $lists;
  61. }
  62. /**
  63. * @notes 资产信息数量
  64. * @return int
  65. * @author ljj
  66. * @date 2022/2/16 3:18 下午
  67. */
  68. public function count(): int
  69. {
  70. return (new AssetArea())->where($this->searchWhere)->count();
  71. }
  72. /**
  73. * @notes 添加资产
  74. * @param array $params
  75. * @author heshihu
  76. * @date 2022/2/22 9:57
  77. */
  78. public static function add(array $params)
  79. {
  80. AssetArea::create([
  81. 'title' => $params['title']
  82. ]);
  83. }
  84. /**
  85. * @notes 编辑资产
  86. * @param array $params
  87. * @return bool
  88. * @author heshihu
  89. * @date 2022/2/22 10:12
  90. */
  91. public static function edit(array $params) : bool
  92. {
  93. try {
  94. AssetArea::update([
  95. 'id' => $params['id'],
  96. 'title' => $params['title'],
  97. ]);
  98. return true;
  99. } catch (\Exception $e) {
  100. self::setError($e->getMessage());
  101. return false;
  102. }
  103. }
  104. /**
  105. * @notes 删除资产
  106. * @param array $params
  107. * @author heshihu
  108. * @date 2022/2/22 10:17
  109. */
  110. public static function delete(array $params)
  111. {
  112. AssetArea::destroy($params['id']);
  113. }
  114. /**
  115. * @notes 查看资产详情
  116. * @param $params
  117. * @return array
  118. * @author heshihu
  119. * @date 2022/2/22 10:15
  120. */
  121. public static function detail($params) : array
  122. {
  123. return AssetArea::findOrEmpty($params['id'])->toArray();
  124. }
  125. public static function getAssetData():array
  126. {
  127. $where = [] ;
  128. $where[]=['status','=',1];
  129. $assetList = AssetInfo::where($where)->field('lease_status,count(id) total_number')->append(['lease_status_desc'])->group('lease_status')->select()->toArray();
  130. $all_lease_status = AssetEnum::LEASE_STATTUS_SCENE;
  131. $lease_satus = array_column($assetList,'lease_status');
  132. $diff_lease_satus = array_diff($all_lease_status, $lease_satus);
  133. if(!empty($diff_lease_satus)){
  134. foreach($diff_lease_satus as $dv){
  135. $pushData['lease_status_desc'] = AssetEnum::getLeaseStatusDesc($dv);
  136. $pushData['lease_status'] = $dv;
  137. $pushData['total_number'] = 0;
  138. $assetList[]=$pushData;
  139. }
  140. }
  141. $totalNumber = sumValues($assetList,'total_number');
  142. $leave_unused = 0;
  143. foreach($assetList as $av){
  144. if($av['lease_status'] == 1){
  145. $leave_unused = $av['total_number'];
  146. }
  147. }
  148. $unused_rate = $totalNumber?round(($leave_unused/$totalNumber*100),2):100;
  149. $return_data['leave_unused_num'] = $leave_unused;
  150. $return_data['unused_rate'] = $unused_rate;
  151. $return_data['asset_list'] = $assetList;
  152. return $return_data;
  153. }
  154. }