ActivityLogic.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\api\logic;
  3. use app\common\logic\BaseLogic;
  4. use app\common\model\coupon\CouponRules;
  5. use app\common\model\goods\Goods;
  6. use app\common\model\goods_category\GoodsCategory;
  7. use app\common\model\property\PropertyActivity;
  8. use think\facade\Db;
  9. use think\facade\Log;
  10. /**
  11. * 活动逻辑处理
  12. * Class ActivityLogic
  13. * @package app\api\logic
  14. */
  15. class ActivityLogic extends BaseLogic
  16. {
  17. public static function getHomepageByActivityId($params){
  18. $res = [];
  19. try{
  20. $propertyActivity = PropertyActivity::with(['propertyHeadInfo'])->where('id',$params['property_activity_id'])->findOrEmpty();
  21. if($propertyActivity->isEmpty()){
  22. throw new \Exception('活动不存在');
  23. }
  24. if(!empty($propertyActivity->getData('activity_start_time')) && $propertyActivity->getData('activity_start_time') > time()){
  25. throw new \Exception('活动未开始');
  26. }
  27. if(!empty($propertyActivity->getData('activity_end_time')) && $propertyActivity->getData('activity_end_time') < time()){
  28. throw new \Exception('活动已结束');
  29. }
  30. $res['activity_info'] = $propertyActivity->toArray();
  31. $res['coupons'] = CouponRules::where('property_activity_id',$params['property_activity_id'])
  32. ->select()
  33. ->toArray();
  34. $res['goods'] = Goods::order(['category_type' => 'desc'])
  35. ->where('property_activity_id',$params['property_activity_id'])
  36. ->where('is_agent',1)
  37. ->visible(['id','goods_name','goods_image','base_service_fee','service_total','service_fee'])
  38. ->select()
  39. ->toArray();
  40. return $res;
  41. }catch(\Exception $e){
  42. throw new \Exception($e->getMessage());
  43. }
  44. }
  45. }