Transfer.php 5.5 KB

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