Takecash.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. //tag任务赠送金币
  85. if($status == 1){
  86. //扣钱
  87. $wallet_rs = model('wallet')->lockChangeAccountRemain($info['user_id'],0,'money',-$info['number'],15,'提现:'.$info['number'],'take_cash',$info['id']);
  88. if($wallet_rs['status'] === false){
  89. Db::rollback();
  90. $this->error($wallet_rs['msg']);
  91. }
  92. /*//上级返利
  93. if ($info['intro_uid'] && $info['intro_money'] > 0) {
  94. $wallet_rs = model('wallet')->lockChangeAccountRemain($info['intro_uid'],0,'money',$info['intro_money'],66,'邀请人提现奖励:'.$info['number'],'take_cash',$info['id']);
  95. if($wallet_rs['status'] === false){
  96. Db::rollback();
  97. $this->error($wallet_rs['msg']);
  98. }
  99. }
  100. //自动打款
  101. if ($info['type'] == 1) { //微信
  102. } elseif ($info['type'] == 2) { //支付宝
  103. $dakuanrs = $this->withdraw($info);
  104. if (!$dakuanrs) {
  105. Db::rollback();
  106. $this->error('打款失败');
  107. }
  108. }*/
  109. //系统消息
  110. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核已经审核通过');
  111. }elseif($status == 2){
  112. //系统消息
  113. $msg_id = \app\common\model\Message::addMessage($info['user_id'],'提现审核','提现审核审核不通过');
  114. }
  115. Db::commit();
  116. $this->success('审核完成');
  117. }
  118. $this->assign('row',$info);
  119. return $this->view->fetch();
  120. }
  121. //提现转账(新版2020-01-01)
  122. public function withdraw($info) {
  123. $data['out_biz_no'] = getMillisecond() . mt_rand(1, 1000); //商户订单号
  124. $data['trans_amount'] = $info['money']; //订单总金额,单位为元,精确到小数点后两位
  125. $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';//业务产品码,收发现金红包固定为:STD_RED_PACKET;单笔无密转账到支付宝账户固定为:TRANS_ACCOUNT_NO_PWD;单笔无密转账到银行卡固定为:TRANS_BANKCARD_NO_PWD
  126. $data['biz_scene'] = 'DIRECT_TRANSFER'; //描述特定的业务场景,可传的参数如下:PERSONAL_COLLECTION:C2C现金红包-领红包;DIRECT_TRANSFER:B2C现金红包、单笔无密转账到支付宝/银行卡
  127. $data['order_title'] = '知音佣金发放'; //转账业务的标题,用于在支付宝用户的账单里显示
  128. $data['payee_info']['identity'] = $info['alipay_account'];//收款方支付宝id或支付宝账户
  129. /*if ($info['alipay_type'] == 1) { //支付宝账户
  130. $data['payee_info']['identity_type'] = 'ALIPAY_LOGON_ID';
  131. //收款支付宝账号真实姓名, 不为空时支付宝会验证
  132. $data['payee_info']['name'] = $info['name'];
  133. } else { //支付宝id
  134. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  135. $data['payee_info']['name'] = '';
  136. }*/
  137. //支付宝id
  138. $data['payee_info']['identity_type'] = 'ALIPAY_USER_ID';
  139. $data['payee_info']['name'] = '';
  140. //转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。
  141. $data['remark'] = '知音佣金发放';
  142. require_once("../extend/AliPay/AliPay.php");
  143. $alipay =new \AliPay();
  144. $result =$alipay->AliPayWithdraw($data);
  145. return $result;
  146. }
  147. }