AssetLeaseLists.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. use think\Exception;
  22. /**
  23. * 资产租赁管理
  24. * Class AssetLists
  25. * @package app\adminapi\lists\asset
  26. */
  27. class AssetLeaseLists 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. $parms = $this->request->get();
  53. $where = [] ;
  54. if(!empty($parms))
  55. {
  56. if(isset($parms['asset_name'])){
  57. $awhere = [] ;
  58. $awhere[] = ['name', 'like', '%' . $parms['asset_name']. '%'];
  59. $assetList = AssetInfo::where($awhere)->select()->toArray();
  60. $a_id_Arr = array_column($assetList,'id');
  61. $where[]=['a_id','in',$a_id_Arr];
  62. }
  63. if(isset($parms['tenant_name'])){
  64. if(!empty($parms['tenant_name'])){
  65. $where[] = ['tenant_name', 'like', '%' . $parms['tenant_name']. '%'];
  66. }
  67. }
  68. if(isset($parms['tenant_mobile'])){
  69. if(!empty($parms['tenant_mobile'])){
  70. $where[] = ['tenant_mobile', 'like', '%' . $parms['tenant_mobile']. '%'];
  71. }
  72. }
  73. }
  74. $lists = (new AssetLeaseInfo())->field('*')
  75. ->append(['first_status_desc','second_status_desc'])
  76. ->with('asset')
  77. ->with('referee')
  78. ->where($where)
  79. // ->where($this->searchWhere)
  80. ->limit($this->limitOffset, $this->limitLength)
  81. ->Order('id desc')
  82. ->select()
  83. ->toArray();
  84. foreach($lists as &$v){
  85. $v['first_name'] = adminModel::where(['id'=>$v['first_uid']])->value('name') ?? '';
  86. $v['second_name'] = adminModel::where(['id'=>$v['second_uid']])->value('name') ?? '' ;
  87. }
  88. return $lists;
  89. }
  90. /**
  91. * @notes 资产信息数量
  92. * @return int
  93. * @author ljj
  94. * @date 2022/2/16 3:18 下午
  95. */
  96. public function count(): int
  97. {
  98. return (new AssetLeaseInfo())->where($this->searchWhere)->count();
  99. }
  100. /**
  101. * @notes 添加租赁资产订单
  102. * @param array $params
  103. * @author heshihu
  104. * @date 2022/2/22 9:57
  105. */
  106. public static function add(array $params)
  107. {
  108. if ($params['lease_end_time']<$params['lease_start_time']) {
  109. return ['code' => 0, 'msg' => '租赁时间范围有误请检查!'];
  110. }
  111. $where = [];
  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_name' =>$params['referee_name'],
  130. 'referee_uid' =>$params['referee_uid'],
  131. 'remark' => $params['remark'] ?? '',
  132. ]);
  133. return ['code' => 200, 'msg' => '新增租赁信息成功!'];
  134. }
  135. /**
  136. * @notes 编辑租赁信息资产
  137. * @param array $params
  138. * @return bool
  139. * @author heshihu
  140. * @date 2022/2/22 10:12
  141. */
  142. public static function edit(array $params) : bool
  143. {
  144. try {
  145. if ($params['lease_end_time']<$params['lease_start_time']) {
  146. throw new \Exception('租赁时间范围有误请检查');
  147. }
  148. $where = [];
  149. $where[] = ['lease_end_time', '>=', $params['lease_start_time']];
  150. $where[] = ['id', '<>', $params['id']];
  151. $where[] = ['a_id', '=', $params['a_id']];
  152. $assetLeaseInfo = AssetLeaseInfo::where($where)->findOrEmpty();
  153. if (!$assetLeaseInfo->isEmpty()) {
  154. throw new \Exception('租赁期内有未到期的租赁信息');
  155. }
  156. AssetLeaseInfo::update([
  157. 'id'=>$params['id'],
  158. 'a_id' => $params['a_id'],
  159. 'tenant_name' => $params['tenant_name'] ?? '',
  160. 'tenant_mobile' => $params['tenant_mobile'] ?? '',
  161. 'license_number' => $params['license_number'] ?? '',
  162. 'license_image' => $params['license_image'] ?? '',
  163. 'lease_contract_image' => $params['lease_contract_image'] ?? '',
  164. 'lease_money' => $params['lease_money'] ?? 0,
  165. 'lease_start_time' => $params['lease_start_time'] ?? '',
  166. 'lease_end_time' => $params['lease_end_time'] ?? '', // 联系人
  167. 'purpose' => $params['purpose'] ?? '',
  168. 'referee_name' =>$params['referee_name'],
  169. 'referee_uid' =>$params['referee_uid'],
  170. 'remark' => $params['remark'] ?? '',
  171. 'first_status'=>$params['first_status'] ?? 1,
  172. 'first_uid'=>$params['first_uid'] ?? 0,
  173. 'second_status'=>$params['second_status'] ?? 0,
  174. 'second_uid'=>$params['second_uid'] ?? 0,
  175. ]);
  176. return true ;
  177. } catch (\Exception $e) {
  178. self::setError($e->getMessage());
  179. return false;
  180. }
  181. }
  182. /**
  183. * @notes 删除资产
  184. * @param array $params
  185. * @author heshihu
  186. * @date 2022/2/22 10:17
  187. */
  188. public static function delete(array $params)
  189. {
  190. AssetInfo::destroy($params['id']);
  191. }
  192. /**
  193. * @notes 查看资产详情
  194. * @param $params
  195. * @return array
  196. * @author heshihu
  197. * @date 2022/2/22 10:15
  198. */
  199. public static function detail($params) : array
  200. {
  201. return AssetLeaseInfo::with('asset')->findOrEmpty($params['id'])->append(['first_status_desc','second_status_desc'])->toArray();
  202. }
  203. }