wesmiler 2 年之前
父節點
當前提交
f09f00b85d

+ 60 - 0
app/Console/Commands/SocketServer.php

@@ -292,6 +292,66 @@ class SocketServer extends Command
                     }
 
                     break;
+                case 'acceptor': // 承兑商
+                    $msgType = isset($data['msg_type']) ? $data['msg_type'] : 1;
+                    $chatType = isset($data['chat_type']) ? $data['chat_type'] : 1;
+                    $message = isset($data['message']) ? trim($data['message']) : '';
+                    $fromUserName = isset($data['from_user_name']) ? trim($data['from_user_name']) : '';
+                    $fromUserAvatar = isset($data['from_user_avatar']) ? trim($data['from_user_avatar']) : '';
+                    $toUserName = isset($data['to_user_name']) ? trim($data['to_user_name']) : '';
+                    $toUserAvatar = isset($data['to_user_avatar']) ? trim($data['to_user_avatar']) : '';
+
+                    // 发送参数验证
+                    if ($toUid <= 0 || $fromUid <= 0 || empty($message) || empty($fromUserName) || empty($toUserName)) {
+                        $this->info("【{$scene} {$date}】Socket:参数错误,from@{$fromUid}-to@{$toUid}。");
+                        $this->sendMsg($frameId, ['success' => false,'op'=>'push','scene'=>$scene,'data'=>$data, 'message' => '参数错误']);
+                        return false;
+                    }
+
+                    $msgData = [
+                        'from_uid' => $fromUid,
+                        'to_uid' => $toUid,
+                        'type' => 9,
+                        'msg_type' => $msgType,
+                        'chat_type' => 3,
+                        'from_user_name' => $fromUserName,
+                        'to_user_name' => $toUserName,
+                        'from_user_avatar' => get_image_path($fromUserAvatar),
+                        'to_user_avatar' => get_image_path($toUserAvatar),
+                        'description' => $msgType == 1 ? mb_substr($message, 0, 20) : '',
+                        'content' => $message,
+                        'goods_id' => isset($data['goods_id'])? intval($data['goods_id']) : 0,
+                        'live_id' => isset($data['live_id'])? intval($data['live_id']) : 0,
+                        'chat_key' => $chatKey,
+                        'create_time' => time(),
+                        'update_time' => time(),
+                        'is_read' => 2,
+                        'status' => 1
+                    ];
+                    if (!$id = MessageModel::insertGetId($msgData)) {
+                        $data = ['success' => false,'op'=>'push','scene'=>$scene,'data'=>$msgData, 'message' => '消息发送失败'];
+                        $this->sendMsg($frameId, $data);
+                        return false;
+                    }
+
+                    // 推送消息给对方
+                    $msgData['from_user_avatar'] = $fromUserAvatar;
+                    $msgData['to_user_avatar'] = $toUserAvatar;
+                    $msgData['content'] = $msgType == 2? get_images_preview(json_decode($msgData['content'],true),'', $apiUrl) : $msgData['content'];
+                    $msgData['time_text'] = dateFormat($msgData['create_time']);
+                    $msgData['goods'] = [];
+                    $msgData['live_info'] = [];
+
+
+                    $this->sendMsg($frameId, ['success' => true, 'op' => 'push', 'scene'=> $scene, 'data' => $msgData, 'message' => '发送成功:' . $frameId]);
+                    $toBindData = RedisService::get("chats:bind:{$scene}_{$toUid}");
+                    $toFd = isset($toBindData['fd']) ? $toBindData['fd'] : 0;
+                    if ($toBindData && $toFd) {
+                        $this->sendMsg($toFd, ['success' => true, 'op' => 'push' ,'scene'=> $scene, 'data' => $msgData, 'message' => '推送消息成功:' . $toFd]);
+                        $this->info("【{$date}】Socket:客户端【{$frameId}-{$fromUid}】推送消息给【{$toFd}-{$toUid}。");
+                    }
+
+                    break;
                 case 'login': // 登录
                     $this->info("【{$scene} {$date}】Socket:登录成功【{$frameId}-{$fromUid}-{$op}】。");
                     $this->sendMsg($frameId, ['success' => true,'op'=> $op, 'scene'=>$scene, 'message' => '登录成功', 'data' => $data, 't' => time()]);

+ 186 - 0
app/Http/Controllers/Api/v1/AcceptorController.php

@@ -0,0 +1,186 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Http\Validator\MemberValidator;
+use App\Http\Validator\MerchantValidator;
+use App\Services\Api\AcceptorService;
+use App\Services\Api\MemberService;
+use App\Services\Api\MerchantCategoryService;
+use App\Services\Api\MerchantService;
+
+/**
+ * 承兑商管理
+ * @package App\Http\Controllers\Api
+ */
+class AcceptorController extends webApp
+{
+    /**
+     * 信息
+     * @return array
+     */
+    public function info()
+    {
+        $type = request()->post('type', 'detail');
+        $id = request()->post('id', 0);
+        $info = AcceptorService::make()->getInfo($this->userId, $type, $id);
+        if($info){
+            return showJson(1010, true, $info);
+        }else{
+            return showJson(2216, false, [],'404');
+        }
+    }
+
+
+    /**
+     * 商家列表
+     * @return array
+     */
+    public function index()
+    {
+        $params = request()->post();
+        $pageSize = request()->post('pageSize', 6);
+        $datas = AcceptorService::make()->getDataList($params, $pageSize);
+        return showJson(1010, true, $datas);
+    }
+
+
+    /**
+     * 申请入驻
+     * @return array
+     */
+    public function apply(MerchantValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'apply');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!$result = MerchantService::make()->apply($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(), false);
+        }else{
+            return showJson(MerchantService::make()->getError(), true, $result);
+        }
+    }
+
+
+    /**
+     * 入驻信息
+     * @return array
+     */
+    public function applyInfo()
+    {
+        $info = MerchantService::make()->getApplyInfo($this->userId);
+        if($info){
+            return showJson(1010, true, $info);
+        }else{
+            return showJson(1009, false);
+        }
+
+    }
+
+
+    /**
+     * 修改账号信息
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function modify(MerchantValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'modify');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!MerchantService::make()->modify($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(),false);
+        }else{
+            return showJson(MerchantService::make()->getError(),true);
+        }
+    }
+
+    /**
+     * 修改店铺信息
+     * @param $userId
+     * @param $params
+     * @return bool
+     */
+    public function saveInfo(MemberValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'info');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!MerchantService::make()->saveInfo($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(),false);
+        }else{
+            return showJson(MerchantService::make()->getError(),true);
+        }
+    }
+
+    /**
+     * 收藏点赞
+     * @param MerchantValidator $validator
+     * @return array
+     */
+    public function collect(MerchantValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'collect');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!$result = MerchantService::make()->collect($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(), false);
+        }else{
+            return showJson(MerchantService::make()->getError(), true, $result);
+        }
+    }
+
+    /**
+     * 缴纳保证金
+     * @param MemberValidator $validator
+     * @return array
+     */
+    public function deposit(MemberValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'deposit');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!$result = MerchantService::make()->deposit($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(),false);
+        }else{
+            return showJson(MerchantService::make()->getError(),true, $result);
+        }
+    }
+
+    /**
+     * 退还保证金
+     * @param MemberValidator $validator
+     * @return array
+     */
+    public function rebackDeposit(MemberValidator $validator)
+    {
+        $params = request()->all();
+        $params = $validator->check($params, 'reback_deposit');
+        if (!is_array($params)) {
+            return showJson($params, false);
+        }
+
+        if(!$result = MerchantService::make()->rebackDeposit($this->userId, $params)){
+            return showJson(MerchantService::make()->getError(),false);
+        }else{
+            return showJson(MerchantService::make()->getError(),true);
+        }
+    }
+}

+ 58 - 0
app/Http/Validator/AcceptorValidator.php

@@ -0,0 +1,58 @@
+<?php
+namespace App\Http\Validator;
+class MerchantValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'realname' => 'required|max:30',
+        'name' => 'required|max:30',
+        'pay_type' => 'required',
+        'status' => 'required',
+    ];
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+        'mobile' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'name' => '商家名称',
+        'logo' => '商家logo',
+        'type' => '商家类别',
+        'category_id' => '行业类目',
+        'service_time' => '营业时间',
+        'country' => '商家所在国家',
+        'city' => '商家所在城市',
+        'address' => '商家所在地址',
+        'mobile' => '联系方式',
+        'currency' => '交易货币',
+        'business_img' => '店铺营业执照',
+        'status' => '状态',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'modify'=> ['name','logo','type','country','city','business_img','service_time','currency'],
+        'apply'=> ['name','logo','type','country','city','business_img','service_time','currency'],
+
+    ];
+
+    /**
+     * 验证
+     * @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);
+    }
+}

+ 22 - 14
app/Services/Api/AcceptorService.php

@@ -94,6 +94,11 @@ class AcceptorService extends BaseService
                     $query->where('a.status', $status);
                 }
 
+                $payType = isset($params['pay_type']) && $params['pay_type'] >0 ? intval($params['pay_type']) : 0;
+                if($payType){
+                    $query->where('a.pay_type', $payType);
+                }
+
             })
             ->selectRaw($field)
             ->orderByRaw($order)
@@ -102,10 +107,15 @@ class AcceptorService extends BaseService
         $datas = $datas ? $datas->toArray() : [];
         if ($datas) {
             $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
+            $xdBuyPrice = ConfigService::make()->getConfigByCode('trade_buy_price_rate', 0);
+            $xdBuyPrice = $xdBuyPrice>0 && $xdBuyPrice<100? $xdBuyPrice : 0;
+            $xdSellPrice = ConfigService::make()->getConfigByCode('trade_sell_price_rate', 0);
+            $xdSellPrice = $xdSellPrice>0 && $xdSellPrice<100? $xdSellPrice : 0;
 
             foreach ($datas['data'] as &$item) {
-                $item['logo'] = $item['logo'] ? get_image_url($item['logo']) : '';
-                $item['xd_price'] = max(10000, moneyFormat($xdPrice + ($xdPrice * $item['price_float'] / 100), 2));
+                $item['avatar'] = $item['avatar'] ? get_image_url($item['avatar']) : '';
+                $item['xd_buy_price'] = max(10000, moneyFormat($xdPrice + ($xdPrice * $xdBuyPrice / 100), 2));
+                $item['xd_sell_price'] = max(10000, moneyFormat($xdPrice - ($xdPrice * $xdSellPrice / 100), 2));
                 $item['usdt_price'] = moneyFormat(1 / $item['xd_price'], 2);
             }
             unset($item);
@@ -120,26 +130,24 @@ class AcceptorService extends BaseService
     }
 
     /**
-     * 获取缓存信息
+     * 获取信息
      * @param $where
      * @param array $field
-     * @param int $expired
      * @return array|mixed
      */
-    public function getCacheInfo($where, $field = [], $expired = 0)
+    public function getInfo($id, $field = [])
     {
-        $cacheKey = "caches:acceptor:info:cache_" . md5(json_encode($where, 256) . json_encode($field, 256) . $expired);
-        $info = RedisService::get($cacheKey);
-        if ($info) {
-            return $info;
-        }
-
-        $defaultField = ['id', 'user_id', 'realname', 'mobile', 'quota', 'usdt', 'status'];
+        $defaultField = ['a.id', 'a.user_id', 'a.realname','a.name', 'a.mobile','a.telegram', 'a.quota','a.pay_type', 'a.usdt', 'a.status','b.nickname','b.avatar'];
         $field = $field ? $field : $defaultField;
-        $info = $this->model->where($where)->where('mark', 1)->select($field)->first();
+        $info = $this->model->from('acceptor as a')
+            ->leftjoin('member as b','b.id','=','a.user_id')
+            ->where(['a.id'=> $id,'a.mark'=>1])
+            ->select($field)
+            ->first();
         $info = $info ? $info->toArray() : [];
         if ($info) {
-            RedisService::set($cacheKey, $info, $expired ? $expired : rand(3, 5));
+
+            $info['avatar'] = get_image_url($info['avatar']);
         }
 
         return $info;

+ 3 - 0
routes/api.php

@@ -168,6 +168,9 @@ Route::prefix('v1')->group(function(){
     Route::post('/order/track', [\App\Http\Controllers\Api\v1\OrderController::class, 'track']);
     Route::post('/order/after', [\App\Http\Controllers\Api\v1\OrderController::class, 'after']);
 
+    // 承兑商
+    Route::match(['get','post'],'/acceptor/index', [\App\Http\Controllers\Api\v1\AcceptorController::class, 'index']);
+    Route::match(['get','post'],'/acceptor/info', [\App\Http\Controllers\Api\v1\AcceptorController::class, 'info']);
 
     // 承兑商交易
     Route::match(['get','post'],'/trade/sell', [\App\Http\Controllers\Api\v1\TradeController::class, 'sell']);