UserExtract.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\finance;
  12. use app\admin\controller\AuthController;
  13. use service\FormBuilder as Form;
  14. use app\admin\model\user\UserExtract as UserExtractModel;
  15. use service\JsonService;
  16. use think\Request;
  17. use think\Url;
  18. /**
  19. * 用户提现管理
  20. * Class UserExtract
  21. * @package app\admin\controller\finance
  22. */
  23. class UserExtract extends AuthController
  24. {
  25. public function index()
  26. {
  27. $where = parent::getMore([
  28. ['status', ''],
  29. ['nickname', ''],
  30. ['extract_type', ''],
  31. ['nireid', ''],
  32. ], $this->request);
  33. $this->assign('where', $where);
  34. $this->assign(UserExtractModel::systemPage($where));
  35. return $this->fetch();
  36. }
  37. public function edit($id)
  38. {
  39. if (!$id) return $this->failed('数据不存在');
  40. $UserExtract = UserExtractModel::get($id);
  41. if (!$UserExtract) return JsonService::fail('数据不存在!');
  42. $f = array();
  43. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  44. $f[] = Form::number('extract_price', '提现金额', $UserExtract['extract_price'])->precision(2);
  45. if ($UserExtract['extract_type'] == 'alipay') {
  46. $f[] = Form::input('alipay_code', '支付宝账号', $UserExtract['alipay_code']);
  47. } else {
  48. $f[] = Form::input('bank_code', '银行卡号', $UserExtract['bank_code']);
  49. $f[] = Form::input('bank_address', '开户行', $UserExtract['bank_address']);
  50. }
  51. $f[] = Form::input('mark', '备注', $UserExtract['mark'])->type('textarea');
  52. $form = Form::make_post_form('编辑', $f, Url::build('update', array('id' => $id)));
  53. $this->assign(compact('form'));
  54. return $this->fetch('public/form-builder');
  55. }
  56. public function update(Request $request, $id)
  57. {
  58. $UserExtract = UserExtractModel::get($id);
  59. if (!$UserExtract) return JsonService::fail('数据不存在!');
  60. if ($UserExtract['extract_type'] == 'alipay') {
  61. $data = parent::postMore([
  62. 'real_name',
  63. 'mark',
  64. 'extract_price',
  65. 'alipay_code',
  66. ], $request);
  67. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  68. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  69. if (!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
  70. } else {
  71. $data = parent::postMore([
  72. 'real_name',
  73. 'extract_price',
  74. 'mark',
  75. 'bank_code',
  76. 'bank_address',
  77. ], $request);
  78. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  79. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  80. if (!$data['bank_code']) return JsonService::fail('请输入银行卡号');
  81. if (!$data['bank_address']) return JsonService::fail('请输入开户行');
  82. }
  83. if (!UserExtractModel::edit($data, $id))
  84. return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
  85. else
  86. return JsonService::successful('修改成功!');
  87. }
  88. public function fail(Request $request, $id)
  89. {
  90. if (!UserExtractModel::be(['id' => $id, 'status' => 0])) return JsonService::fail('操作记录不存在或状态错误!');
  91. $fail_msg = $request->post();
  92. $extract = UserExtractModel::get($id);
  93. if (!$extract) return JsonService::fail('操作记录不存!');
  94. if ($extract->status == 1) return JsonService::fail('已经提现,错误操作');
  95. if ($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝,请勿重复操作!');
  96. $res = UserExtractModel::changeFail($id, $fail_msg['message']);
  97. if ($res) {
  98. return JsonService::successful('操作成功!');
  99. } else {
  100. return JsonService::fail('操作失败!');
  101. }
  102. }
  103. public function succ($id)
  104. {
  105. if (!UserExtractModel::be(['id' => $id, 'status' => 0]))
  106. return JsonService::fail('操作记录不存在或状态错误!');
  107. UserExtractModel::beginTrans();
  108. $extract = UserExtractModel::get($id);
  109. if (!$extract) return JsonService::fail('操作记录不存!');
  110. if ($extract->status == 1) return JsonService::fail('您已提现,请勿重复提现!');
  111. if ($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝!');
  112. $res = UserExtractModel::changeSuccess($id);
  113. if ($res) {
  114. UserExtractModel::commitTrans();
  115. return JsonService::successful('操作成功!');
  116. } else {
  117. UserExtractModel::rollbackTrans();
  118. return JsonService::fail('操作失败!');
  119. }
  120. }
  121. }