| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace app\business;
- use Illuminate\Support\Arr;
- use Respect\Validation\Validator;
- use support\Db;
- use support\Log;
- use support\Redis;
- class WithdrawBusiness
- {
- /** 提现
- * @param array $param
- * @return void
- */
- static public function applyfor(array $param)
- {
- try {
- $system = Db::table('wa_system')->first();
- if ($param['mold'] == 1) {
- if (empty($system->is_money)) {
- throw new \Exception('提现功能暂未开放!');
- }
- if ($system->min_money > $param['money']) {
- throw new \Exception('最小提现金额:' . $system->min_money . '元');
- }
- } elseif ($param['mold'] == 2) {
- throw new \Exception('提现失败!');
- if (empty($system->is_money_one)) {
- throw new \Exception('提现功能暂未开放!');
- }
- if ($system->min_money_one > $param['money']) {
- throw new \Exception('最小提现金额:' . $system->min_money_one . '元');
- }
- } elseif ($param['mold'] == 3) {
- if (empty($system->is_money_two)) {
- throw new \Exception('提现功能暂未开放!');
- }
- if ($system->min_money_two > $param['money']) {
- throw new \Exception('最小提现金额:' . $system->min_money_two . '元');
- }
- } else {
- throw new \Exception('提现功能暂未开放!');
- }
- /** @var $bankCard 银行卡 */
- $bankCard = Db::table('wa_bank_card')->where('uid', $param['user_data']['id'])->first();
- if (empty($bankCard)) {
- throw new \Exception('请绑定银行卡!');
- }
- /** @var $userIdentity 实名信息 */
- $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
- if (empty($userIdentity)) {
- throw new \Exception('请实名后,在提现!');
- }
- $hasWithdraw = Db::table('wa_withdraw')
- ->where('type', $param['mold'])
- ->where('user_id', $param['user_data']['id'])
- ->whereBetween('created_at', [date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59'])->exists();
- if ($hasWithdraw) {
- throw new \Exception('今日已提现,请次日在来提现!');
- }
- if ($param['mold'] == 2){
- $status = 3;
- }else{
- $status = 1;
- }
- $withdrawId = Db::table('wa_withdraw')->insertGetId([
- 'order_no' => date('YmdHis') . mt_rand(10000, 99999),
- 'user_id' => $param['user_data']['id'],
- 'money' => $param['money'],
- 'type' => $param['mold'],
- 'affiliated_bank' => $bankCard->affiliated_bank,
- 'account_holder' => $bankCard->account_holder,
- 'card_number' => $bankCard->card_number,
- 'name' => Arr::get($param, 'name', ''),
- 'identity' => Arr::get($param, 'identity', ''),
- 'img' => !empty(Arr::get($param, 'img', '')) ? implode(',', Arr::get($param, 'img', '')) : '',
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- 'status' => $status
- ]);
- if ($param['mold'] == 2){
- StreamBusiness::addStream($param['user_data']['id'], $param['money'], streamType4, moldType5, moldTypefild5, $withdrawId);
- }
- StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType4, $param['mold'], moldTypefild($param['mold']), $withdrawId);
- } catch (\Throwable $exception) {
- throw new \Exception($exception->getMessage());
- }
- return true;
- }
- /** 提现流水
- * @param array $param
- * @return void
- */
- static public function stream(array $param)
- {
- try {
- $data = Db::table('wa_withdraw')
- ->where(function ($query) use ($param) {
- if (!empty(Arr::get($param, 'mold'))) {
- $query->where('type', $param['mold']);
- }
- })
- ->where('user_id', $param['user_data']['id'])
- ->orderByDesc('id')
- ->paginate(Arr::get($param, 'limit', 10), ['*'], 'page', Arr::get($param, 'page'))
- ->toArray();
- foreach ($data['data'] as $k => $v) {
- $data['data'][$k]->mold_name = moldType($v->type);
- }
- } catch (\Throwable $exception) {
- throw new \Exception($exception->getMessage());
- }
- return $data;
- }
- /** 转账至五行银行卡
- * @param array $param
- * @return void
- */
- static public function transfer_accounts(array $param)
- {
- try {
- $system = Db::table('wa_system')->first();
- if ($param['mold'] != 2) {
- throw new \Exception('转账至五行银行卡暂未开放!');
- }
- $param['mold'] = 5;
- /** @var $bankCard 银行卡 */
- $bankCard = Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->first();
- if (empty($bankCard)) {
- throw new \Exception('请先领取五行银行卡!');
- }
- /** @var $userIdentity 实名信息 */
- $userIdentity = Db::table('wa_user_identity')->where('uid', $param['user_data']['id'])->first();
- if (empty($userIdentity)) {
- throw new \Exception('请实名后,在转入!');
- }
- if (empty($system->conversion_value_cost)) {
- throw new \Exception('暂时不能转入!');
- }
- //五行银行卡余额变更
- $money = bcmul($param['money'], $system->conversion_value_cost, 2);
- Db::table('wa_user_social_cark')->where('user_id', $param['user_data']['id'])->increment('money', $money);
- //转账到五行银行卡余额
- StreamBusiness::addStream($param['user_data']['id'], $money, streamType14, moldType4, moldTypefild4);
- //减少股票账户
- StreamBusiness::delStream($param['user_data']['id'], $param['money'], streamType14, $param['mold'], moldTypefild($param['mold']), $param['user_data']['id']);
- } catch (\Throwable $exception) {
- throw new \Exception($exception->getMessage());
- }
- return true;
- }
- }
|