Money.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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\MoneyOut;
  7. use app\common\model\Order AS OrderModel;
  8. use app\common\model\User AS UserModel;
  9. use think\Db;
  10. use think\Exception;
  11. /**
  12. * 首页接口
  13. */
  14. class Money extends Api
  15. {
  16. protected $noNeedLogin = [];
  17. protected $noNeedRight = ['*'];
  18. /**
  19. * 充值信息
  20. * @return void
  21. * @throws \think\exception\DbException
  22. */
  23. public function recharge()
  24. {
  25. $user = $this->auth->getUser();
  26. $data['amount_list'] = [100,200,500,1000,5000,10000];//快捷输入额度
  27. $data['usdt'] = $data['bank'] = 1;
  28. $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
  29. if(empty($recharge_info)){
  30. $this->error(__('无充值信息'));
  31. }
  32. if(empty($recharge_info['usdt'])){
  33. $data['usdt'] = 0;
  34. }
  35. if(empty($recharge_info['bank'])){
  36. $data['bank'] = 0;
  37. }
  38. $this->success('', $data);
  39. }
  40. /**
  41. * 创建充值订单
  42. * @return void
  43. */
  44. public function recharge_create()
  45. {
  46. $recharge_type = $this->request->post('type');
  47. $amount = $this->request->post('amount');
  48. if(!in_array($recharge_type, [1,2])){
  49. $this->error(__('参数有误'));
  50. }
  51. if(!($amount > 0)){
  52. $this->error(__('参数有误'));
  53. }
  54. $user = $this->auth->getUser();
  55. $recharge_info = UserModel::getAgentRechargeInfoByAgentId($user['agent_id']);
  56. if(empty($recharge_info)){
  57. $this->error(__('无充值信息'));
  58. }
  59. $insert_data = [
  60. 'order_type' => $recharge_type,
  61. 'user_id' => $user['id'],
  62. 'amount' => $amount,
  63. 'status' => MoneyIn::Default,
  64. 'agent_id' => $recharge_info['agent_id']
  65. ];
  66. //USDT充值
  67. if($recharge_type == 1){
  68. if(empty($recharge_info['usdt'])){
  69. $this->error(__('参数有误'));
  70. }
  71. $insert_data['order_no'] = 'U' . time() . $user['id'];
  72. $insert_data['address'] = $recharge_info['usdt'];
  73. }else{
  74. if(empty($recharge_info['bank'])){
  75. $this->error(__('参数有误'));
  76. }
  77. $insert_data['order_no'] = 'B' . time() . $user['id'];
  78. $insert_data['bank_name'] = $recharge_info['bank']['bank_name'];
  79. $insert_data['bank_card'] = $recharge_info['bank']['bank_card'];
  80. $insert_data['account_name']= $recharge_info['bank']['account_name'];
  81. }
  82. //写入
  83. Db::startTrans();
  84. try {
  85. (new MoneyIn())->save($insert_data);
  86. Db::commit();
  87. } catch (Exception $e) {
  88. $this->error($e->getMessage());
  89. }
  90. $this->success('', $insert_data);
  91. }
  92. /**
  93. * 上传图片
  94. * @return void
  95. * @throws \think\exception\DbException
  96. */
  97. public function recharge_upload()
  98. {
  99. $user = $this->auth->getUser();
  100. $order_no = $this->request->post('order_no');
  101. if (empty($order_no)) {
  102. $this->error(__('参数有误'));
  103. }
  104. $order_info = (new MoneyIn())
  105. ->where('user_id', $user['id'])
  106. ->where('order_no', $order_no)
  107. ->find();
  108. if (empty($order_no)) {
  109. $this->error(__('参数有误'));
  110. }
  111. $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
  112. if($file_info['code'] == 0){
  113. $this->error($file_info['msg']);
  114. }
  115. $this->success('', $file_info['data']);
  116. }
  117. /**
  118. * 提交充值信息
  119. * @return void
  120. * @throws \think\exception\DbException
  121. */
  122. public function recharge_submit()
  123. {
  124. $user = $this->auth->getUser();
  125. $order_no = $this->request->post('order_no');
  126. if (empty($order_no)) {
  127. $this->error(__('参数有误'));
  128. }
  129. $order_info = (new MoneyIn())
  130. ->where('user_id', $user['id'])
  131. ->where('order_no', $order_no)
  132. ->find();
  133. if (empty($order_info)) {
  134. $this->error(__('参数有误'));
  135. }
  136. //上传图片
  137. $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
  138. if($file_info['code'] == 0){
  139. $this->error($file_info['msg']);
  140. }
  141. $img_url = $file_info['data']['full_url'];
  142. if ($order_info['status'] != MoneyIn::Default) {
  143. if (empty($order_info['img_url'])) {
  144. (new MoneyIn())
  145. ->where('order_no', $order_no)
  146. ->update([
  147. 'img_url' => $img_url
  148. ]);
  149. }
  150. $this->success(__('提交成功'));
  151. }
  152. (new MoneyIn())
  153. ->where('order_no', $order_no)
  154. ->update([
  155. 'img_url' => $img_url,
  156. 'status' => MoneyIn::Pending,
  157. ]);
  158. $this->success(__('提交成功'));
  159. }
  160. /**
  161. * 提现
  162. * @return void
  163. */
  164. public function withdraw()
  165. {
  166. $user = $this->auth->getUser();
  167. $data['balance'] = $user['balance'];
  168. $data['money_out_sum'] = MoneyOut::where('user_id', $user['id'])->where('status', MoneyOut::Success)->sum('amount');
  169. $withdraw_info = UserModel::getAgentWithdrawInfoByAgentId($user['agent_id']);
  170. if(empty($withdraw_info)){
  171. $this->error(__('无提现信息'));
  172. }
  173. $data = array_merge($data, $withdraw_info);
  174. $this->success('', $data);
  175. }
  176. }