Transfer.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\data\controller\user;
  3. use app\data\model\DataUser;
  4. use app\data\model\DataUserTransfer;
  5. use app\data\service\UserAdminService;
  6. use app\data\service\UserTransferService;
  7. use think\admin\Controller;
  8. use think\admin\extend\CodeExtend;
  9. use think\admin\service\AdminService;
  10. /**
  11. * 用户提现管理
  12. * Class Transfer
  13. * @package app\data\controller\user
  14. */
  15. class Transfer extends Controller
  16. {
  17. /**
  18. * 提现转账方案
  19. * @var array
  20. */
  21. protected $types = [];
  22. protected function initialize()
  23. {
  24. $this->types = UserTransferService::instance()->types();
  25. }
  26. /**
  27. * 用户提现配置
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function config()
  33. {
  34. $this->skey = 'TransferRule';
  35. $this->title = '用户提现配置';
  36. $this->_sysdata();
  37. }
  38. /**
  39. * 微信转账配置
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function payment()
  45. {
  46. $this->skey = 'TransferWxpay';
  47. $this->title = '微信提现配置';
  48. $this->_sysdata();
  49. }
  50. /**
  51. * 配置数据处理
  52. * @param string $tpl 模板文件
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. private function _sysdata(string $tpl = '')
  58. {
  59. if ($this->request->isGet()) {
  60. $this->data = sysdata($this->skey);
  61. $this->fetch($tpl);
  62. } else {
  63. sysdata($this->skey, $this->request->post());
  64. $this->success('配置修改成功');
  65. }
  66. }
  67. /**
  68. * 用户提现管理
  69. * @menu true
  70. * @auth true
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function index()
  76. {
  77. $this->title = '用户提现管理';
  78. $this->transfer = UserTransferService::amount(0);
  79. // 创建查询对象
  80. $query = DataUserTransfer::mQuery()->order('id desc');
  81. // 用户条件搜索
  82. $db = DataUser::mQuery()->like('phone,username|nickname#nickname')->db();
  83. if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
  84. // 数据列表处理
  85. $query->equal('type,status')->dateBetween('create_at')->page();
  86. }
  87. /**
  88. * 数据列表处理
  89. * @param array $data
  90. */
  91. protected function _page_filter(array &$data)
  92. {
  93. UserAdminService::buildByUid($data);
  94. foreach ($data as &$vo) {
  95. $vo['type_name'] = UserTransferService::instance()->types($vo['type']);
  96. }
  97. }
  98. /**
  99. * 提现审核操作
  100. * @auth true
  101. * @throws \think\db\exception\DataNotFoundException
  102. * @throws \think\db\exception\DbException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. */
  105. public function auditStatus()
  106. {
  107. $this->_audit();
  108. }
  109. /**
  110. * 提现打款操作
  111. * @auth true
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\DbException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. */
  116. public function auditPayment()
  117. {
  118. $this->_audit();
  119. }
  120. /**
  121. * 提现审核打款
  122. * @auth true
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\DbException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. */
  127. private function _audit()
  128. {
  129. if ($this->request->isGet()) {
  130. DataUserTransfer::mForm('audit', 'code');
  131. } else {
  132. $data = $this->_vali([
  133. 'code.require' => '打款单号不能为空!',
  134. 'status.require' => '交易审核操作类型!',
  135. 'status.in:0,1,2,3,4' => '交易审核操作类型!',
  136. 'remark.default' => '',
  137. ]);
  138. $map = ['code' => $data['code']];
  139. $find = DataUserTransfer::mk()->where($map)->find();
  140. if (empty($find)) $this->error('不允许操作审核!');
  141. // 提现状态(0已拒绝, 1待审核, 2已审核, 3打款中, 4已打款, 5已收款)
  142. if (in_array($data['status'], [0, 1, 2, 3])) {
  143. $data['last_at'] = date('Y-m-d H:i:s');
  144. } elseif ($data['status'] == 4) {
  145. $data['trade_no'] = CodeExtend::uniqidDate(20);
  146. $data['trade_time'] = date('Y-m-d H:i:s');
  147. $data['change_time'] = date('Y-m-d H:i:s');
  148. $data['change_desc'] = ($data['remark'] ?: '线下打款成功') . ' By ' . AdminService::getUserName();
  149. }
  150. if (DataUserTransfer::mk()->strict(false)->where($map)->update($data) !== false) {
  151. $this->success('操作成功');
  152. } else {
  153. $this->error('操作失败!');
  154. }
  155. }
  156. }
  157. /**
  158. * 后台打款服务
  159. * @auth true
  160. */
  161. public function sync()
  162. {
  163. $this->_queue('提现到微信余额定时处理', 'xdata:UserTransfer', 0, [], 0, 50);
  164. }
  165. }