初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model\app\vip;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use app\common\model\User;
|
||||
use app\api\model\app\vip\CardUser;
|
||||
class Card extends Model
|
||||
{
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'app_vip_card';
|
||||
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $hidden = ['createtime', 'updatetime'];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单中的会员卡与规格对应的信息
|
||||
* @param $cardIdSku 格式 ID_SKU
|
||||
* @return false
|
||||
*/
|
||||
public static function getPayDetail($cardIdSku){
|
||||
$cardId = explode("_",$cardIdSku);
|
||||
|
||||
$data = self::where([
|
||||
'id'=>$cardId[0],
|
||||
'status'=>1
|
||||
])->find();
|
||||
|
||||
|
||||
|
||||
if(!$data){
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['sku'] = json_decode($data['sku'],true);
|
||||
|
||||
if(!$data['sku'] || !isset($cardId[1]) || !isset($data['sku'][$cardId[1]])){
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['price_marking'] = $data['price'] = $data['sku'][$cardId[1]]['price']; //价格
|
||||
$data['time'] = $data['sku'][$cardId[1]]['time']; //时长
|
||||
$data['limit'] = $data['sku'][$cardId[1]]['limit']; //限购
|
||||
$data['name'] = $data['title'];
|
||||
$data['type'] = 'vipcard';
|
||||
|
||||
if(\app\common\library\Platform::getSystemType() == 'single'){
|
||||
$data['cover'] = MODULE_URL.'/assets/image/vipcard.png';
|
||||
}else{
|
||||
$data['cover'] = MODULE_URL.'/public/assets/image/vipcard.png';
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model\app\vip;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
class CardPrivilege extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'app_vip_card_privilege';
|
||||
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'integer';
|
||||
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = false;
|
||||
protected $deleteTime = false;
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 获取批次包含的商品
|
||||
* @return void
|
||||
*/
|
||||
public function getPrivilegeGoods($cardId,$type){
|
||||
|
||||
|
||||
$list = self::with('course')->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model\app\vip;
|
||||
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
use app\common\model\User;
|
||||
class CardUser extends Model
|
||||
{
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'app_vip_card_user';
|
||||
|
||||
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
protected $hidden = ['createtime', 'updatetime'];
|
||||
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user