AssetLeaseLists.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. if(isset($parms['tenant_mobile'])){
  68. if(!empty($parms['tenant_mobile'])){
  69. $where[] = ['tenant_mobile', 'like', '%' . $parms['tenant_mobile']. '%'];
  70. }
  71. }
  72. }
  73. $lists = (new AssetLeaseInfo())->field('*')
  74. ->append(['first_status_desc','second_status_desc'])
  75. ->with('asset')
  76. ->with('referee')
  77. ->where($where)
  78. // ->where($this->searchWhere)
  79. ->limit($this->limitOffset, $this->limitLength)
  80. ->Order('id desc')
  81. ->select()
  82. ->toArray();
  83. foreach($lists as &$v){
  84. $v['first_name'] = adminModel::where(['id'=>$v['first_uid']])->value('name') ?? '';
  85. $v['second_name'] = adminModel::where(['id'=>$v['second_uid']])->value('name') ?? '' ;
  86. }
  87. return $lists;
  88. }
  89. /**
  90. * @notes 资产信息数量
  91. * @return int
  92. * @author ljj
  93. * @date 2022/2/16 3:18 下午
  94. */
  95. public function count(): int
  96. {
  97. return (new AssetLeaseInfo())->where($this->searchWhere)->count();
  98. }
  99. /**
  100. * @notes 添加租赁资产订单
  101. * @param array $params
  102. * @author heshihu
  103. * @date 2022/2/22 9:57
  104. */
  105. public static function add(array $params)
  106. {
  107. if ($params['lease_end_time']<$params['lease_start_time']) {
  108. return ['code' => 0, 'msg' => '租赁时间范围有误请检查!'];
  109. }
  110. $where = [];
  111. $where[] = ['lease_end_time', '>=', $params['lease_start_time']];
  112. $where[] = ['lease_end_time', '>=', $params['lease_start_time']];
  113. $where[] = ['a_id', '=', $params['a_id']];
  114. $assetLeaseInfo = AssetLeaseInfo::where($where)->findOrEmpty();
  115. if (!$assetLeaseInfo->isEmpty()) {
  116. return ['code' => 0, 'msg' => '租赁期内有未到期的租赁信息!'];
  117. }
  118. AssetLeaseInfo::create([
  119. 'a_id' => $params['a_id'],
  120. 'tenant_name' => $params['tenant_name'] ?? '',
  121. 'tenant_mobile' => $params['tenant_mobile'] ?? '',
  122. 'license_number' => $params['license_number'] ?? '',
  123. 'license_image' => $params['license_image'] ?? '',
  124. 'lease_contract_image' => $params['lease_contract_image'] ?? '',
  125. 'lease_money' => $params['lease_money'] ?? 0,
  126. 'lease_start_time' => $params['lease_start_time'] ?? '',
  127. 'lease_end_time' => $params['lease_end_time'] ?? '', // 联系人
  128. 'purpose' => $params['purpose'] ?? '',
  129. 'referee_uid' => 1,
  130. 'remark' => $params['remark'] ?? '',
  131. ]);
  132. return ['code' => 200, 'msg' => '新增租赁信息成功!'];
  133. }
  134. /**
  135. * @notes 编辑资产
  136. * @param array $params
  137. * @return bool
  138. * @author heshihu
  139. * @date 2022/2/22 10:12
  140. */
  141. public static function edit(array $params) : bool
  142. {
  143. try {
  144. AssetInfo::update([
  145. 'id' => $params['id'],
  146. 'name' => $params['name'],
  147. 'images' => $params['images'],
  148. 'address' => $params['address'],
  149. 'contacts' => $params['contacts'],
  150. 'mobile' => $params['mobile'],
  151. 'area' => $params['area'] ?? '',
  152. 'content' => $params['content'] ?? '',
  153. 'status' => $params['status'] ?? 1,
  154. 'sort' => $params['sort'] ?? 0,
  155. 'content' => $params['content'] ?? '',
  156. ]);
  157. return true;
  158. } catch (\Exception $e) {
  159. self::setError($e->getMessage());
  160. return false;
  161. }
  162. }
  163. /**
  164. * @notes 删除资产
  165. * @param array $params
  166. * @author heshihu
  167. * @date 2022/2/22 10:17
  168. */
  169. public static function delete(array $params)
  170. {
  171. AssetInfo::destroy($params['id']);
  172. }
  173. /**
  174. * @notes 查看资产详情
  175. * @param $params
  176. * @return array
  177. * @author heshihu
  178. * @date 2022/2/22 10:15
  179. */
  180. public static function detail($params) : array
  181. {
  182. return AssetInfo::findOrEmpty($params['id'])->append(['status_desc','lease_status_desc'])->toArray();
  183. }
  184. }