|
|
|
@ -59,7 +59,7 @@ class UserExtractRepository extends BaseRepository |
|
|
|
|
public function getWhereCount($id) |
|
|
|
|
{ |
|
|
|
|
$where['extract_id'] = $id; |
|
|
|
|
$where['status'] = 0; |
|
|
|
|
$where['status'] = 0; |
|
|
|
|
return $this->dao->getWhereCount($where) > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -74,11 +74,17 @@ class UserExtractRepository extends BaseRepository |
|
|
|
|
*/ |
|
|
|
|
public function getList(array $where, $page, $limit) |
|
|
|
|
{ |
|
|
|
|
if (isset($where['keyword']) and $where['keyword'] != '') { |
|
|
|
|
$user = app(UserRepository::class)->getUserByPhone($where['keyword']); |
|
|
|
|
if ($user) { |
|
|
|
|
$where['uid'] = $user['uid']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$query = $this->dao->search($where)->with(['user' => function ($query) { |
|
|
|
|
$query->field('uid,avatar,nickname'); |
|
|
|
|
$query->field('uid,avatar,nickname,phone'); |
|
|
|
|
}]); |
|
|
|
|
$count = $query->count(); |
|
|
|
|
$list = $query->page($page, $limit)->select(); |
|
|
|
|
$list = $query->page($page, $limit)->select(); |
|
|
|
|
return compact('count', 'list'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -105,39 +111,43 @@ class UserExtractRepository extends BaseRepository |
|
|
|
|
* @author Qinii |
|
|
|
|
* @day 2020-06-16 |
|
|
|
|
*/ |
|
|
|
|
public function create($user,$data) |
|
|
|
|
public function create($user, $data) |
|
|
|
|
{ |
|
|
|
|
event('user.extract.before',compact('user','data')); |
|
|
|
|
$userExtract = Db::transaction(function()use($user,$data){ |
|
|
|
|
if($user['brokerage_price'] < (systemConfig('user_extract_min'))) |
|
|
|
|
throw new ValidateException('可提现金额不足'); |
|
|
|
|
if($data['extract_price'] < (systemConfig('user_extract_min'))) |
|
|
|
|
event('user.extract.before', compact('user', 'data')); |
|
|
|
|
$assets = app(UserAssetsRepository::class)->assets($user['uid']); |
|
|
|
|
$config = app(UserAssetsRepository::class)->getConfig(); |
|
|
|
|
$userExtract = Db::transaction(function () use ($user, $data, $assets, $config) { |
|
|
|
|
if ($data['extract_price'] < (systemConfig('user_extract_min'))) |
|
|
|
|
throw new ValidateException('提现金额不得小于最低额度'); |
|
|
|
|
if($user['brokerage_price'] < $data['extract_price']) |
|
|
|
|
if ($assets['integral_withdraw'] + $assets['deposit'] < $data['extract_price']) |
|
|
|
|
throw new ValidateException('提现金额不足'); |
|
|
|
|
if($data['extract_type'] == 3) { |
|
|
|
|
$make = app()->make(WechatUserRepository::class); |
|
|
|
|
$openid = $make->idByOpenId((int)$user['wechat_user_id']); |
|
|
|
|
if (!$openid){ |
|
|
|
|
$openid = $make->idByRoutineId((int)$user['wechat_user_id']); |
|
|
|
|
if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2); |
|
|
|
|
$user->brokerage_price = $brokerage_price; |
|
|
|
|
$user->save(); |
|
|
|
|
|
|
|
|
|
$data['extract_sn'] = $this->createSn(); |
|
|
|
|
$data['uid'] = $user['uid']; |
|
|
|
|
$data['balance'] = $brokerage_price; |
|
|
|
|
$data['uid'] = $user['uid']; |
|
|
|
|
$data['fee'] = round($data['extract_price'] * $config['withdrawRate'] / 100, 2); |
|
|
|
|
$data['real_pay'] = $data['extract_price'] - $data['fee']; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var UserAssetsRepository $repository |
|
|
|
|
*/ |
|
|
|
|
$repository = app(UserAssetsRepository::class); |
|
|
|
|
if ($data['extract_price'] > $assets['deposit']) { |
|
|
|
|
$deposit = $assets['deposit']; |
|
|
|
|
$integral = $data['extract_price'] - $assets['deposit']; |
|
|
|
|
$repository->withdraw($user['uid'], $integral); |
|
|
|
|
$repository->updateAssets($user['uid'], array('deposit' => $deposit), false); |
|
|
|
|
} else { |
|
|
|
|
$deposit = $data['extract_price']; |
|
|
|
|
$repository->updateAssets($user['uid'], array('deposit' => $deposit), false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->dao->create($data); |
|
|
|
|
}); |
|
|
|
|
event('user.extract',compact('userExtract')); |
|
|
|
|
event('user.extract', compact('userExtract')); |
|
|
|
|
SwooleTaskService::admin('notice', [ |
|
|
|
|
'type' => 'extract', |
|
|
|
|
'type' => 'extract', |
|
|
|
|
'title' => '您有一条新的提醒申请', |
|
|
|
|
'id' => $userExtract->extract_id |
|
|
|
|
'id' => $userExtract->extract_id |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -152,63 +162,34 @@ class UserExtractRepository extends BaseRepository |
|
|
|
|
])->setTitle('提现审核'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function switchStatus($id,$data) |
|
|
|
|
public function switchStatus($id, $data) |
|
|
|
|
{ |
|
|
|
|
$extract = $this->dao->getWhere(['extract_id' => $id]); |
|
|
|
|
$user = app()->make(UserRepository::class)->get($extract['uid']); |
|
|
|
|
if(!$user) throw new ValidateException('用户不存在'); |
|
|
|
|
$brokerage_price = 0; |
|
|
|
|
if($data['status'] == -1) |
|
|
|
|
$brokerage_price = bcadd($user['brokerage_price'] ,$extract['extract_price'],2); |
|
|
|
|
$type = systemConfig('sys_extension_type'); |
|
|
|
|
$ret = []; |
|
|
|
|
$service = null; |
|
|
|
|
$func = null; |
|
|
|
|
if ($data['status'] == 1 && $extract['extract_type'] == 3 && in_array($type,[1,2])) { |
|
|
|
|
$func = $type == 1 ? 'merchantPay' : 'companyPay'; |
|
|
|
|
$ret = [ |
|
|
|
|
'sn' => $extract['extract_sn'], |
|
|
|
|
'price' => $extract['extract_price'], |
|
|
|
|
'mark' => '企业付款给用户:'.$user->nickname, |
|
|
|
|
'batch_name' => '企业付款给用户:'.$user->nickname |
|
|
|
|
]; |
|
|
|
|
$openid = app()->make(WechatUserRepository::class)->idByOpenId((int)$user['wechat_user_id']); |
|
|
|
|
if ($openid) { |
|
|
|
|
$ret['openid'] = $openid; |
|
|
|
|
$service = WechatService::create(); |
|
|
|
|
} else { |
|
|
|
|
$routineOpenid = app()->make(WechatUserRepository::class)->idByRoutineId((int)$user['wechat_user_id']); |
|
|
|
|
if (!$routineOpenid) throw new ValidateException('非微信用户不支持付款到零钱'); |
|
|
|
|
$ret['openid'] = $routineOpenid; |
|
|
|
|
$service = MiniProgramService::create(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$user = app()->make(UserRepository::class)->get($extract['uid']); |
|
|
|
|
if (!$user) throw new ValidateException('用户不存在'); |
|
|
|
|
|
|
|
|
|
Db::transaction(function()use($id,$data,$user,$brokerage_price,$ret,$service,$func){ |
|
|
|
|
event('user.extractStatus.before',compact('id','data')); |
|
|
|
|
if ($ret) $service->{$func}($ret); |
|
|
|
|
if($brokerage_price){ |
|
|
|
|
$user->brokerage_price = $brokerage_price; |
|
|
|
|
$user->save(); |
|
|
|
|
Db::transaction(function () use ($id, $data, $user, $extract) { |
|
|
|
|
event('user.extractStatus.before', compact('id', 'data')); |
|
|
|
|
if($data['status'] == -1){ |
|
|
|
|
app(UserAssetsRepository::class)->updateAssets($user['uid'], array('deposit' => $extract['extract_price'])); |
|
|
|
|
} |
|
|
|
|
$userExtract = $this->dao->update($id,$data); |
|
|
|
|
event('user.extractStatus',compact('id','userExtract')); |
|
|
|
|
$userExtract = $this->dao->update($id, $data); |
|
|
|
|
event('user.extractStatus', compact('id', 'userExtract')); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Queue::push(SendSmsJob::class,['tempId' => 'EXTRACT_NOTICE', 'id' =>$id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function createSn() |
|
|
|
|
{ |
|
|
|
|
list($msec, $sec) = explode(' ', microtime()); |
|
|
|
|
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); |
|
|
|
|
$sn = 'ue' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)); |
|
|
|
|
$sn = 'ue' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)); |
|
|
|
|
return $sn; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getHistoryBank($uid) |
|
|
|
|
{ |
|
|
|
|
return $this->dao->getSearch(['uid' => $uid,'extract_type' => 0])->order('create_time DESC')->field('real_name,bank_code,bank_address,bank_name')->find(); |
|
|
|
|
return $this->dao->getSearch(['uid' => $uid, 'extract_type' => 0])->order('create_time DESC')->field('real_name,bank_code,bank_address,bank_name')->find(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function detail(int $id) |
|
|
|
@ -217,7 +198,7 @@ class UserExtractRepository extends BaseRepository |
|
|
|
|
$query->field('uid,avatar,nickname'); |
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
|
if(empty($info)){ |
|
|
|
|
if (empty($info)) { |
|
|
|
|
throw new ValidateException('数据异常'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|