AssetLeaseLists.php 8.1 KB

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