Money.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Config;
  5. use app\common\model\MoneyIn;
  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 MoneyIn())->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 recharge_upload()
  97. {
  98. $user = $this->auth->getUser();
  99. $order_no = $this->request->post('order_no');
  100. if (empty($order_no)) {
  101. $this->error(__('参数有误'));
  102. }
  103. $order_info = (new MoneyIn())
  104. ->where('user_id', $user['id'])
  105. ->where('order_no', $order_no)
  106. ->find();
  107. if (empty($order_no)) {
  108. $this->error(__('参数有误'));
  109. }
  110. $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
  111. if($file_info['code'] == 0){
  112. $this->error($file_info['msg']);
  113. }
  114. $this->success('', $file_info['data']);
  115. }
  116. /**
  117. * 提交充值信息
  118. * @return void
  119. * @throws \think\exception\DbException
  120. */
  121. public function recharge_submit()
  122. {
  123. $user = $this->auth->getUser();
  124. $order_no = $this->request->post('order_no');
  125. $img_url = $this->request->post('img_url');
  126. if (empty($order_no)) {
  127. $this->error(__('参数有误'));
  128. }
  129. if (empty($img_url)) {
  130. $this->error(__('参数有误'));
  131. }
  132. $order_info = (new MoneyIn())
  133. ->where('user_id', $user['id'])
  134. ->where('order_no', $order_no)
  135. ->find();
  136. if (empty($order_info)) {
  137. $this->error(__('参数有误'));
  138. }
  139. if ($order_info['status'] != 0) {
  140. if (empty($order_info['img_url'])) {
  141. (new MoneyIn())
  142. ->where('order_no', $order_no)
  143. ->update([
  144. 'img_url' => $img_url
  145. ]);
  146. }
  147. $this->success(__('提交成功'));
  148. }
  149. (new MoneyIn())
  150. ->where('order_no', $order_no)
  151. ->update([
  152. 'img_url' => $img_url,
  153. 'status' => 1,
  154. ]);
  155. $this->success(__('提交成功'));
  156. }
  157. /**
  158. * 提现
  159. * @return void
  160. */
  161. public function withdraw()
  162. {
  163. $user = $this->auth->getUser();
  164. $data['balance'] = $user['balance'];
  165. $data['usdt'] = $data['bank'] = 1;
  166. $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
  167. if(empty($recharge_info)){
  168. $this->error(__('无充值信息'));
  169. }
  170. if(empty($recharge_info['usdt'])){
  171. $data['usdt'] = 0;
  172. }
  173. if(empty($recharge_info['bank'])){
  174. $data['bank'] = 0;
  175. }
  176. $this->success('', $data);
  177. }
  178. }