浏览代码

Wesmiler OTC 提交更新 0729

APPLE 3 年之前
父节点
当前提交
8385a7d995
共有 2 个文件被更改,包括 321 次插入52 次删除
  1. 31 4
      app/Http/Controllers/Admin/AdvertOrderController.php
  2. 290 48
      app/Services/Common/AdvertOrderService.php

+ 31 - 4
app/Http/Controllers/Admin/AdvertOrderController.php

@@ -114,7 +114,12 @@ class AdvertOrderController extends Backend
      */
     public function businessPay()
     {
-        return returnJson(1002);
+        $params = request()->post();
+        if(!AdvertOrderService::make()->businessPay($this->userInfo['user_id'], $params)){
+            return returnJson(AdvertOrderService::make()->getError(), false);
+        }else{
+            return returnJson(AdvertOrderService::make()->getError(), true);
+        }
     }
 
     /**
@@ -144,7 +149,18 @@ class AdvertOrderController extends Backend
      */
     public function businessCollection()
     {
-        return returnJson(1002);
+        $params = request()->post();
+        // 平台处理则无币商参数
+        $businessId = $this->userInfo['user_id'];
+        if($this->userInfo['user_type'] == 1){
+            $params['catch_uid'] = $this->userId;
+            $businessId = 0;
+        }
+        if(!AdvertOrderService::make()->businessCollection($businessId, $params)){
+            return returnJson(AdvertOrderService::make()->getError(), false);
+        }else{
+            return returnJson(AdvertOrderService::make()->getError(), true);
+        }
     }
 
     /**
@@ -158,8 +174,19 @@ class AdvertOrderController extends Backend
     /**
      * 订单取消(交易员或平台操作)
      */
-    public function cancel()
+    public function businessCancel()
     {
-
+        $params = request()->post();
+        // 平台处理则无币商参数
+        $businessId = $this->userInfo['user_id'];
+        if($this->userInfo['user_type'] == 1){
+            $params['catch_uid'] = $this->userId;
+            $businessId = 0;
+        }
+        if(!TradeOrderService::make()->businessCancel($businessId,$params)){
+            return returnJson(TradeOrderService::make()->getError(), false);
+        }else{
+            return returnJson(TradeOrderService::make()->getError(), true);
+        }
     }
 }

+ 290 - 48
app/Services/Common/AdvertOrderService.php

@@ -645,6 +645,79 @@ class AdvertOrderService extends BaseService
     }
 
     /**
+     * 商家订单打款处理
+     * @param $userId 用户ID
+     * @param $params 打款参数
+     * @return false
+     */
+    public function businessPay($businessId, $params)
+    {
+        $orderId = isset($params['id']) ? $params['id'] : 0;
+        if ($orderId <= 0) {
+            $this->error = '1013';
+            return false;
+        }
+
+        $orderInfo = $this->model->where(['business_id' => $businessId, 'id' => $orderId, 'mark' => 1, 'type' => 2])
+            ->whereIn('status', [1, 2, 5, 7])
+            ->select(['id', 'user_id', 'order_no', 'business_id', 'type', 'payment_id', 'num', 'total', 'status'])
+            ->first();
+        $tradeType = isset($orderInfo['type']) ? $orderInfo['type'] : 0;
+        if (empty($orderInfo)) {
+            $this->error = '3016';
+            return false;
+        }
+        if ($tradeType != 2) {
+            $this->error = '3025';
+            return false;
+        }
+
+        // 用户信息
+        $userInfo = MemberService::make()->getInfo($businessId);
+        $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
+        $username = isset($userInfo['username']) ? $userInfo['username'] : 0;
+        if ($status != 1) {
+            $this->error = '2009';
+            return false;
+        }
+
+        // 交易密码
+        $tradePassword = isset($params['trade_password']) ? trim($params['trade_password']) : '';
+        $password = isset($userInfo['trade_password']) ? trim($userInfo['trade_password']) : '';
+        if (empty($password)) {
+            $this->error = '2015';
+            return false;
+        }
+
+        if (!$tradePassword || get_password($tradePassword . md5($tradePassword . 'otc')) != $password) {
+            $this->error = '2016';
+            return false;
+        }
+
+        if (strpos($params['pay_img'], "temp")) {
+            $params['pay_img'] = save_image($params['pay_img'], 'images');
+        } else {
+            $params['pay_img'] = str_replace(IMG_URL, "", $params['pay_img']);
+        }
+
+        $data = [
+            'status' => 3,
+            'pay_type' => $params['pay_type'],
+            'pay_img' => $params['pay_img'],
+            'pay_remark' => $params['pay_remark'],
+            'pay_time' => time(),
+        ];
+
+        if (!$this->model->where(['business_id' => $businessId, 'id' => $orderId, 'mark' => 1])->update($data)) {
+            $this->error = '3018';
+            return false;
+        }
+
+        $this->error = '3017';
+        return true;
+    }
+
+    /**
      * 订单确认处理
      * @param $userId 用户ID
      * @param $params 打款参数
@@ -865,7 +938,7 @@ class AdvertOrderService extends BaseService
         }
 
         // 交易处理,如果是确认状态
-        if ($orderInfo['num'] > 0 && $status == 4 && $userId > 0 && $tradeType == 1) {
+        if ($orderInfo['num'] > 0 && $status == 4 && $userId > 0) {
 
             $info = $this->memberModel->where(['id' => $userId, 'status' => 1, 'mark' => 1])->select(['id', 'username', 'usdt_num', 'user_type'])->first();
             if (empty($info)) {
@@ -888,6 +961,7 @@ class AdvertOrderService extends BaseService
                 'user_id' => $userId,
                 'type' => 1,
                 'pay_type' => 1,
+                'trade_type' => 2,
                 'change_type' => 1,
                 'num' => $orderInfo['num'],
                 'total' => $orderInfo['total'],
@@ -927,58 +1001,12 @@ class AdvertOrderService extends BaseService
                 }
             }
         }
-        // 外来平台需要出币和回调通知
-        else if(in_array($tradeType, [2,3])){
-            $usdtAddress = isset($orderInfo['usdt_address'])? $orderInfo['usdt_address'] : '';
-            $contactType = isset($orderInfo['contact_type'])? $orderInfo['contact_type'] : '';
-            $notifyUrl = isset($orderInfo['notify_url'])? $orderInfo['notify_url'] : '';
-            if($usdtAddress && $contactType && $notifyUrl){
-                // TRC 出币
-                if($contactType == 1 && !$result = UsdtWalletService::make()->usdtTrcTransfer($usdtAddress,$orderInfo['num'])){
-                    $this->model->rollBack();
-                    $this->error = '3045';
-                    return false;
-                }
-                // ERC 出币
-                else if($contactType == 2 && !$result = UsdtWalletService::make()->usdtErcTransfer($usdtAddress,$orderInfo['num'])){
-                    $this->model->rollBack();
-                    $this->error = '3045';
-                    return false;
-                }
-
-
-                // 更新出币数据和发送回调
-                $txid = isset($result['txID'])? $result['txID'] : '';
-                if($txid) {
-                    if (!$this->model->where($where)->update(['txid' => $txid, 'notify_num' => 1, 'notify_time' => date('Y-m-d H:i:s')])) {
-                        $this->model->rollBack();
-                        $this->error = '3045';
-                        return false;
-                    }
-
-                    // 发送回调通知
-                    $notifyData = [
-                        'transaction_id' => $orderInfo['order_no'],
-                        'order_no' => $orderInfo['pt_order_no'],
-                        'usdt' => $orderInfo['num'],
-                        'amount' => $orderInfo['total'],
-                        'contact_type' => $orderInfo['contact_type'],
-                        'usdt_address' => $orderInfo['usdt_address'],
-                        'hash' => $txid,
-                        'status'=> 1,
-                        'pay_time'=> $orderInfo['pay_time']? $orderInfo['pay_time'] : time(),
-                        'trade_time'=> time(),
-                    ];
-
-                    \App\Services\Oapi\TradeOrderService::make()->notify($notifyUrl, $notifyData);
-                }
-            }
-        }
 
         $this->model->commit();
         $this->error = $status == 5 ? 3032 : 3021;
         return true;
     }
+
     /**
      * 取消订单
      * @param $userId
@@ -1119,6 +1147,220 @@ class AdvertOrderService extends BaseService
     }
 
     /**
+     * 取消订单
+     * @param $businessId 币商用户,平台为0
+     * @param $params
+     * @return false
+     */
+    public function businessCancel($businessId, $params)
+    {
+        $orderId = isset($params['id']) ? intval($params['id']) : 0;
+        $catchUid = isset($params['catch_uid']) ? intval($params['catch_uid']) : 0;
+        if ($orderId <= 0) {
+            $this->error = '1013';
+            return false;
+        }
+
+        $where = ['id' => $orderId, 'mark' => 1];
+        if ($businessId) {
+            $where['business_id'] = $businessId;
+        }
+
+        $orderInfo = $this->model->where($where)
+            ->select(['id', 'user_id', 'order_no', 'business_id', 'type', 'num', 'total', 'status'])
+            ->first();
+
+        $tradeType = isset($orderInfo['type']) ? $orderInfo['type'] : 0;
+        $userId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0;
+        $orderBusinessId = isset($orderInfo['business_id']) ? $orderInfo['business_id'] : 0;
+        if (empty($orderInfo) || $orderBusinessId <= 0) {
+            $this->error = '3016';
+            return false;
+        }
+
+        if (empty($userId)) {
+            $this->error = '3019';
+            return false;
+        }
+
+        if ($orderInfo['status'] == 4) {
+            $this->error = '3028';
+            return false;
+        }
+
+        if (!in_array($orderInfo['status'], [1, 2, 3, 5, 7])) {
+            $this->error = '3029';
+            return false;
+        }
+
+        // 用户信息
+        $status = isset($params['status']) ? $params['status'] : 8;
+        if ($businessId > 0 && $status != 8) {
+            $userInfo = MemberService::make()->getInfo($businessId);
+            $status = isset($userInfo['status']) ? $userInfo['status'] : 0;
+            $username = isset($userInfo['username']) ? $userInfo['username'] : 0;
+            if ($status != 1) {
+                $this->error = '2009';
+                return false;
+            }
+
+            // 交易密码
+            $tradePassword = isset($params['trade_password']) ? trim($params['trade_password']) : '';
+            $password = isset($userInfo['trade_password']) ? trim($userInfo['trade_password']) : '';
+            if (empty($password)) {
+                $this->error = '2015';
+                return false;
+            }
+
+            if (!$tradePassword || get_password($tradePassword . md5($tradePassword . 'otc')) != $password) {
+                $this->error = '2016';
+                return false;
+            }
+        }
+
+        $this->model->startTrans();
+        // 订单状态更新,或异常处理
+
+        $updateData = ['status' => $status, 'exception_catch_user' => $catchUid, 'update_time' => time(), 'exception_remark' => '交易员取消'];
+
+        // 异常处理数据
+        if (isset($params['exception_type'])) {
+            $updateData['exception_type'] = intval($params['exception_type']);
+        }
+        if (isset($params['exception_sub_type'])) {
+            $updateData['exception_sub_type'] = intval($params['exception_sub_type']);
+        }
+        if (isset($params['exception_img'])) {
+            $updateData['exception_img'] = trim($params['exception_img']);
+            if (strpos($updateData['exception_img'], "temp")) {
+                $updateData['exception_img'] = save_image($updateData['exception_img'], 'images');
+            } else {
+                $updateData['exception_img'] = str_replace(IMG_URL, "", $updateData['exception_img']);
+            }
+        }
+
+        if (isset($params['exception_img1'])) {
+            $updateData['exception_img'] = trim($params['exception_img1']);
+            if (strpos($updateData['exception_img1'], "temp")) {
+                $updateData['exception_img1'] = save_image($updateData['exception_img'], 'images');
+            } else {
+                $updateData['exception_img1'] = str_replace(IMG_URL, "", $updateData['exception_img1']);
+            }
+        }
+        if (isset($params['exception_img2'])) {
+            $updateData['exception_img2'] = trim($params['exception_img2']);
+            if (strpos($updateData['exception_img2'], "temp")) {
+                $updateData['exception_img2'] = save_image($updateData['exception_img2'], 'images');
+            } else {
+                $updateData['exception_img2'] = str_replace(IMG_URL, "", $updateData['exception_img2']);
+            }
+        }
+
+        if (isset($params['exception_remark'])) {
+            $updateData['exception_remark'] = trim($params['exception_remark']);
+        }
+        if (isset($params['exception_status'])) {
+            $updateData['exception_status'] = intval($params['exception_status']);
+        }
+        if (isset($params['refund_status'])) {
+            $updateData['refund_status'] = intval($params['refund_status']);
+        }
+        if (isset($params['refund_money'])) {
+            $updateData['refund_money'] = intval($params['refund_money']);
+        }
+
+        if (!$this->model->where($where)->update($updateData)) {
+            $this->model->rollBack();
+            $this->error = '3023';
+            return false;
+        }
+
+        // 出售订单,状态已取消,USDT退回
+        if ($tradeType == 2 && $status == 8 && $orderInfo['num'] > 0) {
+            $info = $this->memberModel->where(['id' => $userId, 'status' => 1, 'mark' => 1])->select(['id', 'username', 'usdt_num', 'user_type'])->first();
+            if (empty($info)) {
+                $this->model->rollBack();
+                $this->error = '3019';
+                return false;
+            }
+
+            // 退还币给客户
+            if (!$this->memberModel->where(['id' => $userId, 'mark' => 1])->increment('usdt_num', $orderInfo['num'])) {
+                $this->model->rollBack();
+                $this->error = '3019';
+                return false;
+            }
+
+            // 明细处理
+            $data = [
+                'order_no' => $orderInfo['order_no'],
+                'user_id' => $userId,
+                'type' => 3,
+                'pay_type' => 1,
+                'trade_type' => 2,
+                'change_type' => 1,
+                'num' => $orderInfo['num'],
+                'total' => $orderInfo['total'],
+                'balance' => floatval($info['usdt_num'] + $orderInfo['num']),
+                'create_time' => time(),
+                'update_time' => time(),
+                'remark' => '交易员取消买入退还',
+                'status' => 1,
+                'mark' => 1,
+            ];
+
+            if (!$this->capitalModel->edit($data)) {
+                $this->error = '3014';
+                $this->model->rollBack();
+                return false;
+            }
+        } // 客户买入订单取消
+        else if ($tradeType == 1 && $status == 8 && $orderInfo['num'] > 0) {
+            $info = $this->memberModel->where(['id' => $orderBusinessId, 'status' => 1, 'mark' => 1])->select(['id', 'username', 'usdt_num', 'user_type'])->first();
+            if (empty($info)) {
+                $this->model->rollBack();
+                $this->error = '3019';
+                return false;
+            }
+
+            // 退还币给客户
+            if (!$this->memberModel->where(['id' => $orderBusinessId, 'mark' => 1])->increment('usdt_num', $orderInfo['num'])) {
+                $this->model->rollBack();
+                $this->error = '3019';
+                return false;
+            }
+
+            // 明细处理
+            $data = [
+                'order_no' => $orderInfo['order_no'],
+                'user_id' => $orderBusinessId,
+                'type' => 3,
+                'trade_type' => 2,
+                'pay_type' => 1,
+                'change_type' => 1,
+                'num' => $orderInfo['num'],
+                'total' => $orderInfo['total'],
+                'balance' => floatval($info['usdt_num'] + $orderInfo['num']),
+                'create_time' => time(),
+                'update_time' => time(),
+                'remark' => '交易员取消卖出退还',
+                'status' => 1,
+                'mark' => 1,
+            ];
+
+            if (!$this->capitalModel->edit($data)) {
+                $this->error = '3014';
+                $this->model->rollBack();
+                return false;
+            }
+        }
+
+        $this->model->commit();
+        $this->error = $status == 5 ? 3032 : 3034;
+        return true;
+    }
+
+    /**
      * 获取未支付或处理的订单数
      * @param $userId
      * @param int $type