where([ 'card_id'=>$cardId, 'card_privilege.type'=>$type, 'course.status'=>1, 'course.sales_type'=>['like',"%alone%"], 'course.hide'=>0 ])->limit(6)->select(); $data = []; if(!empty($list)){ foreach ($list as &$row){ $row->course->visible(['name','cover','price','price_marking','pay_type','type','id','is_vip_goods']); $row->course->is_vip_goods = true; $data[] = $row->course; } } return $data; } /** * 获取折扣后的商品价格 * @param $price 价格 * @param $discountVal 折扣 * @return array */ public static function getDiscountPrice($price,$discountVal){ $data = [ 'price_marking' => $price ]; $data['price'] = number_format(($price * $discountVal / 10), 2, '.', '');; return $data; } /** * 检查是否为会员权益商品 * 1. 该商品被指定为某张启用中会员卡的指定课程权益 * 2. 商品类型属于 article/video/audio/live/column,且存在启用了「全部课程」作用域的会员卡 * @param $goodsId 商品ID * @return Boolean */ public static function checkVipGoods($goodsId){ $vipLog = self::with(['card'])->where([ 'card.status'=>1, 'goods_id'=>$goodsId ])->find(); if($vipLog){ return true; } //再判断「全部课程」作用域:只要存在启用中的卡,且课程类型受作用,则认为是 VIP 权益商品 if (\app\common\model\app\vip\CardPrivilege::isCourseInScopeAll($goodsId)) { $cardModel = new \app\api\model\app\vip\Card(); $hasScopeAllCard = $cardModel->where('status', 1) ->where('uniacid', UNIACID) ->where(function ($query) { $query->where(['privilege_free' => 1, 'privilege_free_scope' => 'all']) ->whereOr(['privilege_discount' => 1, 'privilege_discount_scope' => 'all']); })->find(); if ($hasScopeAllCard) { return true; } } return false; } public function card() { return $this->belongsTo('Card', 'card_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function course() { return $this->belongsTo('app\admin\model\Course', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0); } }