<?php
|
|
namespace app\operations\model\takeout;
|
|
use app\common\model\takeout\DeliverymanCash as DeliverymanCashModel;
|
use app\operations\model\takeout\Deliveryman as DeliverymanModel;
|
/**
|
* 模型
|
*/
|
class DeliverymanCash extends DeliverymanCashModel
|
{
|
/**
|
* 获取列表数据
|
*/
|
public function getList($params)
|
{
|
$model = $this;
|
if (!empty($params['search'])) {
|
$model = $model->where('td.real_name', 'like', '%' . $params['search'] . '%');
|
}
|
if (isset($params['apply_status']) && $params['apply_status'] > -1) {
|
$model = $model->where('c.apply_status', '=', $params['apply_status']);
|
}
|
if (isset($params['pay_type']) && $params['pay_type'] > -1) {
|
$model = $model->where('c.pay_type', '=', $params['pay_type']);
|
}
|
// 查询列表数据
|
return $model->alias('c')
|
->with(['user'])
|
->join('takeout_deliveryman td', 'c.commander_id=td.commander_id')
|
->field('c.*,td.real_name,td.mobile')
|
->order(['c.create_time' => 'desc'])
|
->paginate($params);
|
}
|
|
/**
|
* 提现审核
|
*/
|
public function submit($param)
|
{
|
$data = ['apply_status' => $param['apply_status']];
|
if ($param['apply_status'] == 30) {
|
$data['reject_reason'] = $param['reject_reason'];
|
}
|
// 更新申请记录
|
$data['audit_time'] = time();
|
$this->save($data);
|
// 提现驳回:解冻资金
|
if ($param['apply_status'] == 30) {
|
DeliverymanModel::backFreezeMoney($this['user_id'], $this['money']);
|
}
|
return true;
|
}
|
|
/**
|
* 确认已打款
|
*/
|
public function money()
|
{
|
$this->startTrans();
|
try {
|
// 更新申请状态
|
$data = ['apply_status' => 40, 'audit_time' => time()];
|
$this->save($data);
|
|
// 更新累积提现佣金
|
DeliverymanModel::totalMoney($this['user_id'], $this['money']);
|
// 事务提交
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
/**
|
* 获取申请数量
|
*/
|
public static function getApplyCount($apply_status)
|
{
|
return (new static())->where('apply_status', '=', $apply_status)->count();
|
}
|
}
|