UserExtract.php 7.1 KB

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