|
|
@@ -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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|