| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\lists\asset;
- use app\adminapi\lists\BaseAdminDataLists;
- use app\common\lists\ListsSearchInterface;
- use app\common\model\asset\AssetInfo;
- use app\common\model\asset\AssetLeaseInfo;
- use app\common\model\auth\Admin as adminModel ;
- use app\common\model\auth\AdminJobs;
- use app\common\service\FileService;
- use think\Exception;
- /**
- * 资产租赁管理
- * Class AssetLists
- * @package app\adminapi\lists\asset
- */
- class AssetLeaseLists extends BaseAdminDataLists implements ListsSearchInterface
- {
- /**
- * @notes 搜索条件
- * @return \string[][]
- * @author
- * @date 2025/04/12 2:21 下午
- */
- public function setSearch(): array
- {
- return [
- // '=' => [ 'approval_status'],
- '%like%'=>['tenant_name','tenant_mobile'],
- ];
- }
- /**
- * @notes 资产信息列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author ljj
- * @date 2022/2/16 3:18 下午
- */
- public function lists(): array
- {
- $admin_info = $this->adminInfo;
- $parms = $this->request->get();
- $where = [] ;
- $flag = false;
- if(!empty($parms))
- {
- if(isset($parms['name'])) {
- if (!empty($parms['name'])) {
- $awhere = [];
- $awhere[] = ['name', 'like', '%' . $parms['name'] . '%'];
- $assetList = AssetInfo::where($awhere)->select()->toArray();
- $a_id_Arr = array_column($assetList, 'id');
- $where[] = ['a_id', 'in', $a_id_Arr];
- }
- }
- // if(isset($parms['date_type'])) {
- if (!empty($parms['create_time_start']) && !empty($parms['create_time_end'])) {
- // if($parms['date_type'] == 1){
- $where[] = ['create_time', 'between', [strtotime($parms['create_time_start']),strtotime($parms['create_time_end']. ' 23:59:59')]];
- // }else if($parms['date_type'] == 2){
- // $where[] = ['lease_start_time', '>=', $parms['start_time']];
- // $where[] = ['lease_end_time', '<=', $parms['end_time']];
- // }
- }
- // }
- if(isset($parms['approval_status'])) {
- if ($parms['approval_status']) {
- $where[] = ['approval_status', '=', $parms['approval_status']];
- }
- }
- if(isset($parms['expiration_flag'])) {
- $today = date('Y-m-d');
- $expiration_date = date('Y-m-d', strtotime($today . ' +30 day'));
- if ($parms['expiration_flag']) {
- $flag = true;
- $where[] = ['lease_end_time', '<=', $expiration_date];
- $where[] = ['approval_status','=','5'];
- }
- }
- }
- if(!$admin_info['root']) {
- // $where[] = ['lease_start_time', '>=', $parms['start_time']];
- $jwhere = [];
- $jwhere[] = ['admin_id', '=', $admin_info['admin_id']];
- $jobs_list = AdminJobs::where($jwhere)->select()->toArray();
- $all = false;
- $first = false;
- $second = false;
- foreach ($jobs_list as $v) {
- switch ($v['jobs_id']) {
- case 1:
- $all = true;
- break;
- case 2:
- $first = true;
- break;
- case 3:
- $second = true;
- break;
- }
- }
- if (!$all) {
- if(!($first && $second)){
- if($first){
- $where[] = ['approval_status','in',[1,2]];
- }
- if($second){
- $where[] = ['approval_status','in',[3,4,5]];
- }
- }
- }
- }
- $lists = (new AssetLeaseInfo())->field('*')
- ->append(['first_status_desc','second_status_desc','approval_status_desc'])
- // ->with('referee')
- ->with(['asset','referee'])
- ->where($where)
- ->where($this->searchWhere)
- ->limit($this->limitOffset, $this->limitLength)
- ->Order('id desc')
- ->select()
- ->toArray();
- foreach($lists as &$v){
- $v['first_name'] = adminModel::where(['id'=>$v['first_uid']])->value('name') ?? '';
- $v['second_name'] = adminModel::where(['id'=>$v['second_uid']])->value('name') ?? '' ;
- if($flag){
- $startTime = strtotime(date('Y-m-d'));
- $endTime = strtotime($v['lease_end_time']);
- $diff = $startTime-$endTime;
- $day = $diff/86400;
- $v['diff_day'] = $day;
- }
- }
- return $lists;
- }
- /**
- * @notes 资产信息数量
- * @return int
- * @author ljj
- * @date 2022/2/16 3:18 下午
- */
- public function count(): int
- {
- $admin_info = $this->adminInfo;
- $parms = $this->request->get();
- $where = [] ;
- if(!empty($parms))
- {
- if(isset($parms['asset_name'])) {
- if (!empty($parms['asset_name'])) {
- $awhere = [];
- $awhere[] = ['name', 'like', '%' . $parms['asset_name'] . '%'];
- $assetList = AssetInfo::where($awhere)->select()->toArray();
- $a_id_Arr = array_column($assetList, 'id');
- $where[] = ['a_id', 'in', $a_id_Arr];
- }
- }
- if(isset($parms['date_type'])) {
- if (!empty($parms['start_time']) && !empty($parms['end_time'])) {
- if($parms['date_type'] == 1){
- $where[] = ['create_time', 'between', [strtotime($parms['start_time']),strtotime($parms['end_time']. ' 23:59:59')]];
- }else if($parms['date_type'] == 2){
- $where[] = ['lease_start_time', '>=', $parms['start_time']];
- $where[] = ['lease_end_time', '<=', $parms['end_time']];
- }
- }
- }
- if(isset($parms['approval_status'])) {
- if ($parms['approval_status']) {
- $where[] = ['approval_status', '=', $parms['approval_status']];
- }
- }
- if(isset($parms['expiration_flag'])) {
- $today = date('Y-m-d');
- $expiration_date = date('Y-m-d', strtotime($today . ' +30 day'));
- if ($parms['expiration_flag']) {
- $where[] = ['lease_end_time', '<=', $expiration_date];
- $where[] = ['approval_status','=','5'];
- }
- }
- }
- if(!$admin_info['root']) {
- // $where[] = ['lease_start_time', '>=', $parms['start_time']];
- $jwhere = [];
- $jwhere[] = ['admin_id', '=', $admin_info['admin_id']];
- $jobs_list = AdminJobs::where($jwhere)->select()->toArray();
- $all = false;
- $first = false;
- $second = false;
- foreach ($jobs_list as $v) {
- switch ($v['jobs_id']) {
- case 1:
- $all = true;
- break;
- case 2:
- $first = true;
- break;
- case 3:
- $second = true;
- break;
- }
- }
- if (!$all) {
- if(!($first && $second)){
- if($first){
- $where[] = ['approval_status','in',[1,2]];
- }
- if($second){
- $where[] = ['approval_status','in',[3,4,5]];
- }
- }
- }
- }
- return (new AssetLeaseInfo())->where($this->searchWhere)->where($where)->count();
- }
- /**
- * @notes 添加租赁资产订单
- * @param array $params
- * @author heshihu
- * @date 2022/2/22 9:57
- */
- public static function add(array $params)
- {
- if ($params['lease_end_time']<$params['lease_start_time']) {
- return ['code' => 0, 'msg' => '租赁时间范围有误请检查!'];
- }
- $where = [];
- $where[] = ['lease_end_time', '>=', $params['lease_start_time']];
- $where[] = ['a_id', '=', $params['a_id']];
- $assetLeaseInfo = AssetLeaseInfo::where($where)->findOrEmpty();
- if (!$assetLeaseInfo->isEmpty()) {
- return ['code' => 0, 'msg' => '租赁期内有未到期的租赁信息!'];
- }
- AssetLeaseInfo::create([
- 'a_id' => $params['a_id'],
- 'tenant_name' => $params['tenant_name'] ?? '',
- 'tenant_mobile' => $params['tenant_mobile'] ?? '',
- 'license_number' => $params['license_number'] ?? '',
- 'license_image' => $params['license_image'] ?? '',
- 'lease_contract_image' => $params['lease_contract_image'] ?? '',
- 'lease_money' => $params['lease_money'] ?? 0,
- 'lease_start_time' => $params['lease_start_time'] ?? '',
- 'lease_end_time' => $params['lease_end_time'] ?? '',
- 'purpose' => $params['purpose'] ?? '',
- 'referee_name' =>$params['referee_name'],
- 'referee_uid' =>$params['referee_uid'],
- 'remark' => $params['remark'] ?? '',
- ]);
- return ['code' => 200, 'msg' => '新增租赁信息成功!'];
- }
- /**
- * @notes 编辑租赁信息资产
- * @param array $params
- * @return bool
- * @author heshihu
- * @date 2022/2/22 10:12
- */
- public static function edit(array $params) : bool
- {
- try {
- if ($params['lease_end_time']<$params['lease_start_time']) {
- throw new \Exception('租赁时间范围有误请检查');
- }
- $where = [];
- $where[] = ['lease_end_time', '>=', $params['lease_start_time']];
- $where[] = ['id', '<>', $params['id']];
- $where[] = ['a_id', '=', $params['a_id']];
- $assetLeaseInfo = AssetLeaseInfo::where($where)->findOrEmpty();
- if (!$assetLeaseInfo->isEmpty()) {
- throw new \Exception('租赁期内有未到期的租赁信息');
- }
- $asset_lease_info = AssetLeaseInfo::find($params['id']);
- $approval_status = $asset_lease_info['approval_status'];
- //审核状态 1:等待初审 2 初审驳回 3:初审通过 4:等待终审 5:终审通过 6:终审驳回
- $new_approval_status = 1;
- switch ($approval_status){
- case 1:
- $new_approval_status =1;
- break;
- case 2:
- $new_approval_status =1;
- break;
- case 3:
- $new_approval_status =4;
- break;
- case 4:
- $new_approval_status =4;
- break;
- case 5:
- $new_approval_status =5;
- break;
- case 6:
- $new_approval_status =1;
- break;
- default:
- $new_approval_status =1;
- break;
- }
- AssetLeaseInfo::update([
- 'id'=>$params['id'],
- 'a_id' => $params['a_id'],
- 'tenant_name' => $params['tenant_name'] ?? '',
- 'tenant_mobile' => $params['tenant_mobile'] ?? '',
- 'license_number' => $params['license_number'] ?? '',
- 'license_image' => $params['license_image'] ?? '',
- 'lease_contract_image' => $params['lease_contract_image'] ?? '',
- 'lease_money' => $params['lease_money'] ?? 0,
- 'lease_start_time' => $params['lease_start_time'] ?? '',
- 'lease_end_time' => $params['lease_end_time'] ?? '', // 联系人
- 'purpose' => $params['purpose'] ?? '',
- 'referee_name' =>$params['referee_name'],
- 'referee_uid' =>$params['referee_uid'],
- 'remark' => $params['remark'] ?? '',
- 'first_status'=>$params['first_status'] ?? 1,
- 'first_uid'=>$params['first_uid'] ?? 0,
- 'second_status'=>$params['second_status'] ?? 0,
- 'second_uid'=>$params['second_uid'] ?? 0,
- 'approval_status'=>$new_approval_status,
- ]);
- return true ;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- /**
- * @notes 删除资产
- * @param array $params
- * @author heshihu
- * @date 2022/2/22 10:17
- */
- public static function delete(array $params)
- {
- AssetLeaseInfo::destroy($params['id']);
- }
- /**
- * @notes 查看资产详情
- * @param $params
- * @return array
- * @author heshihu
- * @date 2022/2/22 10:15
- */
- public static function detail($params) : array
- {
- return AssetLeaseInfo::with(['asset','firstapproval','endapproval'])->findOrEmpty($params['id'])->append(['first_status_desc','second_status_desc'])->toArray();
- }
- /**
- * @notes 租赁资产信息审核
- * @param array $params
- * @return bool
- * @author heshihu
- * @date 2022/2/22 10:12
- */
- public static function approve(array $params) : bool
- {
- try {
- $id = $params['id'];
- $leaseAssetInfo = AssetLeaseInfo::find($id);
- $updateData['id'] = $id;
- if(in_array($leaseAssetInfo['approval_status'],[1,2,3])){
- if(in_array($params['approval_status'],[4,5,6])){
- throw new \Exception('请先进行初审操作!');
- }
- $approval_status = empty($params['approval_status'])?$leaseAssetInfo['approval_status']:$params['approval_status'];
- $ramark = '';
- if( $approval_status == 3){
- $approval_status = 4;
- $ramark = '';
- $updateData['remark'] = $ramark;
- }elseif($approval_status == 2){
- if(isset($params['remark'])){
- if(empty($params['remark'])){
- throw new \Exception('请输入驳回原因!');
- }else{
- $remark = $params['remark'];
- }
- }else{
- throw new \Exception('请输入驳回原因!');
- }
- }else{
- $updateData['remark'] = $ramark;
- }
- if(!empty($remark)){
- $updateData['remark'] = $remark;
- }
- $updateData['approval_status'] = $approval_status;
- $updateData['first_uid'] = $params['approve_uid'];
- $updateData['first_approval_time'] = time();
- }else{
- //终审
- if(in_array($params['approval_status'],[1,2,3])){
- throw new \Exception('初审已完成无需再次操作');
- }
- $approval_status = $params['approval_status'];
- $ramark = '';
- if($approval_status == 6){
- if(isset($params['remark'])){
- if(empty($params['remark'])){
- throw new \Exception('请输入驳回原因!');
- }else{
- $remark = $params['remark'];
- }
- }else{
- throw new \Exception('请输入驳回原因!');
- }
- }else{
- $updateData['remark'] = $ramark;
- }
- if(!empty($remark)){
- $updateData['remark'] = $remark;
- }
- $updateData['approval_status'] = $approval_status;
- $updateData['second_uid'] = $params['approve_uid'];
- $updateData['end_approval_time'] = time();
- }
- AssetLeaseInfo::update($updateData);
- if($approval_status == 5){
- $leaseAssetInfo = AssetLeaseInfo::find($id);
- $assetInfo = AssetInfo::find($leaseAssetInfo['a_id']);
- $updateAssetData['id'] = $assetInfo['id'];
- $updateFlag = false ;
- if($assetInfo['lease_status']==2){
- if(strtotime($leaseAssetInfo['lease_end_time']) > strtotime($assetInfo['lease_expiration_time'])){
- $updateAssetData['lease_expiration_time'] = $leaseAssetInfo['lease_end_time'];
- $updateFlag = true ;
- }
- }else{
- $updateAssetData['lease_expiration_time'] = $leaseAssetInfo['lease_end_time'];
- $updateAssetData['lease_status'] = 2;
- $updateFlag = true ;
- }
- if($updateFlag){
- AssetInfo::update($updateAssetData);
- }
- }
- return true ;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- public static function autoUpdateStatus():bool{
- $where = [] ;
- $where[] = ['auto_status','=',0] ;
- $where[]= ['approval_status','=',5];
- $assetLeaseList = AssetLeaseInfo::where($where)->select()->toArray();
- $nowTime = time();
- foreach($assetLeaseList as &$v){
- $assetInfo = AssetInfo::find($v['a_id']);
- $a_lease_expiration_time = $assetInfo['lease_expiration_time'];
- if($nowTime >= strtotime($v['lease_end_time'])){
- $updateLeaseData['id']=$v['id'];
- $updateLeaseData['auto_status']=1;
- AssetLeaseInfo::update($updateLeaseData);
- if(strtotime($v['lease_end_time']) >= strtotime($a_lease_expiration_time)) {
- $updateAssetData['id'] = $assetInfo['id'];
- $updateAssetData['lease_status'] = 3;
- AssetInfo::update($updateAssetData);
- }else{
- continue;
- }
- }else{
- continue;
- }
- }
-
- return true;
- }
- public static function setEnd(array $params):bool
- {
- try {
- $id = $params['id'];
- $leaseAssetInfo = AssetLeaseInfo::find($id);
- $updateAssetData['id'] = $leaseAssetInfo['a_id'];
- $updateAssetData['lease_expiration_time'] = '';
- $updateAssetData['lease_status'] = 1;
- AssetInfo::update($updateAssetData);
- return true;
- } catch (\Exception $e) {
- self::setError($e->getMessage());
- return false;
- }
- }
- }
|