AssetLists.php 6.4 KB

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