Deposit.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\user\controller;
  15. use app\api\controller\Alipay;
  16. use app\common\model\UserWallet;
  17. use app\common\model\UserWithdrawLog;
  18. use EasyWeChat\Factory;
  19. use library\Controller;
  20. use think\Db;
  21. use function GuzzleHttp\Psr7\build_query;
  22. /**
  23. * 提现管理
  24. * Class Member
  25. * @package app\Member\controller
  26. */
  27. class Deposit extends Controller
  28. {
  29. /**
  30. * 绑定数据表
  31. * @var string
  32. */
  33. protected $table = 'UserWithdrawLog';
  34. /**
  35. * 提现列表
  36. * @auth true
  37. * @menu true
  38. * @throws \think\Exception
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. * @throws \think\exception\PDOException
  43. */
  44. public function index()
  45. {
  46. $this->search_url = strtolower($this->request->controller()).'/index_search';
  47. $this->title = '提现列表';
  48. $sel_where = [];
  49. $sel_where[] = ['w.is_deleted','=',0];
  50. $this->dep_type = ['','支付宝','银行卡','微信'];
  51. $this->status_arr = ['待审核','已审核','已到账','已拒绝','打款异常'];
  52. if($name = $this->request->get('name')) $sel_where[] =['w.user_name','=',$name];
  53. if($phone = $this->request->get('phone')) $sel_where[] =['m.phone','=',$phone];
  54. if($type = $this->request->get('type')) $sel_where[] =['w.type','=',$type];
  55. $query = $this->_query($this->table)
  56. ->alias('w')
  57. ->where($sel_where)
  58. ->field('w.*,m.headimg,m.openid,m.name as m_name')
  59. ->join('store_member m','m.id = w.user_id');
  60. $query->dateBetween('w.create_at')->order('w.id desc')->page();
  61. }
  62. /**
  63. * 数据列表处理
  64. * @auth true
  65. * @menu true
  66. * @param array $data
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. */
  71. protected function _index_page_filter(&$data)
  72. {
  73. foreach ($data as $k=>&$v){
  74. }
  75. }
  76. protected function _form_filter(&$data){
  77. if($this->request->isGet() && $this->request->action() == 'edit')
  78. {
  79. $this->user = Db::name('store_member')->field('headimg,name,phone')->find($data['user_id']);
  80. }
  81. // 提现审核
  82. if($this->request->isPost() && $this->request->action() == 'edit'){
  83. // 同意提现
  84. if($data['status'] == 1){
  85. $remit_success = 0;
  86. $withdrawal = UserWithdrawLog::where('id',$data['id'])->find()->toArray();
  87. if($withdrawal['status'] == 2) $this->error('已提现成功');
  88. if($withdrawal['status'] == 3) $this->error('余额已退回,无法进行退款操作');
  89. switch ($withdrawal['type'] ){
  90. case 1:// 提现到银行卡
  91. break;
  92. case 2:// 提现到支付宝
  93. $result = Alipay::ali_withdrawal($withdrawal['trade_no'],$withdrawal['account'],$withdrawal['card_no'],$withdrawal['user_name']);
  94. if($result) $remit_success = 1;
  95. break;
  96. case 3:// 提现到微信
  97. $app = Factory::payment(config('app.wx_pay'));
  98. $res = $app->transfer->toBalance([
  99. 'partner_trade_no' => $withdrawal['trade_no'], // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  100. 'openid' => $withdrawal['card_no'],
  101. 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名
  102. 're_user_name' => '', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  103. 'amount' =>$withdrawal['account'] * 100,// 企业付款金额,单位为分
  104. 'desc' =>'会员提现'//企业付款操作说明信息。必填
  105. ]);
  106. if(isset($res['err_code_des'])) $this->error($res['err_code_des']);
  107. $remit_success = 1;
  108. break;
  109. }
  110. if($remit_success == 1){
  111. UserWithdrawLog::where('id',$data['id'])->update(['status'=>2,'desc'=>$data['desc']]);
  112. $this->success('提现成功');
  113. }else{
  114. UserWithdrawLog::where('id',$data['id'])->update(['status'=>4,'desc'=>$data['desc']]);
  115. $this->error('打款失败');
  116. }
  117. }else if ($data['status'] ==3 ){
  118. // 拒绝提现 返回余额
  119. $withdrawal = UserWithdrawLog::where('id',$data['id'])->find()->toArray();
  120. if($withdrawal['status'] == 2) $this->error('已提现成功');
  121. if($withdrawal['status'] == 3) $this->error('余额已退回,无法进行退款操作');
  122. Db::startTrans();
  123. try {
  124. // 退还余额
  125. UserWallet::userMoneyChange($withdrawal['user_id'],$withdrawal['money'],'提现拒绝',11, 1,$withdrawal['id']);
  126. // 修改状态
  127. UserWithdrawLog::where('id',$data['id'])->update(['status'=>$data['status'],'desc'=>$data['desc']]);
  128. Db::commit();
  129. }catch (\Exception $e){
  130. Db::rollback();
  131. $this->error($e->getMessage());
  132. }
  133. $this->success('保存成功');
  134. }
  135. }
  136. }
  137. /**
  138. * 审核
  139. * @auth true
  140. * @menu true
  141. * @throws \think\Exception
  142. * @throws \think\db\exception\DataNotFoundException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. * @throws \think\exception\DbException
  145. * @throws \think\exception\PDOException
  146. */
  147. public function edit()
  148. {
  149. $this->title = '审核';
  150. $this->_form($this->table, 'form');
  151. }
  152. }