Transfer.php 6.2 KB

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