cmbYouku_Api/app/model/Sign.php

96 lines
2.8 KiB
PHP
Raw Normal View History

2024-07-01 15:57:07 +08:00
<?php
namespace app\model;
use think\Model;
class Sign extends Model
{
protected $name = 'sign';
const SIGN_STATUS_DEFAULT = 0;
const SIGN_STATUS_SUCCESS = 1;
const SIGN_STATUS_RELEASE = 2;
public static function getSignSuccessUser()
{
return self::where(['sign_status' => self::SIGN_STATUS_SUCCESS])->select();
}
public static function getByOpenId(string $openId)
{
return self::where(['open_id' => $openId, 'sign_status' => 0])->findOrEmpty();
}
public static function getByUserId(int $userId)
{
return self::where(['user_id' => $userId])->findOrEmpty();
}
/**
* 查询最近一年该用户是否有签约
* @param int $userId
* @return Sign|array|mixed|Model
*/
public static function getSignLastYear(int $userId)
{
return self::whereTime('create_time', '-1 year')->where(['user_id' => $userId, 'sign_status' => Sign::SIGN_STATUS_SUCCESS])->findOrEmpty();
}
/**
* 查询最近一年该用户是否有解约
* @param int $userId
* @return Sign|array|mixed|Model
*/
public static function getReleaseLastYear(int $userId)
{
return self::whereTime('create_time', '-1 year')->where(['user_id' => $userId, 'sign_status' => Sign::SIGN_STATUS_RELEASE])->findOrEmpty();
}
/**
* 根据流水号查询数据
* @param string $requestSerial
* @return Sign|array|mixed|Model
*/
public static function getByRequestSerial(string $requestSerial)
{
return self::where(['request_serial' => $requestSerial])->findOrEmpty();
}
/**
* 根据商户协议号获取数据
* @param string $agreementId
* @return Sign|array|mixed|Model
*/
public static function getByAgreementId(string $agreementId)
{
return self::where(['m_agreement_id' => $agreementId])->findOrEmpty();
}
/**
* 查询正在订阅的用户
* @param int $userId
* @return Sign|array|mixed|Model
*/
public static function getSubscribeByUserId(int $userId)
{
return self::where(['user_id' => $userId, 'sign_status' => Sign::SIGN_STATUS_SUCCESS])->findOrEmpty();
}
/**
* 查询该用户正在签约的信息
* @param int $userId
* @return Sign|array|mixed|Model
*/
public static function getWaitSignByUserId(int $userId)
{
return self::where(['user_id' => $userId, 'sign_status' => Sign::SIGN_STATUS_DEFAULT])->findOrEmpty();
}
/**
* 查询最近一年该用户是否有签约
* @param int $userId
* @return Sign|array|mixed|Model
*/
public static function getSignLastYearByMobile(int $mobile)
{
return self::whereTime('create_time', '-1 year')->where(['mobile' => $mobile, 'sign_status' => Sign::SIGN_STATUS_SUCCESS])->findOrEmpty();
}
}