Parcourir la source

Weenier 168otc项目部署 0630

wesmiler il y a 3 ans
Parent
commit
7063cfd20e

+ 56 - 0
app/Http/Controllers/Api/CoinLogController.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Http\Validator\CoinValidator;
+use App\Services\Common\CoinLogService;
+
+/**
+ * 币明细
+ * Class CoinLogController
+ * @package App\Http\Controllers\Api
+ */
+class CoinLogController extends WebApp
+{
+    public function __construct()
+    {
+        parent::__construct();
+        $this->service = new CoinLogService();
+    }
+
+    /**
+     * 获取列表
+     * @return array|mixed
+     */
+    public function index()
+    {
+        $pageSize = request()->post('limit', 15);
+        $params = request()->all();
+        if($this->userInfo['user_type'] == 2){
+            $params['business_id'] = $this->userInfo['user_id'];
+        }
+        $list = $this->service->getDataList($params, $pageSize);
+        return message(1002, true, $list);
+    }
+
+
+    /**
+     * 提币
+     * @return array
+     */
+    public function withdraw(CoinValidator $validate)
+    {
+        $params = request()->post();
+        $params = $validate->check($params,'out');
+        if(!is_array($params)){
+            return message($params, false,[]);
+        }
+        $params['check_google'] = false;
+        if(!CoinLogService::make()->withdraw($this->userId, $params)){
+            return message(CoinLogService::make()->getError(), false);
+        }else{
+            return message(CoinLogService::make()->getError(), true);
+        }
+    }
+
+}

+ 30 - 14
app/Http/Controllers/Api/WalletController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Api;
 
 use App\Http\Validator\CoinValidator;
+use App\Http\Validator\WalletValidator;
 use App\Services\Api\AdvertService;
 use App\Services\Api\MemberWalletService;
 use App\Services\Common\CoinLogService;
@@ -15,6 +16,12 @@ use App\Services\Common\CoinLogService;
 class WalletController extends webApp
 {
 
+    public function __construct()
+    {
+        $this->service = new MemberWalletService();
+    }
+
+
     /**
      * 获取列表
      * @return array|mixed
@@ -28,31 +35,40 @@ class WalletController extends webApp
     }
 
     /**
-     * 提币
+     * 添加地址簿
+     * @param WalletValidator $validate
      * @return array
      */
-    public function withdraw(CoinValidator $validate)
+    public function add(WalletValidator $validate)
     {
-        $params = request()->post();
-        $params = $validate->check($params,'withdraw');
+        $params = $validate->check(request()->post(),'add');
         if(!is_array($params)){
-            return message($params, false,[]);
+            return message($params, false);
         }
 
-        if(!CoinLogService::make()->withdraw($this->userInfo['user_id'], $params)){
-            return message(CoinLogService::make()->getError(), false);
+        if($this->service->saveData($this->userId, $params)){
+            return message(1002, true);
         }else{
-            return message(CoinLogService::make()->getError(), true);
+            return message($this->service->getError(), true);
         }
     }
 
-    public function add()
-    {
-
-    }
-
-    public function del()
+    /**
+     * 删除
+     * @param WalletValidator $validate
+     * @return array
+     */
+    public function del(WalletValidator $validate)
     {
+        $params = $validate->check(request()->post(),'info');
+        if(!is_array($params)){
+            return message($params, false);
+        }
 
+       if($this->service->del($params['id'], $this->userId)){
+           return message(1002, true);
+       }else{
+           return message(1003, true);
+       }
     }
 }

+ 1 - 0
app/Http/Validator/CoinValidator.php

@@ -38,6 +38,7 @@ class CoinValidator extends BaseValidator
     public static $scenes = [
         'info'=> ['id'],
         'withdraw'=> ['change_type','contact_type','google_code','to_address','trade_password','num'],
+        'out'=> ['contact_type','trade_password','to_address','num'],
         'confirm'=> ['id'],
     ];
 

+ 45 - 0
app/Http/Validator/WalletValidator.php

@@ -0,0 +1,45 @@
+<?php
+namespace App\Http\Validator;
+class WalletValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'coin_type' => 'required',
+        'address' => 'required',
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'coin_type' => '币种类型',
+        'address' => '钱包地址',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'add'=> ['coin_type','address'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 150 - 0
app/Services/Api/CoinLogService.php

@@ -0,0 +1,150 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\CoinLogModel;
+use App\Models\MemberModel;
+use App\Models\UserModel;
+use App\Services\BaseService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
+use Earnp\GoogleAuthenticator\GoogleAuthenticator;
+
+/**
+ * 币种明细(提币、存币)-服务类
+ * Class CoinLogService
+ * @package App\Services\Api
+ */
+class CoinLogService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @since 2020/11/10
+     * CoinLogService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new CoinLogModel();
+        $this->memberModel = new MemberModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 获取列表
+     * @param $params 参数
+     * @param int $pageSize 分页大小:默认 15
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1];
+        $type = isset($params['type']) ? $params['type'] : 1;
+        $status = isset($params['status']) ? $params['status'] : 0;
+        $changeType = isset($params['change_type']) ? $params['change_type'] : 1;
+        $contactType = isset($params['contact_type']) ? $params['contact_type'] : 1;
+        $coinType = isset($params['coin_type']) ? $params['coin_type'] : 1;
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        if ($type > 0) {
+            $where['a.type'] = $type;
+        }
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        if ($contactType > 0) {
+            $where['a.contact_type'] = $contactType;
+        }
+        if ($changeType > 0) {
+            $where['a.change_type'] = $changeType;
+        }
+        if ($coinType > 0) {
+            $where['a.coin_type'] = $coinType;
+        }
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+
+        $list = $this->model->from('coin_logs as a')
+            ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
+            ->where($where)
+            ->where(function ($query) use ($params) {
+                $keyword = isset($params['keyword']) ? $params['keyword'] : '';
+                if ($keyword) {
+                    $query->where('a.order_no', 'like', "{$keyword}")->orWhere('m.username', 'like', "%{$keyword}%");
+                }
+
+                // 日期
+                $date = isset($params['date']) ? $params['date'] : [];
+                $start = isset($date[0]) ? $date[0] : '';
+                $end = isset($date[1]) ? $date[1] : '';
+                $end = $start >= $end ? '' : $end;
+                if ($start) {
+                    $query->where('a.create_time', '>=', strtotime($start));
+                }
+                if ($end) {
+                    $query->where('a.create_time', '<', strtotime($end));
+                }
+            })
+            ->select(['a.*', 'm.username'])
+            ->orderBy('a.create_time', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+        if ($list) {
+            foreach ($list['data'] as &$item) {
+                $item['time_text'] = $item['create_time'] ? datetime(strtotime($item['create_time']), 'm-d H:i') : '';
+            }
+        }
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 验证是否存在
+     * @param \App\Services\字段名 $field
+     * @param \App\Services\字段值 $value
+     * @param string $pk
+     * @return mixed
+     */
+    public function checkExists($field, $value, $pk = 'id', $status = 0)
+    {
+        $cacheKey = "caches:coinLogs:exists:{$field}_{$value}";
+        if ($result = RedisService::get($cacheKey)) {
+            return $result;
+        }
+
+        $result = parent::checkExists($field, $value, $pk, $status);
+        if ($result) {
+            RedisService::set($cacheKey, $result, rand(3, 5));
+        }
+
+        return $result;
+    }
+
+
+}

+ 1 - 1
app/Services/Api/MemberService.php

@@ -63,7 +63,7 @@ class MemberService extends BaseService
      */
     public function getInfo($where, array $field = [])
     {
-        $field = $field ? $field : ['id', 'username', 'realname', 'nickname', 'openid', 'idcard','trade_password', 'trc_address', 'erc_address','erc_hexaddress', 'source', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'safe_level', 'user_type', 'member_level', 'usdt_num', 'user_type', 'status', 'credit', 'avatar'];
+        $field = $field ? $field : ['id', 'username', 'realname', 'nickname', 'openid', 'idcard','google_secret', 'trade_password', 'trc_address', 'erc_address','erc_hexaddress', 'source', 'idcard_check', 'idcard_front_img', 'idcard_back_img', 'safe_level', 'user_type', 'member_level', 'usdt_num', 'user_type', 'status', 'credit', 'avatar'];
         if (is_array($where)) {
             $info = $this->model->where($where)->select($field)->first();
         } else {

+ 24 - 20
app/Services/Common/CoinLogService.php

@@ -209,32 +209,36 @@ class CoinLogService extends BaseService
         }
 
         // 谷歌验证码
-        $googleCode = isset($params['google_code'])? $params['google_code'] : '';
-        $info = UserModel::where(['user_id'=> $userId])->select(['google_secret','google_verify_time'])->first();
-        $googleSecret = isset($info['google_secret'])? $info['google_secret'] : '';
-        $verifyTime = isset($info['google_verify_time'])? intval($info['google_verify_time']) : 0;
-        if(empty($googleSecret)){
-            $this->error = '2017';
-            return false;
-        }
+        $checkGoogle = isset($params['check_google'])? $params['check_google'] : 1;
+        if($checkGoogle){
+            $googleCode = isset($params['google_code'])? $params['google_code'] : '';
+            $info = UserModel::where(['user_id'=> $userId])->select(['google_secret','google_verify_time'])->first();
+            $googleSecret = isset($info['google_secret'])? $info['google_secret'] : '';
+            $verifyTime = isset($info['google_verify_time'])? intval($info['google_verify_time']) : 0;
+            if(empty($googleSecret)){
+                $this->error = '2017';
+                return false;
+            }
 
-        // 刚验证更新的谷歌验证码24小时内不得提币
-        if($verifyTime && $verifyTime> time()){
-            $this->error = '2019';
-            return false;
-        }
+            // 刚验证更新的谷歌验证码24小时内不得提币
+            if($verifyTime && $verifyTime> time()){
+                $this->error = '2019';
+                return false;
+            }
 
-        if (!GoogleAuthenticator::CheckCode($googleSecret, $googleCode)) {
-            $this->error = '2018';
-            return false;
+            if (!GoogleAuthenticator::CheckCode($googleSecret, $googleCode)) {
+                $this->error = '2018';
+                return false;
+            }
         }
 
+
         $config = ConfigService::make()->getConfigOptionByGroup(6);
         $coinOutFree = isset($config['coin_out_free'])? floatval($config['coin_out_free']) : 0;
-        $free = floatval($num * $coinOutFree/100);
+        $fee = floatval($num * $coinOutFree/100);
 
         // 余额是否足够
-        if($userInfo['usdt_num'] < floatval($num + $free)){
+        if($userInfo['usdt_num'] < floatval($num + $fee)){
             $this->error = '2212';
             return false;
         }
@@ -250,7 +254,7 @@ class CoinLogService extends BaseService
             'order_no'=> get_order_num('Tw'),
             'txid'=> uniqid(),
             'num'=> $num,
-            'free'=> $free,
+            'free'=> $fee,
             'balance'=> $userInfo['usdt_num'],
             'create_time'=> time(),
             'update_time'=> time(),
@@ -266,7 +270,7 @@ class CoinLogService extends BaseService
         }
 
         // 扣除余额
-        if(!$this->memberModel->where(['id'=> $userId,'mark'=>1])->decrement('usdt_num', ($num + $free))){
+        if(!$this->memberModel->where(['id'=> $userId,'mark'=>1])->decrement('usdt_num', ($num + $fee))){
             $this->model->rollBack();
             $this->error = '2014';
             return false;