AssetLists.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. '=' => [ 'lease_status'],
  39. '%like%'=>['name'],
  40. ];
  41. }
  42. /**
  43. * @notes 资产信息列表
  44. * @return array
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. * @author ljj
  49. * @date 2022/2/16 3:18 下午
  50. */
  51. public function lists(): array
  52. {
  53. $lists = (new AssetInfo())->field('id,name,address,images,contacts,mobile,area,content,status,lease_status,lease_expiration_time,create_time,sort')
  54. ->append(['status_desc','lease_status_desc'])
  55. ->where($this->searchWhere)
  56. ->limit($this->limitOffset, $this->limitLength)
  57. ->Order('sort 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 AssetInfo())->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. AssetInfo::create([
  81. 'name' => $params['name'],
  82. 'images' => $params['images'] ?? '',
  83. 'address' => $params['address'] ?? '',
  84. 'contacts' => $params['contacts']?? '', // 联系人
  85. 'mobile' => $params['mobile'] ?? '',
  86. 'area' => $params['area'] ?? '',
  87. 'content' => $params['content'] ?? '',
  88. // 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
  89. 'lease_expiration_time'=>$params['lease_expiration_time'] ?? '',
  90. 'status' => $params['status'] ?? 1,
  91. 'sort' => $params['sort'] ?? 0, // 排序
  92. ]);
  93. }
  94. /**
  95. * @notes 编辑资产
  96. * @param array $params
  97. * @return bool
  98. * @author heshihu
  99. * @date 2022/2/22 10:12
  100. */
  101. public static function edit(array $params) : bool
  102. {
  103. try {
  104. AssetInfo::update([
  105. 'id' => $params['id'],
  106. 'name' => $params['name'],
  107. 'images' => $params['images'],
  108. 'address' => $params['address'],
  109. 'contacts' => $params['contacts'],
  110. 'mobile' => $params['mobile'],
  111. 'area' => $params['area'] ?? '',
  112. 'content' => $params['content'] ?? '',
  113. 'status' => $params['status'] ?? 1,
  114. 'sort' => $params['sort'] ?? 0,
  115. 'content' => $params['content'] ?? '',
  116. ]);
  117. return true;
  118. } catch (\Exception $e) {
  119. self::setError($e->getMessage());
  120. return false;
  121. }
  122. }
  123. /**
  124. * @notes 删除资产
  125. * @param array $params
  126. * @author heshihu
  127. * @date 2022/2/22 10:17
  128. */
  129. public static function delete(array $params)
  130. {
  131. AssetInfo::destroy($params['id']);
  132. }
  133. /**
  134. * @notes 查看资产详情
  135. * @param $params
  136. * @return array
  137. * @author heshihu
  138. * @date 2022/2/22 10:15
  139. */
  140. public static function detail($params) : array
  141. {
  142. return AssetInfo::findOrEmpty($params['id'])->append(['status_desc','lease_status_desc'])->toArray();
  143. }
  144. public static function getRentAssetList($params) : array
  145. {
  146. $where = [] ;
  147. if(!empty($params)){
  148. $where[]=['name','like','%'.$params['name'].'%'];
  149. }
  150. $where[]=['status','=',1];
  151. $where[]=['lease_status','in',[1,3]];
  152. $assetList = AssetInfo::where($where)->field('id,name,area')->select()->toArray();
  153. return $assetList;
  154. }
  155. public static function getAssetData():array
  156. {
  157. $where = [] ;
  158. $where[]=['status','=',1];
  159. $assetList = AssetInfo::where($where)->field('lease_status,count(id) total_number')->append(['lease_status_desc'])->group('lease_status')->select()->toArray();
  160. $all_lease_status = AssetEnum::LEASE_STATTUS_SCENE;
  161. $lease_satus = array_column($assetList,'lease_status');
  162. $diff_lease_satus = array_diff($all_lease_status, $lease_satus);
  163. if(!empty($diff_lease_satus)){
  164. foreach($diff_lease_satus as $dv){
  165. $pushData['lease_status_desc'] = AssetEnum::getLeaseStatusDesc($dv);
  166. $pushData['lease_status'] = $dv;
  167. $pushData['total_number'] = 0;
  168. $assetList[]=$pushData;
  169. }
  170. }
  171. $totalNumber = sumValues($assetList,'total_number');
  172. $leave_unused = 0;
  173. foreach($assetList as $av){
  174. if($av['lease_status'] == 1){
  175. $leave_unused = $av['total_number'];
  176. }
  177. }
  178. $unused_rate = $totalNumber?round(($leave_unused/$totalNumber*100),2):100;
  179. $return_data['leave_unused_num'] = $leave_unused;
  180. $return_data['unused_rate'] = $unused_rate;
  181. $return_data['asset_list'] = $assetList;
  182. return $return_data;
  183. }
  184. }