ソースを参照

Merge branch 'main' of https://jihulab.com/tou-biao/api-system

zac3533 1 年間 前
コミット
02cc564610

+ 1 - 1
application/admin/controller/trade/Mongyin.php

@@ -24,7 +24,7 @@ class Mongyin extends Backend
     {
         parent::_initialize();
         $this->mapType  = array();
-        $this->model    = new \app\common\model\Mongyin;
+        $this->model    = new \app\common\model\MongyIn;
         $this->assign('typeList', $this->model->getTypeList());
     }
 

+ 1 - 1
application/admin/controller/trade/Mongyout.php

@@ -29,7 +29,7 @@ class Mongyout extends Backend
     {
         parent::_initialize();
         $this->mapType  = array();
-        $this->model = new \app\common\model\Mongyout;
+        $this->model = new \app\common\model\MongyOut;
         $this->assign('typeList', $this->model->getTypeList());
     }
 

+ 140 - 0
application/api/controller/Money.php

@@ -0,0 +1,140 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\model\Config;
+use app\common\model\MongyIn;
+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 MongyIn())->save($insert_data);
+            Db::commit();
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+        $this->success('', $insert_data);
+    }
+
+    /**
+     * 订单列表
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function list()
+    {
+        $user = $this->auth->getUser();
+        $paginator = OrderModel::where('user_id', $user['id'])
+            ->field('order_no,amount,bonus,status,create_time')
+            ->order('id DESC')
+            ->paginate($this->pageSize);
+        foreach ($paginator as $k => $v) {
+            $paginator[$k]['status_name'] = (new OrderModel())->getStatusNames($v['status']);
+        }
+        $res_data = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
+        $res_data['bonus_sum'] = $user['bonus_sum'];
+        $this->success('', $res_data);
+    }
+
+    /**
+     * 获取订单
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function get()
+    {
+        $user = $this->auth->getUser();
+
+        $data['order_no']   = 'sn45784545';
+        $data['title']      = '商品标题111';
+        $data['amount']     = 4545;
+        $data['bonus']      = $user['bonus_sum'];
+
+        $this->success('', $data);
+    }
+}

+ 1 - 0
application/api/lang/zh-cn.php

@@ -4,4 +4,5 @@ return [
     '请求成功'                                         => '请求成功zh-cn',
     '全部状态'                                         => '全部',
     '未定义'                                           => '未定义',
+    '参数有误'                                         => '参数有误',
 ];

+ 8 - 0
application/api/lang/zh-cn/money.php

@@ -0,0 +1,8 @@
+<?php
+
+return [
+    '无充值信息'               => '系统未配置充值信息,请联系客服',
+    '完成'                    => '完成',
+    '冻结'                    => '冻结',
+    '取消'                    => '取消',
+];

+ 1 - 0
application/api/lang/zh-cn/user.php

@@ -38,4 +38,5 @@ return [
     'Reset password successful'             => '重置密码成功',
     '邀请码有误'                              => '邀请码不正确',
     '确认密码不一致'                           => '确认密码不一致',
+    '账号不存在'                              => '账号不存在',
 ];

+ 6 - 1
application/common/library/Auth.php

@@ -109,6 +109,11 @@ class Auth
                 $this->setError('Account is locked');
                 return false;
             }
+            //已删除
+            if ($user['is_delete'] == 1) {
+                $this->setError('账号不存在');
+                return false;
+            }
             $this->_user = $user;
             $this->_logined = true;
             $this->_token = $token;
@@ -517,7 +522,7 @@ class Auth
         return false;
     }
 
-    /**
+    /**+
      * 设置会话有效时间
      * @param int $keeptime 默认为永久
      */

+ 1 - 1
application/common/model/Mongyin.php → application/common/model/MongyIn.php

@@ -5,7 +5,7 @@ namespace app\common\model;
 use think\Model;
 
 
-class Mongyin extends Model
+class MongyIn extends Model
 {
 
     

+ 1 - 1
application/common/model/Mongyout.php → application/common/model/MongyOut.php

@@ -5,7 +5,7 @@ namespace app\common\model;
 use think\Model;
 
 
-class Mongyout extends Model
+class MongyOut extends Model
 {
 
     

+ 52 - 8
application/common/model/User.php

@@ -34,12 +34,64 @@ class User extends Model
             ->find();
         return $info;
     }
+
+    /**
+     * 根据邀请码获取会员信息
+     * @param $invitation_code
+     * @return array|bool|\PDOStatement|string|Model|null
+     */
     public static function getByInvitationCode($invitation_code)
     {
         $info = self::where('invitation_code', $invitation_code)
             ->find();
         return $info;
     }
+
+    /**
+     * 获取代理信息
+     * @param $invitation_code
+     * @return array|null
+     */
+    public static function getAgentInfoByAgentId($agent_id)
+    {
+        $data['usdt']     = '';
+        $data['bank']     = [];
+        $data['agent_id'] = $agent_id;
+        $info = self::where('id', $agent_id)
+            ->where('is_agent', 1)
+            ->where('is_lock', 0)
+            ->where('is_delete', 0)
+            ->find();
+        if(empty($info)){
+            //没找到代理时,默认显示系统配置
+            if((new Config())->getValue('recharge_usdt_switch')){
+                $data['usdt'] = (new Config())->getValue('recharge_usdt_address');
+            }
+
+            if((new Config())->getValue('recharge_bank_switch')){
+                $data['bank']['bank_name']    = (new Config())->getValue('recharge_bank_name');
+                $data['bank']['bank_card']    = (new Config())->getValue('recharge_bank_card');
+                $data['bank']['account_name'] = (new Config())->getValue('recharge_account_name');
+            }
+            $data['agent_id'] = 0;
+            return $data;
+        }
+
+        if($info['agent_in_usdt']){
+            $data['usdt'] = $info['agent_usdt_address'];
+        }
+        if($info['agent_in_bank']){
+            $bank_info = $info['agent_bank_info'];
+            $data['bank']['bank_name'] = $bank_info['bank_name'];
+            $data['bank']['bank_card'] = $bank_info['bank_card'];
+            $data['bank']['real_name'] = $bank_info['real_name'];
+        }
+        if(empty($data['usdt']) && empty($data['bank'])){
+            return [];
+        }
+        return $data;
+    }
+
     /**
      * 获取个人URL
      * @param string $value
@@ -67,14 +119,6 @@ class User extends Model
         return $value;
     }
 
-    /**
-     * 获取会员的组别
-     */
-    public function getGroupAttr($value, $data)
-    {
-        return UserGroup::get($data['group_id']);
-    }
-
     /**
      * 获取验证字段数组值
      * @param string $value