فهرست منبع

add/up 活动api

liugc 1 سال پیش
والد
کامیت
f5f145fc26

+ 3 - 1
app/api/controller/PropertyActivityController.php

@@ -29,7 +29,9 @@ class PropertyActivityController extends BaseApiController
     public function getActivityHomepage()
     {
         try{
-            $params = (new GoodsValidate())->post()->goCheck('activity');
+            $params = (new GoodsValidate())->post()->goCheck('activity',[
+                'user_id'=>$this->userId
+            ]);
             $result = ActivityLogic::getHomepageByActivityId($params);
             return $this->success('', $result, 1, 1);
         }catch(\Exception $e){

+ 2 - 0
app/api/controller/ServiceOrderController.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 use app\adminapi\logic\master_worker\MasterWorkerLogic;
 use app\adminapi\logic\works\ServiceWorkLogic;
 use app\api\lists\recharge\ServiceOrderLists;
+use app\api\logic\ActivityLogic;
 use app\api\logic\ServiceOrderLogic;
 use app\api\validate\ServiceOrderValidate;
 use app\common\model\works\ServiceWorkAppointmentLog;
@@ -96,6 +97,7 @@ class ServiceOrderController extends BaseApiController
         if (false === $result) {
             return $this->fail(ServiceOrderLogic::getError());
         }
+        ActivityLogic::createPropertyOrder($params);
         return $this->data($result);
     }
 

+ 55 - 0
app/api/logic/ActivityLogic.php

@@ -1,11 +1,13 @@
 <?php
 namespace app\api\logic;
 
+use app\adminapi\logic\property\PropertyUserLogic;
 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 app\common\model\user\User;
 use think\facade\Db;
 use think\facade\Log;
 
@@ -30,6 +32,19 @@ class ActivityLogic extends BaseLogic
             if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
                 throw new \Exception('活动已结束');
             }
+            if($params['user_id']){
+                // property_head_id householder_mobile  householder_name address
+                $userInfo = User::where('id',$params['user_id'])->findOrEmpty();
+                if ($userInfo->isEmpty()) {
+                    // 检查/注册
+                    PropertyUserLogic::getPropertyUserIdByMobile([
+                        'householder_mobile' => $userInfo['mobile'],
+                        'householder_name' => $userInfo['real_name'],
+                        'address' => '',
+                        'property_head_id' => $propertyActivity['property_head_id']
+                    ]);
+                }
+            }
             $res['activity_info'] = $propertyActivity->toArray();
             $res['coupons'] = CouponRules::where('property_activity_id',$params['property_activity_id'])
                 ->select()
@@ -38,6 +53,7 @@ class ActivityLogic extends BaseLogic
                 ->where('property_activity_id',$params['property_activity_id'])
                 ->where('is_agent',1)
                 ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee'])
+                ->order('is_recommend desc')
                 ->select()
                 ->toArray();
             return $res;
@@ -45,4 +61,43 @@ class ActivityLogic extends BaseLogic
             throw new \Exception($e->getMessage());
         }
     }
+
+
+    public static function createPropertyOrder($params){
+        try{
+            // 判断商品是否为 代理活动商品
+            $goods = Goods::findOrEmpty($params['goods_id']);
+            if($goods->isEmpty()){
+                throw new \Exception('产品不存在!');
+            }
+            if($goods->property_activity_id > 0){
+                $propertyActivity = PropertyActivity::findOrEmpty($goods->property_activity_id);
+                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('活动已结束');
+                }
+                // 生成代理单 user_info
+                // remark address  property_head_id  householder_name householder_mobile
+                $result = PropertyOrderLogic::add(array_merge($params,[
+                    'property_head_id' => $propertyActivity['property_head_id'],
+                    'householder_mobile' => $params['user_info']['mobile'],
+                    'householder_name' => $params['user_info']['real_name'],
+                    'address' => $params['address'],
+                    'remark' => '',
+                ]));
+                if($result === false){
+                    throw new \Exception('生成代理单失败');
+                }
+            }
+            return true;
+        }catch(\Exception $e){
+            throw new \Exception($e->getMessage());
+        }
+    }
+
 }