UserExtract.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. use crmeb\services\payment\PaymentService;
  15. use app\admin\model\user\UserExtract as UserExtractAdmin;
  16. /**
  17. * 用户提现管理
  18. * Class UserExtract
  19. * @package app\admin\controller\finance
  20. */
  21. class UserExtract extends AuthController
  22. {
  23. public function index()
  24. {
  25. $where = Util::getMore([
  26. ['status', ''],
  27. ['nickname', ''],
  28. ['extract_type', ''],
  29. ['nireid', ''],
  30. ['date', ''],
  31. ], $this->request);
  32. $limitTimeList = [
  33. 'today' => implode(' - ', [date('Y/m/d'), date('Y/m/d', strtotime('+1 day'))]),
  34. 'week' => implode(' - ', [
  35. date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
  36. date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
  37. ]),
  38. 'month' => implode(' - ', [date('Y/m') . '/01', date('Y/m') . '/' . date('t')]),
  39. 'quarter' => implode(' - ', [
  40. date('Y') . '/' . (ceil((date('n')) / 3) * 3 - 3 + 1) . '/01',
  41. date('Y') . '/' . (ceil((date('n')) / 3) * 3) . '/' . date('t', mktime(0, 0, 0, (ceil((date('n')) / 3) * 3), 1, date('Y')))
  42. ]),
  43. 'year' => implode(' - ', [
  44. date('Y') . '/01/01', date('Y/m/d', strtotime(date('Y') . '/01/01 + 1year -1 day'))
  45. ])
  46. ];
  47. $this->assign('where', $where);
  48. $this->assign('limitTimeList', $limitTimeList);
  49. $this->assign(UserExtractModel::extractStatistics());
  50. $this->assign(UserExtractModel::systemPage($where));
  51. return $this->fetch();
  52. }
  53. /**
  54. * 后台编辑提现信息
  55. * @param $id: user_extract 表 id
  56. */
  57. public function edit($id)
  58. {
  59. if (!$id) return $this->failed('数据不存在');
  60. $UserExtract = UserExtractModel::get($id);
  61. if (!$UserExtract) return JsonService::fail('数据不存在!');
  62. $f = array();
  63. $f[] = Form::input('real_name', '姓名', $UserExtract['real_name']);
  64. $f[] = Form::number('extract_price', '提现金额', $UserExtract['extract_price'])->precision(2);
  65. if ($UserExtract['extract_type'] == 'alipay') {
  66. $f[] = Form::input('alipay_code', '支付宝账号', $UserExtract['alipay_code']);
  67. } else if ($UserExtract['extract_type'] == 'weixin') {
  68. $f[] = Form::input('wechat', '微信号', $UserExtract['wechat']);
  69. } else {
  70. $f[] = Form::input('bank_code', '银行卡号', $UserExtract['bank_code']);
  71. $f[] = Form::input('bank_address', '开户行', $UserExtract['bank_address']);
  72. }
  73. $f[] = Form::input('mark', '备注', $UserExtract['mark'])->type('textarea');
  74. $form = Form::make_post_form('编辑', $f, Url::buildUrl('update', array('id' => $id)));
  75. $this->assign(compact('form'));
  76. return $this->fetch('public/form-builder');
  77. }
  78. /**
  79. * 处理 edit 提交的信息
  80. *
  81. * 根据提现通道的不一样,POST 的数据也不一样
  82. */
  83. public function update($id)
  84. {
  85. $UserExtract = UserExtractModel::get($id);
  86. if (!$UserExtract) return JsonService::fail('数据不存在!');
  87. if ($UserExtract['extract_type'] == 'alipay') {
  88. $data = Util::postMore([
  89. 'real_name',
  90. 'mark',
  91. 'extract_price',
  92. 'alipay_code',
  93. ]);
  94. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  95. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  96. if (!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
  97. } else if ($UserExtract['extract_type'] == 'weixin') {
  98. $data = Util::postMore([
  99. 'real_name',
  100. 'mark',
  101. 'extract_price',
  102. 'wechat',
  103. ]);
  104. // if(!$data['real_name']) return JsonService::fail('请输入姓名');
  105. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  106. if (!$data['wechat']) return JsonService::fail('请输入微信账号');
  107. } else {
  108. $data = Util::postMore([
  109. 'real_name',
  110. 'extract_price',
  111. 'mark',
  112. 'bank_code',
  113. 'bank_address',
  114. ]);
  115. if (!$data['real_name']) return JsonService::fail('请输入姓名');
  116. if ($data['extract_price'] <= -1) return JsonService::fail('请输入提现金额');
  117. if (!$data['bank_code']) return JsonService::fail('请输入银行卡号');
  118. if (!$data['bank_address']) return JsonService::fail('请输入开户行');
  119. }
  120. if (!UserExtractModel::edit($data, $id))
  121. return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
  122. else
  123. return JsonService::successful('修改成功!');
  124. }
  125. /**
  126. * @api {post} /fail 拒绝提现
  127. * @apiName ExtractFail
  128. * @apiGroup Finance
  129. *
  130. * @apiParam {int} id: user_extract id
  131. * @apiBody {string} fail_msg fail reason
  132. *
  133. * @apiSuccessExample:
  134. * {
  135. * "status": 200,
  136. * "msg": "操作成功"
  137. * }
  138. * @apiErrorExample:
  139. * {
  140. * "status": 400,
  141. * "msg": "error reason"
  142. * }
  143. */
  144. public function fail($id)
  145. {
  146. $fail_msg = request()->post();
  147. list($suc, $msg) = PaymentService::user_extract_reject($id, $fail_msg['message']);
  148. if ($suc) {
  149. return JsonService::successful('操作成功!');
  150. } else {
  151. return JsonService::fail($msg);
  152. }
  153. }
  154. /**
  155. * @api {post} /succ 提现通过 (后台操作)
  156. * @apiName ExtractSucc
  157. * @apiGroup Finance
  158. *
  159. * @apiParam {int} id user_extract id
  160. *
  161. * @apiSuccessExample:
  162. * {
  163. * "status": 200,
  164. * "msg": "操作成功"
  165. * }
  166. * @apiErrorExample:
  167. * {
  168. * "status": 400,
  169. * "msg": "error reason"
  170. * }
  171. */
  172. public function succ($id)
  173. {
  174. $extractInfo = UserExtractAdmin::get($id);
  175. if (!$extractInfo) {
  176. return JsonService::fail('记录不存在');
  177. }
  178. // API 转账
  179. list($suc, $ec, $es) = PaymentService::extract_by_api($extractInfo);
  180. if (!$suc) {
  181. return JsonService::fail($es);
  182. }
  183. list($suc, $msg) = PaymentService::user_extract_passed($extractInfo);
  184. if (!$suc) {
  185. return JsonService::fail($msg);
  186. } else {
  187. return JsonService::successful('操作成功');
  188. }
  189. }
  190. }