Explorar el Código

Wesmiler OTC 提交更新 0729

APPLE hace 3 años
padre
commit
344059d9ea

+ 13 - 1
app/Http/Controllers/Admin/AdvertOrderController.php

@@ -123,7 +123,19 @@ class AdvertOrderController extends Backend
      */
     public function collection()
     {
-        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()->collection($businessId, $params)){
+            return returnJson(TradeOrderService::make()->getError(), false);
+        }else{
+            return returnJson(TradeOrderService::make()->getError(), true);
+        }
     }
 
     /**

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

@@ -20,6 +20,7 @@ use App\Services\BaseService;
 use App\Services\ConfigService;
 use App\Services\ChatMessageService;
 use App\Services\RedisService;
+use App\Services\UsdtWalletService;
 
 /**
  * 用户广告订单-服务类
@@ -138,6 +139,8 @@ class AdvertOrderService extends BaseService
                 $item['username_text'] = $item['username'] ? format_account($item['username']) : '';
                 $item['c_username_text'] = $item['c_username'] ? format_account($item['c_username']) : '';
                 $item['exception_img'] = $item['exception_img'] ? get_image_url($item['exception_img']) : '';
+                $item['exception_img1'] = $item['exception_img1'] ? get_image_url($item['exception_img1']) : '';
+                $item['exception_img2'] = $item['exception_img2'] ? get_image_url($item['exception_img2']) : '';
                 $item['pay_img'] = $item['pay_img'] ? get_image_url($item['pay_img']) : '';
                 $item['paymentData']['qrcode'] = isset($item['paymentData']['qrcode']) && $item['paymentData']['qrcode'] ? get_image_url($item['paymentData']['qrcode']) : '';
 
@@ -729,6 +732,254 @@ class AdvertOrderService extends BaseService
     }
 
     /**
+     * 商家订单确认处理
+     * @param $businessId 币商用户ID,平台处理时为0
+     * @param $params 打款参数
+     * @return false
+     */
+    public function businessCollection($businessId, $params)
+    {
+        $orderId = isset($params['id']) ? $params['id'] : 0;
+        $catchUid = isset($params['catch_uid']) ? $params['catch_uid'] : 0;
+        $type = isset($params['type']) ? $params['type'] : 0;
+        if ($orderId <= 0) {
+            $this->error = '1013';
+            return false;
+        }
+
+        // 平台或币商处理
+        $where = ['id' => $orderId, 'mark' => 1];
+        if ($businessId) {
+            $where['business_id'] = $businessId;
+        }
+        if ($type) {
+            $where['type'] = $type;
+        }
+        $orderInfo = $this->model->where($where)
+            ->select(['id', 'user_id', 'order_no','user_id', 'business_id', 'type', 'num', 'total','pay_time', 'status'])
+            ->first();
+
+        $userId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0;
+        $orderType = isset($orderInfo['type']) ? $orderInfo['type'] : 0;
+        if (empty($orderInfo) || empty($userId)) {
+            $this->error = '3016';
+            return false;
+        }
+
+        $status = isset($params['status']) ? intval($params['status']) : 4;
+        if ($status == 4 && $orderInfo['status'] != 3 && $businessId > 0) {
+            $this->error = '3026';
+            return false;
+        }
+
+        if ($status == 5 && $orderInfo['status'] == 8 && $businessId > 0) {
+            $this->error = '3026';
+            return false;
+        }
+
+        if ($status == 5 && $businessId <= 0 && $orderInfo['status'] == 4) {
+            $this->error = '3026';
+            return false;
+        }
+
+        if ($orderType != 1 && $status != 5) {
+            $this->error = '3024';
+            return false;
+        }
+
+
+        // 用户信息
+        if ($businessId > 0) {
+            $userInfo = MemberService::make()->getInfo($businessId);
+            $userStatus = isset($userInfo['status']) ? $userInfo['status'] : 0;
+            $username = isset($userInfo['username']) ? $userInfo['username'] : 0;
+            if ($userStatus != 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()];
+
+        // 异常处理数据
+        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 (!$this->model->where($where)->update($updateData)) {
+            $this->model->rollBack();
+            $this->error = '3023';
+            return false;
+        }
+
+        // 交易处理,如果是确认状态
+        if ($orderInfo['num'] > 0 && $status == 4 && $userId > 0 && $tradeType == 1) {
+
+            $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' => 1,
+                '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;
+            }
+
+            // 更新收款地址数据
+            $paymentId = isset($orderInfo['payment_id']) ? $orderInfo['payment_id'] : 0;
+            $info = $this->paymentModel->where(['id' => $paymentId, 'mark' => 1])->select(['id', 'used_at'])->first();
+            if ($paymentId && $info) {
+                $usedAt = isset($info['used_at']) ? $info['used_at'] : '';
+                if ($usedAt < date('Y-m-d')) {
+                    if (!$this->paymentModel->where(['id' => $paymentId])->update(['used_num' => 1, 'used_quota' => $orderInfo['total'], 'update_time' => time()])) {
+                        $this->model->rollBack();
+                        $this->error = '3018';
+                        return false;
+                    }
+                } else {
+                    $res1 = $this->paymentModel->where(['id' => $paymentId])->increment('used_num', 1);
+                    $res2 = $this->paymentModel->where(['id' => $paymentId])->increment('used_quota', floatval($orderInfo['total']));
+                    if (!$res1 || !$res2) {
+                        $this->model->rollBack();
+                        $this->error = '3014';
+                        return false;
+                    }
+                }
+            }
+        }
+        // 外来平台需要出币和回调通知
+        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
      * @param $params

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

@@ -154,6 +154,8 @@ class TradeOrderService extends BaseService
                 $item['username_text'] = $item['username'] ? format_account($item['username']) : '';
                 $item['c_username_text'] = $item['c_username'] ? format_account($item['c_username']) : '';
                 $item['exception_img'] = $item['exception_img'] ? get_image_url($item['exception_img']) : '';
+                $item['exception_img1'] = $item['exception_img1'] ? get_image_url($item['exception_img1']) : '';
+                $item['exception_img2'] = $item['exception_img2'] ? get_image_url($item['exception_img2']) : '';
                 $item['pay_img'] = $item['pay_img'] ? get_image_url($item['pay_img']) : '';
                 $item['paymentData']['qrcode'] = isset($item['paymentData']['qrcode']) && $item['paymentData']['qrcode'] ? get_image_url($item['paymentData']['qrcode']) : '';