Money.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Config;
  5. use app\common\model\MongyIn;
  6. use app\common\model\Order AS OrderModel;
  7. use app\common\model\User AS UserModel;
  8. use think\Db;
  9. use think\Exception;
  10. /**
  11. * 首页接口
  12. */
  13. class Money extends Api
  14. {
  15. protected $noNeedLogin = [];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 充值信息
  19. * @return void
  20. * @throws \think\exception\DbException
  21. */
  22. public function recharge()
  23. {
  24. $user = $this->auth->getUser();
  25. $data['amount_list'] = [100,200,500,1000,5000,10000];//快捷输入额度
  26. $data['usdt'] = $data['bank'] = 1;
  27. $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
  28. if(empty($recharge_info)){
  29. $this->error(__('无充值信息'));
  30. }
  31. if(empty($recharge_info['usdt'])){
  32. $data['usdt'] = 0;
  33. }
  34. if(empty($recharge_info['bank'])){
  35. $data['bank'] = 0;
  36. }
  37. $this->success('', $data);
  38. }
  39. /**
  40. * 创建充值订单
  41. * @return void
  42. */
  43. public function recharge_create()
  44. {
  45. $recharge_type = $this->request->post('type');
  46. $amount = $this->request->post('amount');
  47. if(!in_array($recharge_type, [1,2])){
  48. $this->error(__('参数有误'));
  49. }
  50. if(!($amount > 0)){
  51. $this->error(__('参数有误'));
  52. }
  53. $user = $this->auth->getUser();
  54. $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
  55. if(empty($recharge_info)){
  56. $this->error(__('无充值信息'));
  57. }
  58. $insert_data = [
  59. 'order_type' => $recharge_type,
  60. 'user_id' => $user['id'],
  61. 'amount' => $amount,
  62. 'status' => 0,
  63. 'agent_id' => $recharge_info['agent_id']
  64. ];
  65. //USDT充值
  66. if($recharge_type == 1){
  67. if(empty($recharge_info['usdt'])){
  68. $this->error(__('参数有误'));
  69. }
  70. $insert_data['order_no'] = 'U' . time() . $user['id'];
  71. $insert_data['address'] = $recharge_info['usdt'];
  72. }else{
  73. if(empty($recharge_info['bank'])){
  74. $this->error(__('参数有误'));
  75. }
  76. $insert_data['order_no'] = 'B' . time() . $user['id'];
  77. $insert_data['bank_name'] = $recharge_info['bank']['bank_name'];
  78. $insert_data['bank_card'] = $recharge_info['bank']['bank_card'];
  79. $insert_data['account_name']= $recharge_info['bank']['account_name'];
  80. }
  81. //写入
  82. Db::startTrans();
  83. try {
  84. (new MongyIn())->save($insert_data);
  85. Db::commit();
  86. } catch (Exception $e) {
  87. $this->error($e->getMessage());
  88. }
  89. $this->success('', $insert_data);
  90. }
  91. /**
  92. * 订单列表
  93. * @return void
  94. * @throws \think\exception\DbException
  95. */
  96. public function list()
  97. {
  98. $user = $this->auth->getUser();
  99. $paginator = OrderModel::where('user_id', $user['id'])
  100. ->field('order_no,amount,bonus,status,create_time')
  101. ->order('id DESC')
  102. ->paginate($this->pageSize);
  103. foreach ($paginator as $k => $v) {
  104. $paginator[$k]['status_name'] = (new OrderModel())->getStatusNames($v['status']);
  105. }
  106. $res_data = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
  107. $res_data['bonus_sum'] = $user['bonus_sum'];
  108. $this->success('', $res_data);
  109. }
  110. /**
  111. * 获取订单
  112. * @return void
  113. * @throws \think\exception\DbException
  114. */
  115. public function get()
  116. {
  117. $user = $this->auth->getUser();
  118. $data['order_no'] = 'sn45784545';
  119. $data['title'] = '商品标题111';
  120. $data['amount'] = 4545;
  121. $data['bonus'] = $user['bonus_sum'];
  122. $this->success('', $data);
  123. }
  124. }