cxhxy/app/common/model/food/SignLog.php
test_service d3170b4d1c 1
2023-12-01 15:43:29 +08:00

58 lines
1.4 KiB
PHP

<?php
namespace app\common\model\food;
/**
* 签到记录模型
*/
class SignLog extends BaseModel
{
// 定义表名
protected $name = 'food_sign_log';
// 定义主键
protected $pk = 'sign_log_id';
// 追加字段
protected $append = [];
/**
* 关联用户表
*/
public function user()
{
return $this->belongsTo('app\\common\\model\\food\\User','user_id');
}
/**
* 奖励类型
*/
public function getTypeAttr($value)
{
$status = ['score' => '积分', 'money' => '余额'];
return ['text' => $status[$value], 'value' => $value];
}
/**
* 获取列表
*/
public function getList($user_id = 0)
{
// 筛选条件
$filter = [];
$user_id > 0 && $filter['user_id'] = $user_id;
// 执行查询
$list = $this->with(['user'])
->where($filter)
->order('sign_log_id','desc')
->paginate(['list_rows'=>15,'query' => request()->param()]);
return $list;
}
/**
* 获取今天签到详情
*/
public function getIsSign($user_id)
{
$beginToday = mktime(0,0,0,date('m'),date('d'),date('Y'));
return $this->where('user_id',$user_id)->where('create_time','>',$beginToday)->count();
}
}