Takecash.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use Think\Db;
  5. /**
  6. * 提现申请
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Takecash extends Backend
  11. {
  12. /**
  13. * Takecash模型对象
  14. * @var \app\admin\model\Takecash
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Takecash;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("typeList", $this->model->getTypeList());
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //当前是否为关联查询
  39. $this->relationSearch = true;
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $list = $this->model
  49. ->with(['user','withdrawalconfig','userto'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('user')->visible(['nickname','mobile']);
  55. $row->getRelation('withdrawalconfig')->visible(['money']);
  56. $row->getRelation('userto')->visible(['nickname','mobile']);
  57. }
  58. $result = array("total" => $list->total(), "rows" => $list->items());
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 审核
  65. */
  66. public function audit(){
  67. $id = input('id');
  68. $info = Db::name('take_cash')
  69. ->where('id',$id)
  70. ->find();
  71. if ($this->request->isPost()) {
  72. if (!isset($info) || $info['status'] != 0) {
  73. $this->error('已经审核过了');
  74. }
  75. $status = input('status',0);
  76. $data = [
  77. 'status' => $status,
  78. 'auditremark' => input('auditremark'),
  79. 'audittime' => time(),
  80. 'updatetime' => time(),
  81. ];
  82. Db::startTrans();
  83. $rs = Db::name('take_cash')->where('id',$id)->update($data);
  84. if($rs === false){
  85. Db::rollback();
  86. $this->error('审核失败');
  87. }
  88. //tag任务赠送金币
  89. if($status == 1){
  90. $remark = '提现(成功)';
  91. Db::name('user_money_log')->where('table','take_cash')->where('table_id',$id)->update(['remark'=>$remark]);
  92. //系统消息
  93. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核已经审核通过');
  94. }elseif($status == 2){
  95. $remark = '提现(驳回)';
  96. Db::name('user_money_log')->where('table','take_cash')->where('table_id',$id)->update(['remark'=>$remark]);
  97. //还钱
  98. $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],0,'money',$info['number'],115,'提现被拒返回:'.$info['number'],'take_cash',$info['id']);
  99. if($wallet_rs['status'] === false){
  100. Db::rollback();
  101. $this->error($wallet_rs['msg']);
  102. }
  103. //系统消息
  104. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核审核不通过');
  105. }
  106. Db::commit();
  107. $this->success('审核完成');
  108. }
  109. $this->assign('row',$info);
  110. return $this->view->fetch();
  111. }
  112. //提现转账(新版2020-01-01)
  113. public function withdraw($info) {
  114. $data['out_biz_no'] = getMillisecond() . mt_rand(1, 1000); //商户订单号
  115. $data['trans_amount'] = $info['money']; //订单总金额,单位为元,精确到小数点后两位
  116. $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';//业务产品码,收发现金红包固定为:STD_RED_PACKET;单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD;单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD
  117. $data['biz_scene'] = 'DIRECT_TRANSFER'; //描述特定的业务场景,可传的参数如下:PERSONAL_COLLECTION:C2C现金红包-领红包;DIRECT_TRANSFER:B2C现金红包、单笔无密转账到支付宝/银行卡
  118. $data['order_title'] = '知音佣金发放'; //转账业务的标题,用于在支付宝用户的账单里显示
  119. $data['payee_info']['identity'] = $info['alipay_account'];//收款方支付宝id或支付宝账户
  120. /*if ($info['alipay_type'] == 1) { //支付宝账户
  121. $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
  122. //收款支付宝账号真实姓名, 不为空时支付宝会验证
  123. $data['payee_info']['name'] = $info['name'];
  124. } else { //支付宝id
  125. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  126. $data['payee_info']['name'] = '';
  127. }*/
  128. //支付宝id
  129. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  130. $data['payee_info']['name'] = '';
  131. //转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。
  132. $data['remark'] = '知音佣金发放';
  133. require_once("../extend/AliPay/AliPay.php");
  134. $alipay =new \AliPay();
  135. $result =$alipay->AliPayWithdraw($data);
  136. return $result;
  137. }
  138. }