<?php
|
|
namespace app\operations\model\branch;
|
|
use app\common\model\branch\DepositRefund as DepositRefundModel;
|
use app\branch\model\branch\Branch as BranchModel;
|
use app\operations\model\branch\Capital as CapitalModel;
|
|
/**
|
* 退押金申请模型类
|
*/
|
class DepositRefund extends DepositRefundModel
|
{
|
/**
|
* 获取列表数据
|
*/
|
public function getList($params)
|
{
|
$model = $this;
|
if ($params['status'] != '') {
|
$model = $model->where('status', '=', $params['status']);
|
}
|
// 查询列表数据
|
return $model->with(['branch'])
|
->order(['create_time' => 'desc'])
|
->paginate($params);
|
}
|
|
/**
|
* 退押金审核
|
*/
|
public function submit($param)
|
{
|
$this->startTrans();
|
try {
|
$data = ['status' => $param['state']];
|
$data['audit_time'] = time();
|
// 更新申请记录
|
$this->save($data);
|
$branch = BranchModel::detail($this['branch_id']);
|
|
if ($param['state'] == 2) {//拒绝退押金
|
(new BranchModel())->where(['branch_id' => $this['branch_id']])->update(['status' => 0]);
|
} else if ($param['state'] == 1) {//同意退押金
|
(new BranchModel())->where(['branch_id' => $this['branch_id']])->update(['status' => 20, 'deposit_money' => 0, 'money' => $branch['money'] + $this['deposit_money'], 'total_money' => $branch['total_money'] + $this['deposit_money']]);
|
$add = [
|
'branch_id' => $this['branch_id'],
|
'flow_type' => 10,
|
'money' => $this['deposit_money'],
|
'describe' => '退押金收入',
|
];
|
//添加资金明细
|
CapitalModel::add($add);
|
}
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
/**
|
* 获取退款数
|
*/
|
public static function getRefundCount(){
|
return (new static())->where('status', '=', 0)->count();
|
}
|
|
/**
|
* 获取供应商申请统计数量
|
*/
|
public function getRefundData($startDate = null, $endDate = null, $type)
|
{
|
$model = $this;
|
$field = '';
|
if($type == 'branch_refund'){
|
$field = 'audit_time';
|
$model = $model->where('status', '=', 1);
|
} else if($type == 'branch_refund_apply'){
|
$field = 'create_time';
|
}
|
if(!is_null($startDate)){
|
$model = $model->where($field, '>=', strtotime($startDate));
|
}
|
if(is_null($endDate)){
|
$model = $model->where($field, '<', strtotime($startDate) + 86400);
|
}else{
|
$model = $model->where($field, '<', strtotime($endDate) + 86400);
|
}
|
|
return $model->count();
|
}
|
}
|