Просмотр исходного кода

Wesmiler OTC 提交更新 0729

APPLE 3 лет назад
Родитель
Сommit
eec8dc36c5

+ 67 - 57
app/Console/Commands/Socket.php

@@ -43,12 +43,12 @@ class Socket extends Command
     public function handle()
     {
         $op = $this->argument('op');
-        $op = $op? $op : 'start';
-        if($op == 'start'){
-            echo 'socket start ...';
+        $op = $op ? $op : 'start';
+        if ($op == 'start') {
+            echo "socket start ...\n";
             $this->start();
-        }else if ($op == 'stop'){
-            echo 'socket stop ...';
+        } else if ($op == 'stop') {
+            echo "socket stop ...\n";
             $this->stop();
         }
     }
@@ -59,21 +59,21 @@ class Socket extends Command
     public function start()
     {
         //创建websocket服务器对象,监听0.0.0.0:7104端口
-        $this->ws = new \swoole_websocket_server("0.0.0.0", env('SOCKET_PORT','6420'));
+        $this->ws = new \swoole_websocket_server("0.0.0.0", env('SOCKET_PORT', '6420'));
 
 //        $this->ws->set();
 
         //监听WebSocket连接打开事件
-        $this->ws->on('open',[$this,'open']);
+        $this->ws->on('open', [$this, 'open']);
 
         //监听WebSocket消息事件
-        $this->ws->on('message',[$this,'message']);
+        $this->ws->on('message', [$this, 'message']);
 
         //监听WebSocket主动推送消息事件
-        $this->ws->on('request',[$this,'request']);
+        $this->ws->on('request', [$this, 'request']);
 
         //监听WebSocket连接关闭事件
-        $this->ws->on('close',[$this,'close']);
+        $this->ws->on('close', [$this, 'close']);
 
         $this->ws->start();
     }
@@ -83,9 +83,10 @@ class Socket extends Command
      * @param $ws
      * @param $request
      */
-    public function open($ws, $request){
-        echo "连接成功:".$request->fd."\n";
-        $this->ws->push($request->fd,'连接成功');
+    public function open($ws, $request)
+    {
+        echo "连接成功:" . $request->fd . "\n";
+        $this->ws->push($request->fd, json_encode(['message'=>'连接成功'], 256));
     }
 
     /**
@@ -93,63 +94,70 @@ class Socket extends Command
      * @param $ws
      * @param $frame
      */
-    public function message($ws,$frame){
-        if($frame->data == 'ping'){
+    public function message($ws, $frame)
+    {
+        if ($frame->data == 'ping') {
             $this->ws->push($frame->fd, 'pong');
             return false;
         }
 
         // 消息处理
-        $data = $frame->data? json_decode($frame->data, true) : [];
-        $op = isset($data['op'])? $data['op'] : '';
-        if($data){
-            switch($op){
-                case 'bind': // 绑定用户
-                    if(!ChatMessageService::make()->bind($frame->fd, $data)){
-                        $this->ws->push($frame->fd, lang(ChatMessageService::make()->getError()));
-                        return false;
-                    }
-                    break;
-                default:  // 默认聊天
-                    $toUid = isset($data['to_uid'])? intval($data['to_uid']) : 0;
-                    $fromUid = isset($data['from_uid'])? intval($data['from_uid']) : 0;
-                    $messageType = isset($data['message_type'])? $data['message_type'] : 1;
-                    if($toUid<=0 || $fromUid<=0){
+        $data = $frame->data ? json_decode($frame->data, true) : [];
+        $op = isset($data['op']) ? $data['op'] : '';
+        $userId = isset($data['from_uid'])? intval($data['from_uid']) : 0;
+        $chatKey = isset($data['chat_key'])? trim($data['chat_key']) : '';
+        if($userId && $frame->fd){
+            RedisService::set("chats:bind:{$userId}", ['fd'=> $frame->fd, 'user_id'=> $userId,'chat_key'=>$chatKey], 86400);
+        }
+        if ($data) {
+            switch ($op) {
+                case 'chat': // 默认聊天
+                    $toUid = isset($data['to_uid']) ? intval($data['to_uid']) : 0;
+                    $fromUid = isset($data['from_uid']) ? intval($data['from_uid']) : 0;
+                    $messageType = isset($data['message_type']) ? $data['message_type'] : 1;
+
+                    if ($toUid <= 0 || $fromUid <= 0) {
                         return false;
                     }
-                    if(!ChatMessageService::make()->saveData($data)){
-                        $this->ws->push($frame->fd, lang(ChatMessageService::make()->getError()));
+
+                    if (!ChatMessageService::make()->saveData($data)) {
+                        $data = ['message'=> lang(ChatMessageService::make()->getError())];
+                        $this->ws->push($frame->fd, json_encode($data, 256));
                         return false;
                     }
 
+                    $toInfo = MemberService::make()->getInfo($toUid);
+                    $fromInfo = MemberService::make()->getInfo($fromUid);
+                    $message = isset($data['message']) ? $data['message'] : '';
+                    $chatKey = getChatKey($fromUid, $toUid);
+                    $data = [
+                        'type' => isset($data['type']) ? $data['type'] : 1,
+                        'message_type' => $messageType,
+                        'from_uid' => $fromUid,
+                        'from_userName' => isset($fromInfo['username']) ? format_account($fromInfo['username']) : '客服',
+                        'to_uid' => isset($data['to_uid']) ? $data['to_uid'] : 0,
+                        'to_userName' => isset($toInfo['username']) ? format_account($toInfo['username']) : '客服',
+                        'chat_key' => $chatKey,
+                        'message' => $message,
+                        'message_url' => $messageType == 2 && $message ? get_image_url($message) : '',
+                        'create_time' => time(),
+                        'time_text' => date('m-d H:i'),
+                        'is_read' => 1,
+                        'status' => 1,
+                    ];
+
+                    $this->ws->push($frame->fd, json_encode($data, 256));
                     $toBindData = RedisService::get("chats:bind:{$toUid}");
-                    $toFd = isset($toBindData['fd'])? $toBindData['fd'] : 0;
-                    if($toBindData && $toFd){
-                        $toInfo = MemberService::make()->getInfo($toUid);
-                        $fromInfo = MemberService::make()->getInfo($fromUid);
-                        $message = isset($data['message'])? $data['message'] : '';
-                        $data = [
-                            'type'=> isset($data['type'])? $data['type'] : 1,
-                            'message_type'=> $messageType,
-                            'from_uid'=> $fromUid,
-                            'from_userName'=> isset($fromInfo['username'])? $fromInfo['username'] : '',
-                            'to_uid'=> isset($data['to_uid'])? $data['to_uid'] : 0,
-                            'to_userName'=> isset($toInfo['username'])? $toInfo['username'] : '',
-                            'chat_key'=> getChatKey($fromUid, $toUid),
-                            'message'=> $messageType==2&&$message? get_image_url($message) : $message,
-                            'create_time'=> time(),
-                            'time_text'=> date('m-d H:i'),
-                            'is_read'=> 1,
-                            'status'=> 1,
-                        ];
+                    $toFd = isset($toBindData['fd']) ? $toBindData['fd'] : 0;
+                    $toChatKey = isset($toBindData['chat_key']) ? $toBindData['chat_key'] : '';
+                    if ($toBindData && $toFd && $toChatKey == $chatKey) {
                         $this->ws->push($toFd, json_encode($data, 256));
                     }
 
                     break;
-
             }
-        }else{
-            $this->ws->push($frame->fd, 'not data');
+        } else {
+            $this->ws->push($frame->fd, '{message:no data}');
         }
     }
 
@@ -158,7 +166,8 @@ class Socket extends Command
      * @param $request
      * @param $response
      */
-    public function request($request,$response){
+    public function request($request, $response)
+    {
 
     }
 
@@ -167,9 +176,10 @@ class Socket extends Command
      * @param $ws
      * @param $fd
      */
-    public function close($ws,$fd=''){
+    public function close($ws, $fd = '')
+    {
 //        var_dump($ws);
-        echo '连接关闭:'.$fd."\n";
+        echo '连接关闭:' . $fd . "\n";
         $this->ws->close($fd);
     }
 

+ 3 - 1
app/Http/Controllers/Admin/IndexController.php

@@ -198,6 +198,8 @@ class IndexController extends Backend
     public function wallet()
     {
         $data = ConfigService::make()->getConfigOptionByGroup(5);
+        var_dump($data);
+        return false;
         if(isset($data['trc_address']) && $data['trc_address']){
             $qrcode = \App\Services\Api\MemberService::make()->makeQrcode($data['trc_address']);
             $data['trc_qrcode'] = $qrcode? get_image_url($qrcode) : '';
@@ -244,7 +246,7 @@ class IndexController extends Backend
             'from'=> $changeType==1? '' : $address,
             'to'=> $changeType==1? $address : '',
         ];
-
+var_dump($params);
         $datas = CoinLogService::make()->getDataList($params, $limit);
 
         return returnJson(MESSAGE_OK, true, is_array($datas)? $datas : []);

+ 6 - 4
app/Http/Controllers/Admin/UploadController.php

@@ -45,12 +45,13 @@ class UploadController extends Backend
         }
 
         // 网络域名拼接
+        $file_url = $file_path;
         if (strpos($file_path, IMG_URL) === false) {
-            $file_path = IMG_URL . $file_path;
+            $file_url = IMG_URL . $file_path;
         }
 
         // 返回结果
-        return returnJson(MESSAGE_OK, true, $file_path);
+        return returnJson(MESSAGE_OK, true, ['url'=>$file_url,'path'=>$file_path]);
     }
 
     /**
@@ -72,12 +73,13 @@ class UploadController extends Backend
         }
 
         // 网络域名拼接
+        $file_url = $file_path;
         if (strpos($file_path, IMG_URL) === false) {
-            $file_path = IMG_URL . $file_path;
+            $file_url = IMG_URL . $file_path;
         }
 
         // 返回结果
-        return returnJson(MESSAGE_OK, true, $file_path);
+        return returnJson(MESSAGE_OK, true, ['url'=>$file_url,'path'=>$file_path]);
     }
 
 }

+ 19 - 19
app/Http/Controllers/Api/TaskController.php

@@ -18,7 +18,7 @@ class TaskController extends webApp
 {
 
     /**
-     * 监听处理存币(转账-进账)
+     * 监听处理用户TRC子钱包存币(转账-进账)
      * @return array|mixed
      */
     public function catchTrcRecharge()
@@ -28,13 +28,13 @@ class TaskController extends webApp
         if($checkKey != $key){
             return showJson(1003, false);
         }
-
-        $page = RedisService::get("caches:wallet:rechargePage");
+        $cachekey = "caches:wallet:trc_";
+        $page = RedisService::get($cachekey."rechargePage");
         $page = $page? $page : 1;
 
         $members = MemberService::make()->getCatchMember($page, 500);
         if(empty($members)){
-            RedisService::set("caches:wallet:rechargePage", 1, 600);
+            RedisService::set($cachekey."rechargePage", 1, 600);
             return showJson(1019, false);
         }
 
@@ -44,15 +44,15 @@ class TaskController extends webApp
             $result = UsdtWalletService::make()->getTrc20RechargeLog($v['id'], $v['trc_address']);
             if($result){
                 $count++;
-                RedisService::set("caches:wallet:catchRecharge:{$v['id']}_result", $result, 600);
+                RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $result, 600);
             }else{
                 $failedCount++;
                 $error = lang(UsdtWalletService::make()->getError());
-                RedisService::set("caches:wallet:catchRecharge:{$v['id']}_result", $error, 600);
+                RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $error, 600);
             }
         }
 
-        RedisService::set("caches:wallet:rechargePage", $page+1, 600);
+        RedisService::set($cachekey."rechargePage", $page+1, 600);
         if($count>0){
             return showJson(1020, true,['success'=> $count,'fail'=> $failedCount]);
         }else{
@@ -60,12 +60,11 @@ class TaskController extends webApp
         }
     }
 
-
     /**
-     * 监听处理提币(转账-出账)
+     * 监听处理用户ERC子钱包存币(转账-进账)
      * @return array|mixed
      */
-    public function catchTrcTransfer()
+    public function catchErcRecharge()
     {
         $key = md5('OTC');
         $checkKey = request()->get('key');
@@ -73,30 +72,31 @@ class TaskController extends webApp
             return showJson(1003, false);
         }
 
-        $page = RedisService::get("caches:wallet:transferPage");
+        $cachekey = "caches:wallet:erc_";
+        $page = RedisService::get($cachekey."rechargePage");
         $page = $page? $page : 1;
 
         $members = MemberService::make()->getCatchMember($page, 500);
         if(empty($members)){
-            RedisService::set("caches:wallet:transferPage", 1, 600);
+            RedisService::set($cachekey."rechargePage", 1, 600);
             return showJson(1019, false);
         }
 
         $count = 0;
         $failedCount = 0;
         foreach ($members as $v){
-            $result = UsdtWalletService::make()->getTrc20TransferLogByUser($v['id'], $v['trc_address']);
+            $result = UsdtWalletService::make()->getErc20RechargeLog($v['id'], $v['trc_address']);
             if($result){
                 $count++;
-                RedisService::set("caches:wallet:catchTransfer:{$v['id']}_result", $result, 600);
+                RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $result, 600);
             }else{
                 $failedCount++;
                 $error = lang(UsdtWalletService::make()->getError());
-                RedisService::set("caches:wallet:catchTransfer:{$v['id']}_result", $error, 600);
+                RedisService::set($cachekey."catchRecharge:{$v['id']}_result", $error, 600);
             }
         }
 
-        RedisService::set("caches:wallet:transferPage", $page+1, 600);
+        RedisService::set($cachekey."rechargePage", $page+1, 600);
         if($count>0){
             return showJson(1020, true,['success'=> $count,'fail'=> $failedCount]);
         }else{
@@ -105,7 +105,7 @@ class TaskController extends webApp
     }
 
     /**
-     * 监听平台TRC出账钱包交易记录(提币回调确认完成交易)
+     * 监听平台TRC平台出账钱包交易记录(提币回调确认完成交易)
      * @return array|mixed
      */
     public function catchTrcTransferByOtc()
@@ -138,7 +138,7 @@ class TaskController extends webApp
     }
 
     /**
-     * 监听平台ERC出账钱包交易记录(提币回调确认完成交易)
+     * 监听平台ERC平台出账钱包交易记录(提币回调确认完成交易)
      * @return array|mixed
      */
     public function catchErcTransferByOtc()
@@ -150,7 +150,7 @@ class TaskController extends webApp
         }
 
         // 出账手续费钱包
-        $otcOutAddress = ConfigService::make()->getConfigByCode('trc_out_address');
+        $otcOutAddress = ConfigService::make()->getConfigByCode('erc_out_address');
         if(empty($otcOutAddress)){
             return showJson(2210, false);
         }

+ 9 - 2
app/Http/Controllers/Api/TestController.php

@@ -8,6 +8,7 @@ use App\Services\EmailService;
 use App\Services\RedisService;
 use App\Services\UsdtWalletService;
 use Illuminate\Http\Request;
+use Web3p\EthereumTx\Transaction;
 
 /**
  * 测试
@@ -28,10 +29,16 @@ class TestController extends webApp
     public function index()
     {
 
-        //$result = UsdtWalletService::make()->getErcBalance('0x00000000219ab540356cbb839cbe05303d7705fa');
+        echo getChatKey(10005,10003);
+
+
+        return false;
+
+//        $result = UsdtWalletService::make()->getErcBalance('0x00000000219ab540356cbb839cbe05303d7705fa');
         //var_dump($result);
 //        $result = UsdtWalletService::make()->getTransactionSignData('0xd46e8dd6', '0xd46e8dd67c5d32be8058bb8eb970870f07244567','2441406250');
-        $result = UsdtWalletService::make()->usdtErcTransfer('0x00000000219ab540356cbb839cbe05303d7705fa', 1);
+        $result = UsdtWalletService::make()->getErc20TransferLogByOtc('0xeAD1f37a6C045AAf21AC064e52235739F69C4F9d', 10);
+//        $result = UsdtWalletService::make()->ercTransfer('0x00000000219ab540356cbb839cbe05303d7705fa', 1);
         if(!$result){
             return message(UsdtWalletService::make()->getError(), false);
         }

+ 74 - 0
app/Http/Controllers/Oapi/LoginController.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Http\Controllers\Oapi;
+
+use App\Http\Validator\MemberValidator;
+use App\Models\ApiModel;
+use App\Services\Api\MemberService;
+use App\Services\Common\ApiService;
+use App\Services\RedisService;
+
+/**
+ * 登陆注册
+ * Class LoginController
+ * @package App\Http\Controllers\Oapi
+ */
+class LoginController extends webApp
+{
+
+
+    /**
+     * 登录
+     */
+    public function login(MemberValidator  $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'login');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        $apiKey = request()->post('api_key','');
+        if(!$apiInfo = ApiService::make()->checkApi($apiKey)){
+            return message(ApiService::make()->getError(), false);
+        }
+
+        $apiId = isset($apiInfo['id'])? $apiInfo['id'] : 0;
+        if($apiId<=0){
+            return message(6002, false);
+        }
+
+        if(!$result = MemberService::make()->apiLogin($apiId,$params)){
+            return message(MemberService::make()->getError(), false);
+        }
+
+        return message(2004, true, $result);
+    }
+
+    public function register(MemberValidator  $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'reg');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        $apiKey = request()->post('api_key','');
+        if(!$apiInfo = ApiService::make()->checkApi($apiKey)){
+            return message(ApiService::make()->getError(), false);
+        }
+
+        $apiId = isset($apiInfo['id'])? $apiInfo['id'] : 0;
+        if($apiId<=0){
+            return message(6002, false);
+        }
+
+        if(!$result = MemberService::make()->apiLogin($apiId,$params)){
+            return message(MemberService::make()->getError(), false);
+        }
+
+        return message(2004, true, $result);
+    }
+
+
+}

+ 21 - 0
app/Http/Controllers/Oapi/TaskController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Controllers\Oapi;
+
+/**
+ * 任务
+ * Class TaskController
+ * @package App\Http\Controllers\Oapi
+ */
+class TaskController extends webApp
+{
+
+    /**
+     *
+     */
+    public function catchTradeNotify()
+    {
+
+    }
+
+}

+ 21 - 0
app/Http/Controllers/Oapi/TradeController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Controllers\Oapi;
+
+/**
+ * 交易
+ * Class TradeController
+ * @package App\Http\Controllers\Oapi
+ */
+class TradeController extends webApp
+{
+    /**
+     * 交易下单
+     */
+    public function order()
+    {
+
+    }
+
+
+}

+ 21 - 0
app/Http/Controllers/Oapi/WalletController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Controllers\Oapi;
+
+/**
+ * 交易
+ * Class WalletController
+ * @package App\Http\Controllers\Oapi
+ */
+class WalletController extends webApp
+{
+    /**
+     * 钱包数据
+     */
+    public function order()
+    {
+
+    }
+
+
+}

+ 128 - 0
app/Http/Controllers/Oapi/webApp.php

@@ -0,0 +1,128 @@
+<?php
+// +----------------------------------------------------------------------
+// | Laravel框架 [ Laravel ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 Laravel研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: wesmiler <12345678@qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Http\Controllers\Oapi;
+
+use App\Helpers\Jwt;
+use App\Http\Controllers\BaseController;
+use App\Models\ApiModel;
+use App\Services\Api\MemberService;
+use App\Services\ConfigService;
+use App\Services\RedisService;
+
+/**
+ * 控制器基类
+ * @since 2020/11/10
+ * Class BaseController
+ * @package App\Http\Controllers
+ */
+class webApp extends BaseController
+{
+    // 模型
+    protected $model;
+    // 服务
+    protected $service;
+    // 校验
+    protected $validate;
+    // 登录ID
+    protected $userId = 0;
+
+    // 所属接口平台ID
+    protected $apiId = 0;
+
+    // 登录信息
+    protected $userInfo = [];
+
+    /**
+     * 构造函数
+     * @author wesmiler
+     * @since 2020/11/10
+     * Backend constructor.
+     */
+    public function __construct()
+    {
+
+        parent::__construct();
+
+        // 初始化分页参数
+        $this->initConfig();
+
+        // 登录检测中间件
+        $this->middleware('api.login');
+
+        // 初始化登录信息
+        $this->middleware(function ($request, $next) {
+            // 请求头信息
+            $token = $request->all('token');
+            $tokenData = RedisService::get("apis:tokens:{$token}");
+            $userId = isset($tokenData['id'])? $tokenData['id'] : 0;
+
+            // 请求频率限制
+            $clientIp = get_client_ip();
+            $ipStr = str_replace('.', '_', $clientIp);
+            $cacheKey = "apis:request:temp:{$ipStr}";
+            $requestCount = RedisService::get($cacheKey);
+            $requestCount = $requestCount? $requestCount : 0;
+            if($requestCount >= 10){
+                return message(1028, false, null, 403);
+            }
+
+            // 登录验证
+            $userInfo = RedisService::get("apis:auths:info:{$userId}");
+            if(empty($userInfo) && $userId){
+                $this->initLogin($userId);
+            }else{
+                $this->userId = $userId;
+                $this->userInfo = $userInfo;
+                $this->apiId = isset($userInfo['api_id'])? $userInfo['api_id'] : 0;
+            }
+
+            RedisService::set($cacheKey, $requestCount+1, rand(1,2));
+            return $next($request);
+        });
+    }
+
+    /**
+     * 初始化配置
+     * @author laravel开发员
+     * @since 2020/11/10
+     */
+    public function initConfig()
+    {
+        // 请求参数
+        $this->param = \request()->input();
+
+        // 分页基础默认值
+        defined('PERPAGE') or define('PERPAGE', isset($this->param['limit']) ? $this->param['limit'] : 20);
+        defined('PAGE') or define('PAGE', isset($this->param['page']) ? $this->param['page'] : 1);
+    }
+
+    /**
+     * 登录验证
+     * @param $userId 用户ID
+     * @return
+     * @author wesmiler
+     * @since 2020/8/31
+     */
+    public function initLogin($userId)
+    {
+        // 登录用户ID
+        $this->userId = $userId;
+
+        // 登录用户信息
+        if ($userId) {
+            $userInfo = MemberService::make()->getInfo($this->userId);
+            $this->userInfo = $userInfo;
+            $this->apiId = isset($userInfo['api_id'])? $userInfo['api_id'] : 0;
+            RedisService::set("apis:auths:info:{$userId}", $this->userInfo, 4*24*3600);
+        }
+    }
+}

+ 40 - 0
app/Http/Middleware/ApiLogin.php

@@ -0,0 +1,40 @@
+<?php
+
+
+namespace App\Http\Middleware;
+use App\Services\RedisService;
+use Closure;
+use Illuminate\Auth\Middleware\Authenticate as Middleware;
+
+class ApiLogin extends Middleware
+{
+    /**
+     * 执行句柄
+     * @param \Illuminate\Http\Request $request
+     * @param Closure $next
+     * @param mixed ...$guards
+     * @return mixed
+     * @throws \Illuminate\Auth\AuthenticationException
+     * @since 2020/8/31
+     * @author wesmiler
+     */
+    public function handle($request, Closure $next, ...$guards)
+    {
+        $response = $next($request);
+        $action = app('request')->route()->getAction();
+        $controller = class_basename($action['controller']);
+        list($controller, $action) = explode('@', $controller);
+        $noLoginActs = ['LoginController','TestController','TaskController'];
+        $token = $request->all('token');
+        $tokenData = RedisService::get("apis:tokens:{$token}");
+        $userId = isset($tokenData['id'])? $tokenData['id'] : 0;
+
+        if (!$userId && !in_array($controller, $noLoginActs)) {
+            // 在这里可以定制你想要的返回格式, 亦或者是 JSON 编码格式
+            return response()->json(message(1004, false, null, 403));
+        }
+
+        //如果已登录则执行正常的请求
+        return $response;
+    }
+}

+ 160 - 1
app/Services/ChatMessageService.php

@@ -63,6 +63,165 @@ class ChatMessageService extends BaseService
     }
 
     /**
+     * 获取列表
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1,'a.status'=>1];
+        $type = isset($params['type'])? $params['type'] : 1;
+        $chatKey = isset($params['chat_key'])? $params['chat_key'] : '';
+        $fromUid = isset($params['from_uid'])? $params['from_uid'] : 0;
+        $toUid = isset($params['to_uid'])? $params['to_uid'] : 0;
+        $orderNo = isset($params['order_no'])? $params['order_no'] : '';
+        if($type>0){
+            $where['a.type'] = $type;
+        }
+        if($chatKey){
+            $where['a.chat_key'] = $chatKey;
+        }
+        if($fromUid>0){
+            $where['a.from_uid'] = $fromUid;
+        }
+        if($toUid>0){
+            $where['a.to_uid'] = $toUid;
+        }
+        if($orderNo){
+            $where['a.order_no'] = $orderNo;
+        }
+        $list = $this->model->from('chat_message as a')
+            ->leftJoin('member as m', 'm.id', '=', 'a.from_uid')
+            ->leftJoin('member as m1', 'm1.id', '=', 'a.to_uid')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $id = isset($params['id'])? $params['id'] : 0;
+                if($id>0){
+                    $query->where('id','<', $id);
+                }
+            })
+            ->where(function ($query) use($params){
+                $userId = isset($params['user_id'])? $params['user_id'] : 0;
+                if($userId){
+                    $query->where('a.from_uid','=',$userId)->orWhere('a.to_uid','=', $userId);
+                }
+
+            })
+            ->select(['a.*', 'm.username as from_username','m.avatar as from_avatar','m1.username as to_username','m1.avatar as to_avatar'])
+            ->orderBy('a.create_time','desc')
+            ->orderBy('a.id','desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach($list['data'] as &$item){
+                $item['from_username_text'] = $item['from_username']? format_account($item['from_username']):'客服';
+                $item['to_username_text'] = $item['to_username']? format_account($item['to_username']):'客服';
+                $item['message_url'] = $item['message_type']==2? get_image_url($item['message']):'';
+                $item['from_avatar'] = $item['from_avatar']? get_image_url($item['from_avatar']):'';
+                $item['to_avatar'] = $item['to_avatar']? get_image_url($item['to_avatar']):'';
+                $item['time_text'] = $item['create_time']? format_time(strtotime($item['create_time'])):'刚刚';
+                $userId = isset($params['user_id'])? $params['user_id'] : 0;
+                if($userId == $item['to_uid']){
+                    // 已读
+                    $this->model->where(['id'=> $item['id']])->update(['is_read'=>1,'update_time'=> time()]);
+                }
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    public function getNewList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1,'status'=>1];
+        $type = isset($params['type'])? $params['type'] : 1;
+        $chatKey = isset($params['chat_key'])? $params['chat_key'] : '';
+        $fromUid = isset($params['from_uid'])? $params['from_uid'] : 0;
+        $toUid = isset($params['to_uid'])? $params['to_uid'] : 0;
+        $orderNo = isset($params['order_no'])? $params['order_no'] : '';
+        if($type>0){
+            $where['a.type'] = $type;
+        }
+        if($chatKey){
+            $where['a.chat_key'] = $chatKey;
+        }
+        if($fromUid>0){
+            $where['a.from_uid'] = $fromUid;
+        }
+        if($toUid>0){
+            $where['a.to_uid'] = $toUid;
+        }
+        if($orderNo){
+            $where['a.order_no'] = $orderNo;
+        }
+        $list = $this->model->from('chat_message as a')
+            ->leftJoin('member as m', 'm.id', '=', 'a.from_uid')
+            ->leftJoin('member as m1', 'm1.id', '=', 'a.to_uid')
+            ->where($where)
+            ->where(function ($query) use($params){
+                $userId = isset($params['user_id'])? $params['user_id'] : 0;
+                if($userId){
+                    $query->where('a.from_uid','=',$userId)->orWhere('a.to_uid','=', $userId);
+                }
+
+            })
+            ->select(['a.id', 'a.from_uid','a.to_uid','a.type','a.chat_key','a.order_no','a.create_time', 'm.username as from_username','m.avatar as from_avatar','m1.username as to_username','m1.avatar as to_avatar'])
+            ->groupBy('a.chat_key')
+            ->orderBy('a.create_time','desc')
+            ->orderBy('a.id','desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list? $list->toArray() :[];
+        if($list){
+            foreach($list['data'] as &$item){
+                $item['from_username_text'] = $item['from_username']? format_account($item['from_username']):'客服';
+                $item['to_username_text'] = $item['to_username']? format_account($item['to_username']):'客服';
+                $item['from_avatar'] = $item['from_avatar']? get_image_url($item['from_avatar']):'';
+                $item['to_avatar'] = $item['to_avatar']? get_image_url($item['to_avatar']):'';
+                $item['time_text'] = $item['create_time']? format_time(strtotime($item['create_time'])):'刚刚';
+                $item['info'] = $this->getTempInfo($item['chat_key']);
+            }
+        }
+
+        return [
+            'pageSize'=> $pageSize,
+            'total'=>isset($list['total'])? $list['total'] : 0,
+            'list'=> isset($list['data'])? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 获取最新的聊天消息
+     * @param $chatKey 聊天窗口标识
+     * @return array|mixed
+     */
+    public function getTempInfo($chatKey)
+    {
+        $cacheKey = "caches:chats:temp:{$chatKey}";
+        $info = RedisService::get($cacheKey);
+        if($info){
+            return $info;
+        }
+
+        $info = $this->model->where(['chat_key'=> $cacheKey,'status'=>1,'mark'=>1])
+                ->select(['id','message','is_read','message_type','create_time'])
+                ->orderBy('create_time','desc')
+                ->orderBy('id','desc')
+                ->first();
+        if($info){
+            $info['message_url'] = $info['message_type']==2? get_image_url($info['message']):'';
+            $info['time_text'] = $info['create_time']? format_time(strtotime($info['create_time'])):'刚刚';
+            RedisService::set($cacheKey, $info, rand(3,5));
+        }
+
+        return $info;
+    }
+
+    /**
      * 添加或编辑
      * @return array
      */
@@ -84,7 +243,7 @@ class ChatMessageService extends BaseService
             'mark'=> 1,
         ];
 
-        return parent::edit($data); // TODO: Change the autogenerated stub
+        return $this->model->insertGetId($data);
     }
 
     /**

+ 1 - 0
app/Services/Common/AdvertOrderService.php

@@ -136,6 +136,7 @@ class AdvertOrderService extends BaseService
                 $item['overtime_text'] = in_array($item['status'], [1, 2]) && $overTime ? date('H:i', $overTime) : '';
                 $payType = isset($item['pay_type']) ? $item['pay_type'] : 0;
                 $item['pay_name'] = isset($payTypes[$payType]) ? $payTypes[$payType] : '其他';
+                $item['chat_key'] = getChatKey($item['user_id'],$item['business_id']);
             }
         }
 

+ 57 - 0
app/Services/Common/ApiService.php

@@ -14,6 +14,7 @@ namespace App\Services\Common;
 use App\Models\AdModel;
 use App\Models\ApiModel;
 use App\Services\BaseService;
+use App\Services\RedisService;
 
 /**
  * 接口管理-服务类
@@ -76,4 +77,60 @@ class ApiService extends BaseService
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
 
+    /**
+     * 验证接口
+     * @param $apiKey
+     * @return false
+     */
+    public function checkApi($apiKey)
+    {
+        if(empty($apiKey)){
+            $this->error = '6001';
+            return false;
+        }
+
+        $cachekey = "apis:apiKeys:{$apiKey}";
+        $info = RedisService::get($cachekey);
+        if(empty($info)){
+            $info = ApiModel::where(['api_key'=> $apiKey,'status'=> 1,'mark'=>1])
+                ->select(['id','username','user_limits','expired_at'])
+                ->first();
+            if(empty($info)){
+                $this->error = '6002';
+                return false;
+            }
+
+            // 接口是否已到期
+            $expiredAt = isset($info['expired_at']) && $info['expired_at']? strtotime($info['expired_at']) : 0;
+            if($expiredAt && $expiredAt<= time()){
+                $this->error = '6003';
+                return false;
+            }
+        }
+
+        return $info;
+    }
+
+    /**
+     * 获取详情
+     * @param $id
+     * @return mixed
+     */
+    public function getInfo($id, $refresh = false)
+    {
+        $cachekey = "caches:apis:info:{$id}";
+        $info = RedisService::get($cachekey);
+        if($info && !$refresh){
+            return $info;
+        }
+        $info = ApiModel::where(['id'=> $id,'status'=> 1,'mark'=>1])
+            ->select(['id','username','notify_url','user_limits','expired_at'])
+            ->first();
+        if($info){
+            $info['user_limits'] = $info['user_limits']? explode(',', $info['user_limits']) : [];
+            RedisService::set($cachekey, $info, 30);
+        }
+
+        return $info;
+    }
 }

+ 11 - 1
app/Services/Common/CoinLogService.php

@@ -71,6 +71,8 @@ class CoinLogService extends BaseService
         $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;
+        $from = isset($params['from'])? $params['from'] : '';
+        $to = isset($params['to'])? $params['to'] : '';
         if($type>0){
             $where['a.type'] = $type;
         }
@@ -90,6 +92,14 @@ class CoinLogService extends BaseService
             $where['a.user_id'] = $userId;
         }
 
+        if($from){
+            $where['a.from_address'] = $from;
+        }
+
+        if($to){
+            $where['a.to_address'] = $to;
+        }
+
         $list = $this->model->from('coin_logs as a')
             ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
             ->where($where)
@@ -166,7 +176,7 @@ class CoinLogService extends BaseService
         }
 
         $data = $this->model->where(['txid' => $txid])
-            ->select(['id', 'user_id','order_no', 'num','free', 'coin_type', 'balance', 'change_type', 'status'])
+            ->select(['id', 'user_id','order_no', 'num','free', 'coin_type', 'balance','contact_type', 'change_type', 'status'])
             ->first();
         if($data){
             RedisService::set($cacheKey, $data, rand(3,5));

+ 1 - 0
app/Services/Common/TradeOrderService.php

@@ -139,6 +139,7 @@ class TradeOrderService extends BaseService
                 $item['overtime_text'] = in_array($item['status'], [1, 2]) && $overTime ? date('H:i', $overTime) : '';
                 $payType = isset($item['pay_type']) ? $item['pay_type'] : 0;
                 $item['pay_name'] = isset($payTypes[$payType]) ? $payTypes[$payType] : '其他';
+                $item['chat_key'] = getChatKey($item['user_id'],$item['business_id']);
             }
         }
 

Разница между файлами не показана из-за своего большого размера
+ 718 - 344
app/Services/UsdtWalletService.php


Разница между файлами не показана из-за своего большого размера
+ 1318 - 0
app/Services/UsdtWalletService_back.php