field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name') ->leftJoin('user u', 'u.id = w.user_id') ->leftJoin('user_level ul', 'ul.id = u.level') ->where($where) ->page($get['page'], $get['limit']) ->order('w.id desc') ->select(); $count = Db::name('withdraw_apply w') ->field('w.*, u.nickname,u.avatar, u.sn as user_sn, u.mobile, ul.name as user_level_name') ->leftJoin('user u', 'u.id = w.user_id') ->leftJoin('user_level ul', 'ul.id = u.level') ->where($where) ->order('w.id desc') ->count(); foreach ($lists as &$item) { $item['type_text'] = Withdraw::getTypeDesc($item['type']); $item['status_text'] = Withdraw::getStatusDesc($item['status']); $item['avatar'] = UrlServer::getFileUrl($item['avatar']); $item['user_level_name'] = $item['user_level_name'] ? $item['user_level_name'] : '无等级'; $item['create_time'] = date('Y-m-d h:i:s', $item['create_time']); $item['payment_time'] = date('Y-m-d h:i:s', $item['payment_time']); } return ['count' => $count, 'lists' => $lists]; } //审核通过 public static function confirm($post) { $id = $post['id']; $withdraw = Db::name('withdraw_apply') ->where('id', $id) ->find(); // 判断提现单是否为待提现状态 1 if($withdraw['status'] != 1) { return [ 'code' => 0, 'msg' => '不是待提现申请单' ]; } //提现到钱包余额 if ($withdraw['type'] == Withdraw::TYPE_BALANCE){ $user = User::get($withdraw['user_id']); $user->user_money = ['inc', $withdraw['left_money']]; $user->save(); AccountLogLogic::AccountRecord( $withdraw['user_id'], $withdraw['left_money'], 1, AccountLog::withdraw_to_balance, '', $withdraw['id'], $withdraw['sn'] ); //更新提现申请单状态为提现成功 Db::name('withdraw_apply') ->where('id', $id) ->update(['status' => Withdraw::STATUS_SUCCESS, 'update_time' => time(), 'description'=>$post['description']]); return [ 'code' => 1, 'msg' => '提现至钱包余额成功' ]; } //提现到微信零钱 if($withdraw['type'] == Withdraw::TYPE_WECHAT_CHANGE) { // 先更新审核备注 Db::name('withdraw_apply') ->where('id', $id) ->update(['update_time' => time(),'description'=>$post['description']]); return WechatCorporatePaymentLogic::pay($withdraw); } //提现到微信收款码、支付收款码 if($withdraw['type'] == Withdraw::TYPE_WECHAT_CODE || $withdraw['type'] == Withdraw::TYPE_ALI_CODE || Withdraw::TYPE_BANK) { // 直接标识为提现中状态 Db::name('withdraw_apply') ->where('id', $id) ->update(['status' => Withdraw::STATUS_ING, 'update_time' => time(),'description'=>$post['description']]); return [ 'code' => 1, 'msg' => '审核通过,提现中' ]; } } //审核拒绝 public static function refuse($post) { Db::startTrans(); try{ $withdraw_apply = WithdrawApply::where('id', $post['id'])->find(); $withdraw_apply->status = Withdraw::STATUS_FAIL; // 提现失败 $withdraw_apply->description = $post['description']; $withdraw_apply->update_time = time(); $withdraw_apply->save(); //拒绝提现,回退佣金 $user = User::get($withdraw_apply['user_id']); $user->earnings = ['inc', $withdraw_apply['money']]; $user->save(); //增加佣金变动记录 AccountLogLogic::AccountRecord( $withdraw_apply['user_id'], $withdraw_apply['money'], 1, AccountLog::withdraw_back_earnings, '', $withdraw_apply['id'], $withdraw_apply['sn'] ); Db::commit(); } catch (Exception $e){ Db::rollback(); } } /** * 提现失败 */ public static function withdrawFailed($id) { $withdraw_apply = WithdrawApply::where('id', $id)->find(); $withdraw_apply->status = Withdraw::STATUS_FAIL; // 提现失败 $withdraw_apply->update_time = time(); $withdraw_apply->save(); //拒绝提现,回退佣金 $user = User::get($withdraw_apply['user_id']); $user->earnings = ['inc', $withdraw_apply['money']]; $user->save(); //增加佣金变动记录 AccountLogLogic::AccountRecord( $withdraw_apply['user_id'], $withdraw_apply['money'], 1, AccountLog::withdraw_back_earnings, '', $withdraw_apply['id'], $withdraw_apply['sn'] ); } /** * 提现详情 */ public static function detail($id) { $detail = Db::name('withdraw_apply w') ->field('w.*,u.sn as user_sn, u.nickname, u.mobile') ->leftJoin('user u', 'u.id=w.user_id') ->where('w.id', $id) ->find(); $detail['typeDesc'] = Withdraw::getTypeDesc($detail['type']); $detail['statusDesc'] = Withdraw::getStatusDesc($detail['status']); $detail['create_time'] = Date('Y-m-d h:i:s', $detail['create_time']); $detail['payment_time'] = Date('Y-m-d h:i:s', $detail['payment_time']); $detail['transfer_time'] = $detail['transfer_time'] ? Date('Y-m-d h:i:s', $detail['transfer_time']) : ''; return $detail; } /** * 提现结果查询 */ public static function search($id) { $withdraw = Db::name('withdraw_apply') ->where('id', $id) ->find(); // 判断提现单是否为提现中状态 2 且 提现方式为 微信零钱 2 if($withdraw['status'] == 2 && $withdraw['type'] == 2) { return WechatCorporatePaymentLogic::search($withdraw); }else{ return [ 'code' => 0, 'msg' => '不是提现中的微信零钱申请单,无法查询' ]; } } /** * 转账失败 */ public static function transferFail($post) { if(empty($post['transfer_description'])) { return [ 'code' => 0, 'msg' => '请填写转账说明' ]; } // 标识提现失败 Db::name('withdraw_apply')->where('id', $post['id'])->update([ 'status' => 4, // 提现失败 'transfer_description' => $post['transfer_description'], 'update_time' => time() ]); $withdraw_apply = Db::name('withdraw_apply')->where('id', $post['id'])->find(); // 退回佣金 $user = User::get($withdraw_apply['user_id']); $user->earnings = ['inc', $withdraw_apply['money']]; $user->save(); //增加佣金变动记录 AccountLogLogic::AccountRecord( $withdraw_apply['user_id'], $withdraw_apply['money'], 1, AccountLog::withdraw_back_earnings, '', $withdraw_apply['id'], $withdraw_apply['sn'] ); return [ 'code' => 1, 'msg' => '转账失败,提现金额已退回佣金账户' ]; } /** * 转账成功 */ public static function transferSuccess($post) { if(empty($post['transfer_voucher'])) { return [ 'code' => 0, 'msg' => '请上传转账凭证' ]; } $post['transfer_voucher'] = UrlServer::getFileUrl($post['transfer_voucher']); if(empty($post['transfer_description'])) { return [ 'code' => 0, 'msg' => '请填写转账说明' ]; } // 标识提现成功 Db::name('withdraw_apply')->where('id', $post['id'])->update([ 'status' => 3, // 提现成功 'transfer_voucher' => $post['transfer_voucher'], 'transfer_description' => $post['transfer_description'], 'update_time' => time(), 'transfer_time' => time() ]); return [ 'code' => 1, 'msg' => '转账成功' ]; } }