| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- <?php
- /**
- * 提现
- */
- namespace app\admin\controller\withdraw;
- use alipay\AopCertClient;
- use alipay\request\AlipayFundTransUniTransferRequest;
- use app\admin\logic\WithdrawLogLogic;
- use app\admin\model\dao\WithdrawLog;
- use app\admin\traits\Curd;
- use app\api\services\AliPayServices;
- use app\api\services\ThirdPayServices;
- use app\validate\admin\withdraw\withdraw\ReturnServiceMoney;
- use EasyAdmin\annotation\ControllerAnnotation;
- use EasyAdmin\annotation\NodeAnotation;
- use app\common\controller\AdminController;
- use app\common\model\WithDrawLogModel;
- use think\App;
- use think\Exception;
- use think\exception\ValidateException;
- use think\facade\Db;
- /**
- * Class Admin
- * @package app\admin\controller\withdraw
- * @ControllerAnnotation(title="提现管理处理")
- */
- class Withdraw extends AdminController
- {
- public function __construct(App $app, WithDrawLogModel $model)
- {
- parent::__construct($app);
- $this->model = $model;
- }
- use Curd;
- /**
- * @NodeAnotation(title="列表")
- */
- public function index()
- {
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- foreach ($where as $key => &$val) {
- if ($val[0] == 'status') {
- $where[$key][0] = 'w.status';
- }
- }
- $count = $this->model
- // ->withJoin('user', 'INNER')
- ->where($this->user_map)
- ->where($where)
- ->count();
- $list = $this->model
- ->alias('w')
- ->leftJoin('user u', 'u.id = w.uid')
- // ->withJoin('user', 'INNER')
- ->where($this->user_map)
- ->where($where)
- ->field('w.*,u.path,u.user_type,u.luzi_money')
- ->page($page, $limit)
- ->order($this->sort)
- ->select();
- $withdrawLog = new WithdrawLogLogic();
- foreach ($list as $key => &$val) {
- // 老刘下级 13824334135 uid 5344367
- // 郑跃兵 17888779318 uid 5344369,13866400965 uid 5344368
- // 大飞 19805553599 uid 5344633 ,18682271568 uid 5344640
- //
- // if ($val['user_type'] == 10){
- // $val['tips_text'] = '潘总号';
- // }else{
- // $val['tips_text'] = '其他线';
- // }
- // $val['tips_text'] = '其他线';
- //
- // if (strpos($val['path'], '5344367') !== false || $val['uid'] == 5344367){
- // $val['tips_text'] = '老刘下级';
- // }
- //
- // if ((strpos($val['path'], '5344633') !== false || $val['uid'] == 5344633) || (strpos($val['path'], '5344640') !== false || $val['uid'] == 5344640)){
- // $val['tips_text'] = '大飞下级';
- // }elseif ((strpos($val['path'], '5344369') !== false || $val['uid'] == 5344369) || (strpos($val['path'], '5344368') !== false || $val['uid'] == 5344368)){
- // $val['tips_text'] = '郑跃兵下级';
- // }
- // if (strpos($val['path'], '7493433') !== false){
- // $val['tips_text'] = '心态下级';
- // }
- //
- if (strpos($val['path'], '7493466') !== false) {
- $val['tips_text'] = '郑下级';
- }
- if ($val['luzi_money'] > 0) {
- $val['tips_text'] = '撸子标记,不要提现';
- } else {
- $val['tips_text'] = '';
- }
- $val['is_show'] = $withdrawLog->isShowReturnServiceMoney($val['id']);
- }
- // tips_text
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="取消提现")
- */
- // public function cancel ($id)
- // {
- // $row = $this->model->where('id', $id)->where('status', 'in', '0')->find();
- // empty($row) && $this->error('取消失败');
- // $row->status = 3;
- // Db::startTrans();
- // try {
- // edit_user_money(9, $row['uid'], $row['apply_money']);
- // $row->save();
- // Db::commit();
- // } catch (\Exception $e) {
- // Db::rollback();
- // $this->error('取消失败');
- // }
- // $this->success('取消成功');
- // }
- /**
- * @NodeAnotation(title="提现失败")
- */
- public function withdrawerror($id)
- {
- if ($this->request->isPost()) {
- $post = $this->request->post();
- $row = $this->model->where('id', $id)->where('status', 'in', '0')->find();
- empty($row) && $this->error('取消失败');
- $row->status = 3;
- $row->fail_log = $post['error_text'];
- $is_backsx = $post['is_backsx'];
- $row->is_backsx = $is_backsx;
- Db::startTrans();
- try {
- if ($is_backsx == 1) {
- edit_user_money(10, $row['uid'], $row['apply_money']);
- } else {
- edit_user_money(10, $row['uid'], $row['practical_money']);
- }
- Db::name('user')->where('id', $row['uid'])->dec('total_withdraw', $row['apply_money'])->update();
- // Db::name('user')->whereIn('id', $row['path'])->dec('total_team_withdraw', $row['apply_money'])->update();
- // Db::name('user')->whereIn('id', $row['uid'])->dec('total_team_withdraw', $row['apply_money'])->update();
- $row->save();
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error('取消失败' . $e->getMessage());
- }
- $this->success('取消成功');
- }
- //
- // if ($this->request->isPost()) {
- // $row = $this->model->where('id', $id)->where('status', 'in', '0')->find();
- // empty($row) && $this->error('取消失败');
- // if ($row['status'] != 1){
- // $this->error('状态错误,请刷新数据');
- // }
- //
- // $this->model->startTrans();
- // try {
- // $this->model->where('id', $post['id'])->save(['status'=>3,'error_text'=>$error_text, 'is_backsx'=>$is_backsx]);
- // if ($is_backsx == 1){
- // edit_user_xz(15, $order_info['uid'], $order_info['xz_num']+$order_info['shouxu'], $order_info['hf_ordersn'], $order_info['shouxu']);
- // edit_user_couponnum(5, $order_info['uid'], $order_info['price']/10);
- // }else{
- // edit_user_xz(15, $order_info['uid'], $order_info['xz_num'], $order_info['hf_ordersn'], 0);
- // edit_user_couponnum(5, $order_info['uid'], $order_info['price']/10);
- // }
- //
- // $this->model->commit();
- // } catch (\Exception $e) {
- // $this->model->rollback();
- // $this->error('失败'.$e->getMessage());
- // }
- // $this->success('成功');
- // }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="执行提现")
- */
- public function tx($id)
- {
- // if (in_array(env('APP.CUR_SYS_PARAMS'), [1, 2])){
- // $this->error('错误');
- // }
- $info = $this->model->where('id', $id)->where('status', 0)->find();
- if (empty($info))
- $this->error('提现记录不存在');
- $user = Db::name('user')->findOrEmpty(['id' => $info['uid']]);
- if (empty($user) || $user['status'] != 1)
- $this->error('用户不存在或已被禁用');
- if ($user['luzi_money'] > 0) {
- $this->error('撸子账号 联系技术处理');
- }
- // $this->error('通道错误,失败');
- // if ($user['is_auth'] != 1)
- // $this->error('该用户还未实名认证');
- Db::name('user')->whereIn('id', $user['path'])->inc('total_team_withdraw', $info['apply_money'])->update();
- Db::name('user')->whereIn('id', $user['id'])->inc('total_team_withdraw', $info['apply_money'])->update();
- // 支付宝提现
- if ($info['channel'] == 1) {
- // 电科支付宝提现代付
- if (false) {
- Db::startTrans();
- try {
- $interface_url = 'http://1.14.197.47/proxy/pay/fetch'; //正式
- $out_trade_no = createdOrderWithdrawSn($info['uid']);
- $params = [
- 'appId' => 'diankef',
- 'version' => '1.0',
- 'nonceStr' => nonce_str(15),
- 'amount' => intval($info['practical_money'] * 100),
- 'orderId' => $out_trade_no,
- 'accountName' => $info['zfb_name'],
- 'accountNo' => $info['zfb_number'],
- 'bankName' => '网商银行',
- 'asyncNotifyUrl' => env('PAYSQZ.PAYBACK_DAIFU_ZFB_NEWURL'),
- 'quick' => 1,
- 'subject' => '余额提现'
- ];
- ksort($params);
- $services = new ThirdPayServices();
- $params['sign'] = $services->diankesigndf($params);
- // 提交确定支付
- sr_log('确认提交提现' . json_encode($params));
- $result = curlPost($interface_url, $params);
- sr_log('result:' . $result);
- $res = json_decode($result);
- if (isset($res->status) && $res->status == 9) {
- Db::name('withdraw_log')->where('id', $id)->update(['status' => 4, 'out_biz_no' => $out_trade_no, 'update_at' => date('Y-m-d H:i:s', time()), 'final_transfer_type' => 1]);
- } else {
- sr_throw('支付错误,请联系客服');
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- Db::name('withdraw_log')->where('id', $id)->update(['status' => 1, 'out_biz_no' => '1111', 'update_at' => date('Y-m-d H:i:s', time()), 'final_transfer_type' => 1]);
- $this->success('提现成功');
- // try {
- ////
- // /** 初始化 **/
- // $aop = new AopCertClient();
- // $pay_info = Db::name('pay_config')->where('channel', 1)->where('status', 1)->find();
- // /** 支付宝网关 **/
- // $aop -> gatewayUrl = "https://openapi.alipay.com/gateway.do";
- //
- // /** 应用id,如何获取请参考:https://opensupport.alipay.com/support/helpcenter/190/201602493024 **/
- // $aop -> appId = $pay_info['app_id'];
- //
- // /** 密钥格式为pkcs1,如何获取私钥请参考:https://opensupport.alipay.com/support/helpcenter/207/201602471154?ant_source=antsupport **/
- // $aop -> rsaPrivateKey = $pay_info['private_key'];
- //
- // /** 应用公钥证书路径,下载后保存位置的绝对路径 **/
- // $appCertPath = $pay_info['app_cert_path'];
- //
- // /** 支付宝公钥证书路径,下载后保存位置的绝对路径 **/
- // $alipayCertPath = $pay_info['pay_cert_path'];
- //
- // /** 支付宝根证书路径,下载后保存位置的绝对路径 **/
- // $rootCertPath = $pay_info['pay_root_cert'];
- //
- // /** 设置签名类型 **/
- // $aop -> signType= "RSA2";
- //
- // /** 设置请求格式,固定值json **/
- // $aop -> format = "json";
- //
- // /** 设置编码格式 **/
- // $aop -> charset= "utf-8";
- //
- // /** 调用getPublicKey从支付宝公钥证书中提取公钥 **/
- // $aop -> alipayrsaPublicKey = $aop -> getPublicKey($alipayCertPath);
- //
- // /** 是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内 **/
- // $aop -> isCheckAlipayPublicCert = true;
- //
- // /** 调用getCertSN获取证书序列号 **/
- // $aop -> appCertSN = $aop -> getCertSN($appCertPath);
- //
- // /** 调用getRootCertSN获取支付宝根证书序列号 **/
- // $aop -> alipayRootCertSN = $aop -> getRootCertSN($rootCertPath);
- //
- // /** 实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.fund.trans.uni.transfer(单笔转账接口) **/
- // $request = new AlipayFundTransUniTransferRequest();
- // $out_biz_no = time() . rand(10000, 99999) . $info['uid'];
- // /** 设置业务参数,具体接口参数传值以文档说明为准:https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.uni.transfer/ **/
- // $request -> setBizContent("{".
- //
- // /** 商户端的唯一订单号,对于同一笔转账请求,商户需保证该订单号唯一 **/
- // "\"out_biz_no\":\"".$out_biz_no."\",".
- //
- // /** 转账金额,TRANS_ACCOUNT_NO_PWD产品取值最低0.1 **/
- // "\"trans_amount\":\"".$info['practical_money']."\",".
- //
- // /** 产品码,单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD **/
- // "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",".
- //
- // /** 场景码,单笔无密转账到支付宝账户固定为:DIRECT_TRANSFER **/
- // "\"biz_scene\":\"DIRECT_TRANSFER\",".
- //
- // /** 转账业务的标题,用于在支付宝用户的账单里显示 **/
- // "\"order_title\":\"提现\",".
- //
- // /** 收款方信息 **/
- // "\"payee_info\":{".
- //
- // /** 参与方的唯一标识,收款支付宝账号或者支付宝吧账号唯一会员ID **/
- // "\"identity\":\"".$info['zfb_number']."\",".
- //
- // /** 参与方的标识类型:ALIPAY_USER_ID 支付宝的会员ID **/
- // "\"identity_type\":\"ALIPAY_LOGON_ID\",".
- //
- // /** 参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填 **/
- // "\"name\":\"".$info['zfb_name']."\"".
- // "},".
- //
- // /** 业务备注 **/
- // "\"remark\":\"单笔转账\"".
- //
- // "}");
- //
- // $result = $aop -> execute($request);
- //
- //// sr_log('支付宝体现返回'.json_encode($result));
- //
- //
- // /** 获取接口调用结果,如果调用失败,可根据返回错误信息到该文档寻找排查方案:https://opensupport.alipay.com/support/helpcenter/114 **/
- //// $res = json_encode($result, JSON_UNESCAPED_UNICODE);
- //// $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- //// $resultCode = $result->{$responseNode}->code;
- //
- // if (isset($result->alipay_fund_trans_uni_transfer_response->code) && $result->alipay_fund_trans_uni_transfer_response->code == 10000) {
- // } else {
- // Db::name('withdraw_log')->where('id', $id)->update(['fail_log' => $result->alipay_fund_trans_uni_transfer_response->sub_msg, 'status' => 3]);
- // edit_user_money(9, $info['uid'], $info['apply_money']);
- // $this->success('提现失败');
- // }
- //// sr_log(json_encode($res));
- //// $rpm = $this->apiRequest('adminWithdrawal', compact('id'));
- //// if ($rpm['code'] != 200)
- //// $this->error($rpm['msg']);
- // } catch (Exception $e) {
- // sr_log($e->getMessage());
- // $this->error('提现失败');
- // }
- } else {
- $info->status = 1;
- $info->update_at = date('Y-m-d H:i:s', time());
- $info->final_transfer_type = 3;
- $info->save();
- }
- // $transferstatus = get_config(2, 'TRANSFERSTATUS'); // 获取支付设置
- // if ($transferstatus == 1 || $transferstatus == 2) { // 自动转账
- // try {
- // $rpm = $this->apiRequest('adminWithdrawal', compact('id'));
- // if ($rpm['code'] != 200)
- // $this->error($rpm['msg']);
- // } catch (\Exception $e) {
- // $this->error('提现失败');
- // }
- // } else { // 手动执行
- // $info->status = 1;
- // $info->update_at = date('Y-m-d H:i:s', time());
- // $info->final_transfer_type = 3;
- // $info->save();
- // }
- $this->success('提现成功');
- }
- /**
- * @NodeAnotation(title="导出")
- */
- public function export()
- {
- list($page, $limit, $where) = $this->buildTableParames();
- $tableName = $this->model->getName();
- $tableName = CommonTool::humpToLine(lcfirst($tableName));
- $prefix = config('database.connections.mysql.prefix');
- $dbList = Db::query("show full columns from {$prefix}{$tableName}");
- $header = [];
- foreach ($dbList as $vo) {
- $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
- if (!in_array($vo['Field'], $this->noExportFields)) {
- $header[] = [$comment, $vo['Field']];
- }
- }
- $list = $this->model
- ->where($where)
- ->withJoin('user', 'INNER')
- ->where($where)
- ->limit(100000)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- $fileName = time();
- return Excel::exportData($list, $header, $fileName, 'xlsx');
- }
- /**
- * @NodeAnotation(title="提现数据")
- */
- public function withdrawdata()
- {
- $tx_success = Db::name('withdraw_log')->where('status', 1)->sum('practical_money');
- $this->assign('tx_success', $tx_success);
- $tx = Db::name('withdraw_log')->where('status', 0)->sum('practical_money');
- $this->assign('tx', $tx);
- return $this->fetch();
- }
- /**
- * 退还手续费
- * @return mixed
- */
- public function returnservicemoney()
- {
- $id = $this->request['id'];
- $withdrawLog = new WithdrawLogLogic();
- if ($this->request->isPost()) {
- $post = $this->request->post();
- try {
- validate(ReturnServiceMoney::class)->check($post);
- } catch (ValidateException $e) {
- $this->error($e->getMessage());
- }
- $result = $withdrawLog->returnServiceMoney($post);
- if ($result !== true) {
- $this->error($result);
- }
- $this->success('成功');
- }
- $withdrawLog->getWithdrawLog($id);
- $this->assign('info', $withdrawLog);
- return $this->fetch();
- }
- }
|