Wang Chen 4 年之前
父節點
當前提交
fb06b8ac6d

+ 1 - 0
app/Consts/ErrorConst.php

@@ -44,4 +44,5 @@ class ErrorConst
     const ACTIVITY_NOT_FOUND                = '20001:查询不到相关活动';
     const ACTIVITY_NOT_START                = '20002:活动还未开始';
     const ACTIVITY_IS_END                   = '20003:活动已经结束';
+    const ACTIVITY_INVALID                  = '20004:无效的活动';
 }

+ 14 - 3
app/Http/Controllers/QuickApp/Activity/ActivityController.php

@@ -9,7 +9,9 @@ use App\Libs\Utils;
 use App\Modules\Activity\Services\ActivityService;
 use App\Modules\Channel\Services\ChannelService;
 use App\Modules\Product\Services\ProductService;
+use App\Modules\SendOrder\Models\QuickAppSendOrder;
 use App\Modules\Subscribe\Services\OrderService;
+use App\Modules\User\Models\QappChannelAccount;
 use Illuminate\Http\Request;
 use App\Http\Controllers\QuickApp\BaseController;
 use Redis;
@@ -195,12 +197,21 @@ class ActivityController extends BaseController
         $channelId  = (int)$this->distribution_channel_id;
         $activity   = ActivityService::getByToken($token);
         $activityId = getProp($activity, 'id');
-
-        if (!$activityId || !getProp($activity, 'setting') || (int)getProp($activity, 'create_type') !== 5
-            || (int)getProp($activity, 'distribution_channel_id') !== $channelId) {
+        if (!$activityId || !getProp($activity, 'setting') || (int)getProp($activity, 'create_type') !== 5) {
             Utils::throwError(ErrorConst::ACTIVITY_NOT_FOUND);
         }
 
+        // 用户派单的信息是否跟创建该活动的子账号一致
+        $sendOrderId   = $this->send_order_id;
+        $qappAccountId = (int)getProp($activity, 'qapp_account_id');
+        if ($qappAccountId) {
+            $sendOrder   = QuickAppSendOrder::getSendOrderById($sendOrderId);
+            $qappAccount = QappChannelAccount::getByAccount(getProp($sendOrder, 'account'));
+            if ($qappAccountId !== (int)getProp($qappAccount, 'id')) {
+                Utils::throwError(ErrorConst::ACTIVITY_INVALID);
+            }
+        }
+
         // 活动开始时间判断
         if (getProp($activity, 'start_time') > date('Y-m-d H:i:s')) {
             Utils::throwError(ErrorConst::ACTIVITY_NOT_START);

+ 2 - 1
app/Modules/Activity/Models/Activity.php

@@ -7,7 +7,8 @@ use Illuminate\Database\Eloquent\Model;
 class Activity extends Model
 {
     protected $table = 'activity';
-    protected $fillable = ['id', 'name', 'start_time', 'end_time', 'activity_page', 'product_id', 'token', 'default_template_id', 'customer_msg', 'distribution_channel_id', 'setting','type'];
+    protected $fillable = ['id', 'name', 'start_time', 'end_time', 'activity_page', 'product_id', 'token',
+        'default_template_id', 'customer_msg', 'distribution_channel_id', 'setting', 'type', 'qapp_account_id'];
 
     //查询活动信息
     static function search($params = [], $is_all = false)

+ 14 - 0
app/Modules/SendOrder/Models/QuickAppSendOrder.php

@@ -13,4 +13,18 @@ class QuickAppSendOrder extends Model
         'child_gzh_nickname',
         'child_gzh_name',
     ];
+
+    /**
+     * @param $sendOrderId
+     * @return array
+     */
+    public static function getSendOrderById($sendOrderId)
+    {
+        if (empty($sendOrderId)) {
+            return [];
+        }
+        
+        $result = self::where('id', $sendOrderId)->first();
+        return $result ? $result->toArray() : [];
+    }
 }

+ 33 - 0
app/Modules/User/Models/QappChannelAccount.php

@@ -0,0 +1,33 @@
+<?php
+
+
+namespace App\Modules\User\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappChannelAccount extends Model
+{
+    protected $table = 'qapp_channel_accounts';
+    protected $fillable = [
+        'account',
+        'password',
+        'channel_user_id',
+        'distribution_channel_id',
+        'remark',
+        'is_enabled',
+        'is_deleted',
+        'created_at',
+        'updated_at',
+    ];
+
+    public static function getByAccount($account)
+    {
+        if (empty($account)) {
+            return [];
+        }
+
+        return self::where('account', $account)->first();
+    }
+
+}