初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\app\vip;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 付费会员卡绑定会员
|
||||
*/
|
||||
class CardUser extends Model
|
||||
{
|
||||
|
||||
// 表名,不含前缀
|
||||
protected $name = 'app_vip_card_user';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = false;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = false;
|
||||
protected $updateTime = false;
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 开通会员
|
||||
* @param $userId 用户
|
||||
* @param $cardId 会员卡ID
|
||||
* @param $time 开通时长 天数
|
||||
* @return void
|
||||
*/
|
||||
public static function openVip($userId,$cardId,$time){
|
||||
|
||||
$data = self::where([
|
||||
'user_id'=>$userId,
|
||||
'card_id'=>$cardId,
|
||||
])->find();
|
||||
|
||||
$time *= 86400;
|
||||
|
||||
if($data){
|
||||
$endtime = ( $data['end_time'] > time() ? $data['end_time'] :time() ) + $time;
|
||||
self::where([
|
||||
'id'=>$data['id']
|
||||
])->update([
|
||||
'updatetime'=>time(),
|
||||
'end_time'=>$endtime
|
||||
]);
|
||||
}else{
|
||||
$endtime = time() + $time;
|
||||
self::insert([
|
||||
'updatetime'=>time(),
|
||||
'createtime'=>time(),
|
||||
'end_time'=>$endtime,
|
||||
'status'=>1,
|
||||
'user_id'=>$userId,
|
||||
'card_id'=>$cardId,
|
||||
'uniacid'=>UNIACID
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户VIP信息
|
||||
* @param $userId
|
||||
* @return void
|
||||
*/
|
||||
public static function getUserVipInfo($userId){
|
||||
$data = self::with(['card'])->where([
|
||||
'card_user.user_id'=>$userId,
|
||||
'card_user.status'=>1,
|
||||
// 'card.status'=>1,
|
||||
'card_user.end_time'=>['>',time()]
|
||||
])->order('card_user.updatetime','desc')->find();
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户VIP信息
|
||||
* @param $userId
|
||||
* @return void
|
||||
*/
|
||||
public static function getUserAllVipInfo($userId){
|
||||
$data = self::with(['card'])->where([
|
||||
'card_user.user_id'=>$userId,
|
||||
'card_user.status'=>1,
|
||||
// 'card.status'=>1,
|
||||
'card_user.end_time'=>['>',time()]
|
||||
])->order('card_user.updatetime','desc')->select();
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function card()
|
||||
{
|
||||
return $this->belongsTo('app\api\model\app\vip\Card', 'card_id', 'id', [], 'Right')->setEagerlyType(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user