| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\Config;
- use app\common\model\MoneyIn;
- use app\common\model\Order AS OrderModel;
- use app\common\model\User AS UserModel;
- use think\Db;
- use think\Exception;
- /**
- * 首页接口
- */
- class Money extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 充值信息
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge()
- {
- $user = $this->auth->getUser();
- $data['amount_list'] = [100,200,500,1000,5000,10000];//快捷输入额度
- $data['usdt'] = $data['bank'] = 1;
- $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- if(empty($recharge_info['usdt'])){
- $data['usdt'] = 0;
- }
- if(empty($recharge_info['bank'])){
- $data['bank'] = 0;
- }
- $this->success('', $data);
- }
- /**
- * 创建充值订单
- * @return void
- */
- public function recharge_create()
- {
- $recharge_type = $this->request->post('type');
- $amount = $this->request->post('amount');
- if(!in_array($recharge_type, [1,2])){
- $this->error(__('参数有误'));
- }
- if(!($amount > 0)){
- $this->error(__('参数有误'));
- }
- $user = $this->auth->getUser();
- $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- $insert_data = [
- 'order_type' => $recharge_type,
- 'user_id' => $user['id'],
- 'amount' => $amount,
- 'status' => 0,
- 'agent_id' => $recharge_info['agent_id']
- ];
- //USDT充值
- if($recharge_type == 1){
- if(empty($recharge_info['usdt'])){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'U' . time() . $user['id'];
- $insert_data['address'] = $recharge_info['usdt'];
- }else{
- if(empty($recharge_info['bank'])){
- $this->error(__('参数有误'));
- }
- $insert_data['order_no'] = 'B' . time() . $user['id'];
- $insert_data['bank_name'] = $recharge_info['bank']['bank_name'];
- $insert_data['bank_card'] = $recharge_info['bank']['bank_card'];
- $insert_data['account_name']= $recharge_info['bank']['account_name'];
- }
- //写入
- Db::startTrans();
- try {
- (new MoneyIn())->save($insert_data);
- Db::commit();
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- $this->success('', $insert_data);
- }
- /**
- * 上传图片
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge_upload()
- {
- $user = $this->auth->getUser();
- $order_no = $this->request->post('order_no');
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- $order_info = (new MoneyIn())
- ->where('user_id', $user['id'])
- ->where('order_no', $order_no)
- ->find();
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- $file_info = ali_oss_upload($this->request, 'recharge', $order_no);
- if($file_info['code'] == 0){
- $this->error($file_info['msg']);
- }
- $this->success('', $file_info['data']);
- }
- /**
- * 提交充值信息
- * @return void
- * @throws \think\exception\DbException
- */
- public function recharge_submit()
- {
- $user = $this->auth->getUser();
- $order_no = $this->request->post('order_no');
- $img_url = $this->request->post('img_url');
- if (empty($order_no)) {
- $this->error(__('参数有误'));
- }
- if (empty($img_url)) {
- $this->error(__('参数有误'));
- }
- $order_info = (new MoneyIn())
- ->where('user_id', $user['id'])
- ->where('order_no', $order_no)
- ->find();
- if (empty($order_info)) {
- $this->error(__('参数有误'));
- }
- if ($order_info['status'] != 0) {
- if (empty($order_info['img_url'])) {
- (new MoneyIn())
- ->where('order_no', $order_no)
- ->update([
- 'img_url' => $img_url
- ]);
- }
- $this->success(__('提交成功'));
- }
- (new MoneyIn())
- ->where('order_no', $order_no)
- ->update([
- 'img_url' => $img_url,
- 'status' => 1,
- ]);
- $this->success(__('提交成功'));
- }
- /**
- * 提现
- * @return void
- */
- public function withdraw()
- {
- $user = $this->auth->getUser();
- $data['balance'] = $user['balance'];
- $data['usdt'] = $data['bank'] = 1;
- $recharge_info = UserModel::getAgentInfoByAgentId($user['agent_id']);
- if(empty($recharge_info)){
- $this->error(__('无充值信息'));
- }
- if(empty($recharge_info['usdt'])){
- $data['usdt'] = 0;
- }
- if(empty($recharge_info['bank'])){
- $data['bank'] = 0;
- }
- $this->success('', $data);
- }
- }
|