AssetLeaseLists.php 5.5 KB

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