138 lines
4.5 KiB
PHP
138 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace app\model\Merchant;
|
|
|
|
use app\model\BaseModel;
|
|
use app\model\merchant\Merchant as MerchantModel;
|
|
/**
|
|
* 系统站点信息管理
|
|
* @author Administrator
|
|
*
|
|
*/
|
|
class Apply extends BaseModel
|
|
{
|
|
|
|
/**
|
|
* 获取提现记录
|
|
* @param $condition
|
|
* @param string $field
|
|
* @param string $order
|
|
* @param OrderCommon $instance
|
|
* @return array
|
|
*/
|
|
public function getWithdrawalLogList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'createtime desc', $field = '*')
|
|
{
|
|
$list = model('merch_withdraw')->pageList($condition, $field, $order, $page, $page_size);
|
|
return $this->success($list);
|
|
}
|
|
|
|
/**
|
|
* 同意提现申请
|
|
* @param $condition
|
|
* @return array
|
|
*/
|
|
public function agree($condition)
|
|
{
|
|
$check_condition = array_column($condition, 2, 0);
|
|
$site_id = $check_condition[ 'site_id' ];
|
|
if (empty($site_id)) {
|
|
return $this->error(-1, '参数错误');
|
|
}
|
|
$info = model("merch_withdraw")->getInfo($condition);
|
|
|
|
if (empty($info))
|
|
return $this->error();
|
|
|
|
model('merch_withdraw')->startTrans();
|
|
try {
|
|
$data = array (
|
|
"status" => 1,
|
|
"status_name" => "待转账",
|
|
"audit_time" => time(),
|
|
);
|
|
$result = model("merch_withdraw")->update($data, $condition);
|
|
model('merch_withdraw')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('merch_withdraw')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 拒绝提现申请
|
|
* @param $condition
|
|
* @param $param
|
|
* @return array
|
|
*/
|
|
public function refuse($condition, $param)
|
|
{
|
|
$info = model("merch_withdraw")->getInfo($condition, "site_id,transfer_type,merch_id,apply_money");
|
|
if (empty($info))
|
|
return $this->error();
|
|
model('merch_withdraw')->startTrans();
|
|
try {
|
|
$data = array (
|
|
"status" => -1,
|
|
"status_name" => "已拒绝",
|
|
"refuse_reason" => $param[ "refuse_reason" ],
|
|
"audit_time" => time(),
|
|
);
|
|
$result = model("merch_withdraw")->update($data, $condition);
|
|
|
|
//增加余额
|
|
$MerchModel = new MerchantModel();
|
|
$merch = model('merch')->getInfo(['merch_id'=>$info[ "merch_id" ]]);
|
|
$account_res = $MerchModel->credit($info['site_id'],0,$info[ "merch_id" ],$merch['balance'],$info['apply_money'],'商户提现未通过返还');
|
|
//减少提现中余额
|
|
model("merch")->setDec([ [ "merch_id", "=", $info[ "merch_id" ] ] ], "balance_withdraw_apply", $info[ "apply_money" ]);
|
|
|
|
model('merch_withdraw')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('merch_withdraw')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 提现转账完成
|
|
* @param array $param
|
|
* @return array
|
|
*/
|
|
public function transferFinish($param = [])
|
|
{
|
|
$condition = [
|
|
[ 'id', '=', $param[ 'id' ] ],
|
|
[ 'site_id', '=', $param[ 'site_id' ] ],
|
|
[ 'status', '=', 1 ]
|
|
];
|
|
$info = model("merch_withdraw")->getInfo($condition);
|
|
if (empty($info)) return $this->error();
|
|
|
|
$payment_time = time();
|
|
model('merch_withdraw')->startTrans();
|
|
try {
|
|
$data = [
|
|
'status' => 2,
|
|
'status_name' => '已转账',
|
|
'payment_time' => $payment_time,
|
|
'certificate' => $param[ 'certificate' ] ?? '',
|
|
'certificate_remark' => $param[ 'certificate_remark' ] ?? ''
|
|
];
|
|
$result = model("merch_withdraw")->update($data, $condition);
|
|
|
|
//增加已提现余额
|
|
model("merch")->setInc([ [ "merch_id", "=", $info[ "merch_id" ] ] ], "balance_withdraw", $info[ "apply_money" ]);
|
|
//减少提现中余额
|
|
model("merch")->setDec([ [ "merch_id", "=", $info[ "merch_id" ] ] ], "balance_withdraw_apply", $info[ "apply_money" ]);
|
|
|
|
model('merch_withdraw')->commit();
|
|
return $this->success();
|
|
} catch (\Exception $e) {
|
|
model('merch_withdraw')->rollback();
|
|
return $this->error('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
} |