AssetLists.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. 'status' => $params['status'] ?? 1,
  89. 'sort' => $params['sort'] ?? 0, // 排序
  90. ]);
  91. }
  92. /**
  93. * @notes 编辑资产
  94. * @param array $params
  95. * @return bool
  96. * @author heshihu
  97. * @date 2022/2/22 10:12
  98. */
  99. public static function edit(array $params) : bool
  100. {
  101. try {
  102. AssetInfo::update([
  103. 'id' => $params['id'],
  104. 'name' => $params['name'],
  105. 'images' => $params['images'],
  106. 'address' => $params['address'],
  107. 'contacts' => $params['contacts'],
  108. 'mobile' => $params['mobile'],
  109. 'area' => $params['area'] ?? '',
  110. 'content' => $params['content'] ?? '',
  111. 'status' => $params['status'] ?? 1,
  112. 'sort' => $params['sort'] ?? 0,
  113. 'content' => $params['content'] ?? '',
  114. ]);
  115. return true;
  116. } catch (\Exception $e) {
  117. self::setError($e->getMessage());
  118. return false;
  119. }
  120. }
  121. /**
  122. * @notes 删除资产
  123. * @param array $params
  124. * @author heshihu
  125. * @date 2022/2/22 10:17
  126. */
  127. public static function delete(array $params)
  128. {
  129. AssetInfo::destroy($params['id']);
  130. }
  131. /**
  132. * @notes 查看资产详情
  133. * @param $params
  134. * @return array
  135. * @author heshihu
  136. * @date 2022/2/22 10:15
  137. */
  138. public static function detail($params) : array
  139. {
  140. return AssetInfo::findOrEmpty($params['id'])->append(['status_desc','lease_status_desc'])->toArray();
  141. }
  142. public static function getRentAssetList($params) : array
  143. {
  144. $where = [] ;
  145. if(!empty($params)){
  146. $where[]=['name','like','%'.$params['name'].'%'];
  147. }
  148. $where[]=['status','=',1];
  149. $where[]=['lease_status','in',[1,3]];
  150. $assetList = AssetInfo::where($where)->field('id,name,area')->select()->toArray();
  151. return $assetList;
  152. }
  153. public static function getAssetData():array
  154. {
  155. $where = [] ;
  156. $where[]=['status','=',1];
  157. $assetList = AssetInfo::where($where)->field('lease_status,count(id) total_number')->append(['lease_status_desc'])->group('lease_status')->select()->toArray();
  158. $all_lease_status = AssetEnum::LEASE_STATTUS_SCENE;
  159. $lease_satus = array_column($assetList,'lease_status');
  160. $diff_lease_satus = array_diff($all_lease_status, $lease_satus);
  161. if(!empty($diff_lease_satus)){
  162. foreach($diff_lease_satus as $dv){
  163. $pushData['lease_status_desc'] = AssetEnum::getLeaseStatusDesc($dv);
  164. $pushData['lease_status'] = $dv;
  165. $pushData['total_number'] = 0;
  166. $assetList[]=$pushData;
  167. }
  168. }
  169. $totalNumber = sumValues($assetList,'total_number');
  170. $leave_unused = 0;
  171. foreach($assetList as $av){
  172. if($av['lease_status'] == 1){
  173. $leave_unused = $av['total_number'];
  174. }
  175. }
  176. $unused_rate = $totalNumber?round(($leave_unused/$totalNumber*100),2):100;
  177. $return_data['leave_unused_num'] = $leave_unused;
  178. $return_data['unused_rate'] = $unused_rate;
  179. $return_data['asset_list'] = $assetList;
  180. return $return_data;
  181. }
  182. }