liugc 1 år sedan
förälder
incheckning
e6f7905782

+ 2 - 2
app/adminapi/logic/property/PropertyActivityLogic.php

@@ -73,8 +73,8 @@ class PropertyActivityLogic extends BaseLogic
             PropertyActivity::where('id', $params['id'])->update([
                 'property_head_id' => $params['property_head_id'],
                 'activity_name' => $params['activity_name'],
-                'activity_start_time' => $params['activity_start_time'],
-                'activity_end_time' => $params['activity_end_time'],
+                'activity_start_time' => $params['activity_start_time']?strtotime($params['activity_start_time']):0,
+                'activity_end_time' => $params['activity_end_time']?strtotime($params['activity_end_time']):0,
             ]);
 
             Db::commit();

+ 7 - 7
app/api/controller/PropertyActivityController.php

@@ -7,6 +7,7 @@ use app\adminapi\validate\property\PropertyActivityValidate;
 use app\api\logic\ActivityLogic;
 use app\api\logic\GoodsLogic;
 use app\api\validate\GoodsValidate;
+use think\facade\Log;
 
 
 /**
@@ -27,14 +28,13 @@ class PropertyActivityController extends BaseApiController
      */
     public function getActivityHomepage()
     {
-        $params = (new GoodsValidate())->post()->goCheck('activity',[
-            'user_id'=>$this->userId
-        ]);
-        $result = ActivityLogic::getHomepageByActivityId($params);
-        if (false === $result) {
-            return $this->fail(GoodsLogic::getError());
+        try{
+            $params = (new GoodsValidate())->post()->goCheck('activity');
+            $result = ActivityLogic::getHomepageByActivityId($params);
+            return $this->success('', $result, 1, 1);
+        }catch(\Exception $e){
+            return $this->fail($e->getMessage());
         }
-        return $this->success('', $result, 1, 1);
     }
 
 

+ 13 - 2
app/api/logic/ActivityLogic.php

@@ -5,6 +5,7 @@ use app\common\logic\BaseLogic;
 use app\common\model\coupon\CouponRules;
 use app\common\model\goods\Goods;
 use app\common\model\goods_category\GoodsCategory;
+use app\common\model\property\PropertyActivity;
 use think\facade\Db;
 use think\facade\Log;
 
@@ -19,6 +20,17 @@ class ActivityLogic extends BaseLogic
     public static function getHomepageByActivityId($params){
         $res = [];
         try{
+            $propertyActivity = PropertyActivity::with(['propertyHeadInfo'])->where('id',$params['property_activity_id'])->findOrEmpty();
+            if($propertyActivity->isEmpty()){
+                throw new \Exception('活动不存在');
+            }
+            if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
+                throw new \Exception('活动未开始');
+            }
+            if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
+                throw new \Exception('活动已结束');
+            }
+            $res['activity_info'] = $propertyActivity->toArray();
             $res['coupons'] = CouponRules::where('property_activity_id',$params['property_activity_id'])
                 ->select()
                 ->toArray();
@@ -30,8 +42,7 @@ class ActivityLogic extends BaseLogic
                 ->toArray();
             return $res;
         }catch(\Exception $e){
-            Log::info('getHomepageByActivityId:'.$e->getMessage());
-            return $res;
+            throw new \Exception($e->getMessage());
         }
     }
 }