pages = [
'name' => '提现申请'
];
}
public function indexData()
{
return ['status' => config('adconfig.draw_money_status')];
}
public function shareData($id = '')
{
$wallte = merchant()->wallets;//钱包信息
//可用总额=订单总额-提现成功总额
//订单总额
$order_total_money = Order::merchantTotalMoney(merchant('id'));
//提现总额:提现申请,提现审核中,提现完成,提现的金额咯。
$draw_total_money = DrawMoney::merchantDrawMoney(merchant('id'));
//成功结算的佣金金额
$commmission_total_money = MerchantCommission::getMoneyTotal(merchant('id'), 1);
//账号余额=订单结算总额 + 佣金结算完成总额 - 提现总额
$use_money = round($order_total_money + $commmission_total_money - $draw_total_money, 2);
$draw_info = $this->getDrawMoneyStatus();
$day_seizure = $this->daySeizure();
return [
'use_money' => $use_money,
'draw_limit' => $this->drawTimeLimit(),
'day_seizure' => $day_seizure,
'day_seizure_ratio' => $this->dayDrawRatio(),
'draw_info' => $draw_info, 'wallte' => $wallte,
'bank' => BankRel::where(['is_checked' => 1, 'model_id' => $this->getMerchantId(), 'model_type' => 'merchant'])->get()
];
}
public function drawTimeLimit()
{
//提现时间限制
$draw_time_limit = config_cache('draw_config.draw_time_limit');
$draw_time_limit = explode('-', $draw_time_limit);
if (empty($draw_time_limit)) {
$draw_time_limit = [
9, 20
];
}
//当前时间,
$time = date('H');
if ($time >= $draw_time_limit[0] and $time <= $draw_time_limit[1]) {
return true;
}
return false;
}
//每天扣押款
public function daySeizure()
{
//统计今天成就结算总额
$to_day_total_money = Order::getMerchantTotalToDayMoney($this->getMerchantId(), 1);
$day_seizure_money = 0;
//每天押款多少比率
if ($to_day_total_money > 0) {
$day_seizure_ratio = $this->dayDrawRatio(); //config_cache('draw_config.draw_day_money_ratio') ? config_cache('draw_config.draw_day_money_ratio') : 0;
$day_seizure_money = round($to_day_total_money * $day_seizure_ratio / 100, 2);
}
return ['day_total_money' => $to_day_total_money, 'day_seizure_money' => $day_seizure_money];
}
public function getDrawMoneyStatus()
{
//提现总额今天
$data['draw_total'] = $this->setModel()::where('merchant_id', $this->getMerchantId())->whereRaw('DATE_FORMAT(created_at,"%Y-%m-%d") =? ', [date('Y-m-d')])->sum('draw_money');
$data['draw_number'] = $this->setModel()::where('merchant_id', $this->getMerchantId())->whereRaw('DATE_FORMAT(created_at,"%Y-%m-%d") =? ', [date('Y-m-d')])->count('*');
return $data;
}
protected function extendValidate($request, $model, $id)
{
if(!config_cache('draw_config.draw_open')){
return $this->errorJosn('系统关闭了提现功能,请联系我们');
}
//检查是否金额对的上
$data = $request->all();
$day_seizure = $this->daySeizure();
//提现余额是否大于可用余额
//提现金额
$day_moeny = $day_seizure['day_seizure_money'];
//提现金额+冻结资金,如果大于钱包余额
if ($data['draw_money'] + $day_moeny > merchant()->wallets['money']) {
return $this->errorJosn('可用余额不足');
}
//单笔提款金额不能少于
if ($data['draw_money'] < floatval(config_cache('draw_config.draw_min_money'))) {
return $this->errorJosn('单笔提款金额不能少于' . config_cache('draw_config.draw_min_money'));
}
//单笔提款金额不能大于
if ($data['draw_money'] > floatval(config_cache('draw_config.draw_max_money'))) {
return $this->errorJosn('单笔提款金额不能大于' . config_cache('draw_config.draw_max_money'));
}
//次数
$draw_info = $this->getDrawMoneyStatus();
//每天提款次数
$max_number = config_cache('draw_config.draw_day_max_money');
if (($draw_info['draw_number'] + 1) > $max_number) {
return $this->errorJosn('超过今天最大提款次数');
}
//每天提款时间限制
$draw_time_limit = $this->drawTimeLimit();
if (!$draw_time_limit) {
return $this->errorJosn('现在不是提现时间');
}
}
public function checkRule($id = '')
{
if (!$id) {
return [
'draw_money' => 'required',
'fee_money' => 'required',
'bank_realname' => 'required',
];
}
return [
'draw_money' => 'required',
'fee_money' => 'required',
'bank_realname' => 'required',
];
}
public function setErrorMsg()
{
$messages = [
'draw_money.required' => '提现金额不能为空',
'money.required' => '到账金额不能为空',
'fee_money.required' => '手续费不能为空',
'bank_realname.required' => '收款人不能为空',
];
return $messages;
}
public function setModel()
{
return new DrawMoney();
}
public function checkSelf($show)
{
if ($show->model_id != $this->getMerchantId() && $show->model_type == 'merchant') {
return false;
}
return true;
}
public function postDataDb($request, $id = '')
{
$data = $request->all();
$data['merchant_id'] = $this->getMerchantId();
//提现手续费,提现资金,到账资金
$data['money'] = $data['draw_money'] - $data['fee_money'];
$data['status'] = 0;//等待处理
$data['begindb'] = 1;
return $data;
}
public function saveAfter($request, $model, $id = '')
{
//事务类型
//提现成功需要减去账号金额,发生资金变动
$waller_r = MerchantWallet::moneyDecr($this->getMerchantId(), $model->draw_money);
//自己变动插入
$money_log = MerchantMoneyLog::drawMoney($this->getMerchantId(), '-' . $model->draw_money, '提现申请', $model->id);
if ($waller_r && $money_log) {
return true;
}
return false;
}
//发送邮件提醒
public function beginAfter($request, $model, $data = [])
{
$data=[
'id'=>$model->id,
'name'=>merchant('name'),
'draw_money'=>$data['draw_money'],
'money'=>$data['money'],
'fee_money'=>$data['fee_money'],
'bank_name'=>$data['bank_name'],
'bank_account'=>$data['bank_account'],
'bank_realname'=>$data['bank_realname'],
'bank_source'=>$data['bank_source'],
'created_at'=>date('Y-m-d H:i:s')
];
if(config_cache('draw_config.draw_email'))
{
Mail::to(config_cache('draw_config.draw_email'))->send(new DrawMoneyShipped($data));
}
}
public function apiJson(Request $request)
{
$offset = $request->input('page', 1);
$pagesize = $request->input('limit', 1);
$offset = ($offset - 1) * $pagesize;
$order_id = $request->input('sort', 'id');
$order_type = $request->input('order', 'desc');
$debug = $request->input('debug', 0);
$model = $this->setModel();
$data = $request->all();
$data['merchant_id'] = $this->getMerchantId();
$search = new SearchServices($model, $data, 'draw_money');
$model = $search->getModel();
$total = $model->count();
$result = $model->skip($offset)->orderBy($order_id, $order_type)->orderBy('id', 'desc')->take($pagesize)->get();;
$narr = array();
foreach ($result as $k => $v) {
$v['edit_url'] = action($this->route['controller_name'] . '@edit', ['id' => $v->id]);
$v['edit_post_url'] = action($this->route['controller_name'] . '@update', ['id' => $v->id]);
$v['draw_type_name'] = $v->DrawTypeName;
$text_class = '';
if ($v['status'] == 1) {
$text_class = "text-grep";
}
if ($v['status'] == 3) {
$text_class = "text-danger";
}
//查看原因
$why='';
if($v['status']==3)
{
$why='查看原因';
}
$v['status_name_tpl'] = '' . $v->StatusName . ' '.$why;
$narr[] = $v;
}
$json = [
"status" => 1,
'code' => $total > 0 ? 0 : 1,
'msg' => $total > 0 ? '请求数据成功' : '暂无数据',
'count' => $total,
'data' => $narr
];
if ($debug) {
return $this->jsonDebug($json);
}
return response()->json($json);
}
}