UserExtract.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lianghuan
  5. * Date: 2018-03-03
  6. * Time: 16:37
  7. */
  8. namespace app\admin\controller\finance;
  9. use app\admin\controller\AuthController;
  10. use think\facade\Route as Url;
  11. use crmeb\services\JsonService;
  12. use app\admin\model\user\UserExtract as UserExtractModel;
  13. use crmeb\services\{UtilService as Util, FormBuilder as Form};
  14. /**
  15. * 用户提现管理
  16. * Class UserExtract
  17. * @package app\admin\controller\finance
  18. */
  19. class UserExtract extends AuthController
  20. {
  21. public function index()
  22. {
  23. $where = Util::getMore([
  24. ['status', ''],
  25. ['nickname', ''],
  26. ['extract_type', ''],
  27. ['nireid', ''],
  28. ['date', ''],
  29. ], $this->request);
  30. $limitTimeList = [
  31. 'today' => implode(' - ', [date('Y/m/d'), date('Y/m/d', strtotime('+1 day'))]),
  32. 'week' => implode(' - ', [
  33. date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
  34. date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
  35. ]),
  36. 'month' => implode(' - ', [date('Y/m') . '/01', date('Y/m') . '/' . date('t')]),
  37. 'quarter' => implode(' - ', [
  38. date('Y') . '/' . (ceil((date('n')) / 3) * 3 - 3 + 1) . '/01',
  39. date('Y') . '/' . (ceil((date('n')) / 3) * 3) . '/' . date('t', mktime(0, 0, 0, (ceil((date('n')) / 3) * 3), 1, date('Y')))
  40. ]),
  41. 'year' => implode(' - ', [
  42. date('Y') . '/01/01', date('Y/m/d', strtotime(date('Y') . '/01/01 + 1year -1 day'))
  43. ])
  44. ];
  45. $this->assign('where', $where);
  46. $this->assign('limitTimeList', $limitTimeList);
  47. $this->assign(UserExtractModel::extractStatistics());
  48. $this->assign(UserExtractModel::systemPage($where));
  49. return $this->fetch();
  50. }
  51. public function edit($id)
  52. {
  53. if (!$id) return $this->failed('数据不存在');
  54. $UserExtract = UserExtractModel::get($id);
  55. if (!$UserExtract) return JsonService::fail('数据不存在!');
  56. $f = array();
  57. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  58. $f[] = Form::number('extract_price', '提现金额', $UserExtract['extract_price'])->precision(2);
  59. if ($UserExtract['extract_type'] == 'alipay') {
  60. $f[] = Form::input('alipay_code', '支付宝账号', $UserExtract['alipay_code']);
  61. } else if ($UserExtract['extract_type'] == 'weixin') {
  62. // $f[] = Form::input('wechat', '微信号', $UserExtract['wechat']);
  63. } else {
  64. $f[] = Form::input('bank_code', '银行卡号', $UserExtract['bank_code']);
  65. $f[] = Form::input('bank_address', '开户行', $UserExtract['bank_address']);
  66. }
  67. $f[] = Form::input('mark', '备注', $UserExtract['mark'])->type('textarea');
  68. $form = Form::make_post_form('编辑', $f, Url::buildUrl('update', array('id' => $id)));
  69. $this->assign(compact('form'));
  70. return $this->fetch('public/form-builder');
  71. }
  72. public function update($id)
  73. {
  74. $UserExtract = UserExtractModel::get($id);
  75. if (!$UserExtract) return JsonService::fail('数据不存在!');
  76. if ($UserExtract['extract_type'] == 'alipay') {
  77. $data = Util::postMore([
  78. 'real_name',
  79. 'mark',
  80. 'extract_price',
  81. 'alipay_code',
  82. ]);
  83. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  84. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  85. if (!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
  86. } else if ($UserExtract['extract_type'] == 'weixin') {
  87. $data = Util::postMore([
  88. 'real_name',
  89. 'mark',
  90. 'extract_price',
  91. // 'wechat',
  92. ]);
  93. // if(!$data['real_name']) return JsonService::fail('请输入姓名');
  94. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  95. // if (!$data['wechat']) return JsonService::fail('请输入微信账号');
  96. } else {
  97. $data = Util::postMore([
  98. 'real_name',
  99. 'extract_price',
  100. 'mark',
  101. 'bank_code',
  102. 'bank_address',
  103. ]);
  104. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  105. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  106. if (!$data['bank_code']) return JsonService::fail('请输入银行卡号');
  107. if (!$data['bank_address']) return JsonService::fail('请输入开户行');
  108. }
  109. if (!UserExtractModel::edit($data, $id))
  110. return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
  111. else
  112. return JsonService::successful('修改成功!');
  113. }
  114. public function fail($id)
  115. {
  116. if (!UserExtractModel::be(['id' => $id, 'status' => 0])) return JsonService::fail('操作记录不存在或状态错误!');
  117. $fail_msg = request()->post();
  118. $extract = UserExtractModel::get($id);
  119. if (!$extract) return JsonService::fail('操作记录不存在!');
  120. if ($extract->status == 1) return JsonService::fail('已经提现,错误操作');
  121. if ($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝,请勿重复操作!');
  122. $res = UserExtractModel::changeFail($id, $fail_msg['message']);
  123. if ($res) {
  124. return JsonService::successful('操作成功!');
  125. } else {
  126. return JsonService::fail('操作失败!');
  127. }
  128. }
  129. public function succ($id)
  130. {
  131. if (!UserExtractModel::be(['id' => $id, 'status' => 0]))
  132. return JsonService::fail('操作记录不存在或状态错误!');
  133. UserExtractModel::beginTrans();
  134. $extract = UserExtractModel::get($id);
  135. if (!$extract) return JsonService::fail('操作记录不存!');
  136. if ($extract->status == 1) return JsonService::fail('您已提现,请勿重复提现!');
  137. if ($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝!');
  138. $res = UserExtractModel::changeSuccess($id);
  139. if ($res) {
  140. UserExtractModel::commitTrans();
  141. return JsonService::successful('操作成功!');
  142. } else {
  143. UserExtractModel::rollbackTrans();
  144. return JsonService::fail('操作失败!');
  145. }
  146. }
  147. }