AssetLists.php 6.9 KB

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