123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\user\controller;
- use app\api\controller\Alipay;
- use app\common\model\UserWallet;
- use app\common\model\UserWithdrawLog;
- use EasyWeChat\Factory;
- use library\Controller;
- use think\Db;
- use function GuzzleHttp\Psr7\build_query;
- /**
- * 提现管理
- * Class Member
- * @package app\Member\controller
- */
- class Deposit extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'UserWithdrawLog';
- /**
- * 提现列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->search_url = strtolower($this->request->controller()).'/index_search';
- $this->title = '提现列表';
- $sel_where = [];
- $sel_where[] = ['w.is_deleted','=',0];
- $this->dep_type = ['','支付宝','银行卡','微信'];
- $this->status_arr = ['待审核','已审核','已到账','已拒绝','打款异常'];
- if($name = $this->request->get('name')) $sel_where[] =['w.user_name','=',$name];
- if($phone = $this->request->get('phone')) $sel_where[] =['m.phone','=',$phone];
- if($type = $this->request->get('type')) $sel_where[] =['w.type','=',$type];
- $query = $this->_query($this->table)
- ->alias('w')
- ->where($sel_where)
- ->field('w.*,m.headimg,m.openid,m.name as m_name')
- ->join('store_member m','m.id = w.user_id');
- $query->dateBetween('w.create_at')->order('w.id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- foreach ($data as $k=>&$v){
- }
- }
- protected function _form_filter(&$data){
- if($this->request->isGet() && $this->request->action() == 'edit')
- {
- $this->user = Db::name('store_member')->field('headimg,name,phone')->find($data['user_id']);
- }
- // 提现审核
- if($this->request->isPost() && $this->request->action() == 'edit'){
- // 同意提现
- if($data['status'] == 1){
- $remit_success = 0;
- $withdrawal = UserWithdrawLog::where('id',$data['id'])->find()->toArray();
- if($withdrawal['status'] == 2) $this->error('已提现成功');
- if($withdrawal['status'] == 3) $this->error('余额已退回,无法进行退款操作');
- switch ($withdrawal['type'] ){
- case 1:// 提现到银行卡
- break;
- case 2:// 提现到支付宝
- $result = Alipay::ali_withdrawal($withdrawal['trade_no'],$withdrawal['account'],$withdrawal['card_no'],$withdrawal['user_name']);
- if($result) $remit_success = 1;
- break;
- case 3:// 提现到微信
- $app = Factory::payment(config('app.wx_pay'));
- $res = $app->transfer->toBalance([
- 'partner_trade_no' => $withdrawal['trade_no'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
- 'openid' => $withdrawal['card_no'],
- 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名
- 're_user_name' => '', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
- 'amount' =>$withdrawal['account'] * 100,// 企业付款金额,单位为分
- 'desc' =>'会员提现'//企业付款操作说明信息。必填
- ]);
- if(isset($res['err_code_des'])) $this->error($res['err_code_des']);
- $remit_success = 1;
- break;
- }
- if($remit_success == 1){
- UserWithdrawLog::where('id',$data['id'])->update(['status'=>2,'desc'=>$data['desc']]);
- $this->success('提现成功');
- }else{
- UserWithdrawLog::where('id',$data['id'])->update(['status'=>4,'desc'=>$data['desc']]);
- $this->error('打款失败');
- }
- }else if ($data['status'] ==3 ){
- // 拒绝提现 返回余额
- $withdrawal = UserWithdrawLog::where('id',$data['id'])->find()->toArray();
- if($withdrawal['status'] == 2) $this->error('已提现成功');
- if($withdrawal['status'] == 3) $this->error('余额已退回,无法进行退款操作');
- Db::startTrans();
- try {
- // 退还余额
- UserWallet::userMoneyChange($withdrawal['user_id'],$withdrawal['money'],'提现拒绝',11, 1,$withdrawal['id']);
- // 修改状态
- UserWithdrawLog::where('id',$data['id'])->update(['status'=>$data['status'],'desc'=>$data['desc']]);
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('保存成功');
- }
- }
- }
- /**
- * 审核
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '审核';
- $this->_form($this->table, 'form');
- }
- }
|