AssetLists.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. $parms = $this->request->get();
  54. $where=[];
  55. if (!empty($parms['create_time_start']) && !empty($parms['create_time_end'])) {
  56. $where[] = ['create_time', 'between', [strtotime($parms['create_time_start']), strtotime($parms['create_time_end'] . ' 23:59:59')]];
  57. }
  58. $lists = (new AssetInfo())->field('id,name,address,images,contacts,mobile,area,content,status,lease_status,lease_expiration_time,create_time,sort')
  59. ->append(['status_desc','lease_status_desc'])
  60. ->where($this->searchWhere)
  61. ->where($where)
  62. ->limit($this->limitOffset, $this->limitLength)
  63. ->Order('sort desc')
  64. ->select()
  65. ->toArray();
  66. return $lists;
  67. }
  68. /**
  69. * @notes 资产信息数量
  70. * @return int
  71. * @author ljj
  72. * @date 2022/2/16 3:18 下午
  73. */
  74. public function count(): int
  75. {
  76. return (new AssetInfo())->where($this->searchWhere)->count();
  77. }
  78. /**
  79. * @notes 添加资产
  80. * @param array $params
  81. * @author heshihu
  82. * @date 2022/2/22 9:57
  83. */
  84. public static function add(array $params)
  85. {
  86. AssetInfo::create([
  87. 'name' => $params['name'],
  88. 'images' => $params['images'] ?? '',
  89. 'address' => $params['address'] ?? '',
  90. 'contacts' => $params['contacts']?? '', // 联系人
  91. 'mobile' => $params['mobile'] ?? '',
  92. 'area' => $params['area'] ?? '',
  93. 'content' => $params['content'] ?? '',
  94. // 'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
  95. 'lease_expiration_time'=>$params['lease_expiration_time'] ?? '',
  96. 'status' => $params['status'] ?? 1,
  97. 'sort' => $params['sort'] ?? 0, // 排序
  98. ]);
  99. }
  100. /**
  101. * @notes 编辑资产
  102. * @param array $params
  103. * @return bool
  104. * @author heshihu
  105. * @date 2022/2/22 10:12
  106. */
  107. public static function edit(array $params) : bool
  108. {
  109. try {
  110. AssetInfo::update([
  111. 'id' => $params['id'],
  112. 'name' => $params['name'],
  113. 'images' => $params['images'],
  114. 'address' => $params['address'],
  115. 'contacts' => $params['contacts'],
  116. 'mobile' => $params['mobile'],
  117. 'area' => $params['area'] ?? '',
  118. 'content' => $params['content'] ?? '',
  119. 'status' => $params['status'] ?? 1,
  120. 'sort' => $params['sort'] ?? 0,
  121. 'content' => $params['content'] ?? '',
  122. ]);
  123. return true;
  124. } catch (\Exception $e) {
  125. self::setError($e->getMessage());
  126. return false;
  127. }
  128. }
  129. /**
  130. * @notes 删除资产
  131. * @param array $params
  132. * @author heshihu
  133. * @date 2022/2/22 10:17
  134. */
  135. public static function delete(array $params)
  136. {
  137. AssetInfo::destroy($params['id']);
  138. }
  139. /**
  140. * @notes 查看资产详情
  141. * @param $params
  142. * @return array
  143. * @author heshihu
  144. * @date 2022/2/22 10:15
  145. */
  146. public static function detail($params) : array
  147. {
  148. return AssetInfo::findOrEmpty($params['id'])->append(['status_desc','lease_status_desc'])->toArray();
  149. }
  150. public static function getRentAssetList($params) : array
  151. {
  152. $where = [] ;
  153. if(!empty($params)){
  154. $where[]=['name','like','%'.$params['name'].'%'];
  155. }
  156. $where[]=['status','=',1];
  157. $where[]=['lease_status','in',[1,3]];
  158. $assetList = AssetInfo::where($where)->field('id,name,area')->select()->toArray();
  159. return $assetList;
  160. }
  161. public static function getAssetData():array
  162. {
  163. $where = [] ;
  164. $where[]=['status','=',1];
  165. $assetList = AssetInfo::where($where)->field('lease_status,count(id) total_number')->append(['lease_status_desc'])->group('lease_status')->select()->toArray();
  166. $all_lease_status = AssetEnum::LEASE_STATTUS_SCENE;
  167. $lease_satus = array_column($assetList,'lease_status');
  168. $diff_lease_satus = array_diff($all_lease_status, $lease_satus);
  169. if(!empty($diff_lease_satus)){
  170. foreach($diff_lease_satus as $dv){
  171. $pushData['lease_status_desc'] = AssetEnum::getLeaseStatusDesc($dv);
  172. $pushData['lease_status'] = $dv;
  173. $pushData['total_number'] = 0;
  174. $assetList[]=$pushData;
  175. }
  176. }
  177. $totalNumber = sumValues($assetList,'total_number');
  178. $leave_unused = 0;
  179. foreach($assetList as $av){
  180. if($av['lease_status'] == 1){
  181. $leave_unused = $av['total_number'];
  182. }
  183. }
  184. $unused_rate = $totalNumber?round(($leave_unused/$totalNumber*100),2):100;
  185. $return_data['leave_unused_num'] = $leave_unused;
  186. $return_data['unused_rate'] = $unused_rate;
  187. $return_data['asset_list'] = $assetList;
  188. return $return_data;
  189. }
  190. }