会员支付管理后台-用于提供会员管理小程序支付的api接口,与后台数据管理展示
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

157 lines
4.2 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace addon\hygl\app\model\user_coupons;
use addon\hygl\app\model\coupons\Coupons;
use core\base\BaseModel;
use think\model\concern\SoftDelete;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
use addon\hygl\app\model\user\User;
/**
* 用户优惠券模型
* Class UserCoupons
* @package addon\hygl\app\model\user_coupons
*/
class UserCoupons extends BaseModel
{
use SoftDelete;
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
/**
* 模型名称
* @var string
*/
protected $name = 'hygl_user_coupons';
/**
* 定义软删除标记字段.
* @var string
*/
protected $deleteTime = 'delete_time';
/**
* 定义软删除字段的默认值.
* @var int
*/
protected $defaultSoftDelete = 0;
/**
* 搜索器:用户优惠券用户id
* @param $value
* @param $data
*/
public function searchUserIdAttr($query, $value, $data)
{
if ($value) {
$query->where("user_id", "like", "%" . $value . "%");
}
}
/**
* 搜索器:用户优惠券卡券名字
* @param $value
* @param $data
*/
public function searchCouponsIdAttr($query, $value, $data)
{
if ($value) {
$id_arr = Coupons::where("name", "like", "%" . $value . "%")->column('id');
if ($id_arr) {
$query->whereIn('coupons_id', $id_arr);
}
}
}
/**
* 搜索器:用户优惠券卡券面值
* @param $value
* @param $data
*/
public function searchNominalValueAttr($query, $value, $data)
{
$start = empty($value[0]) ? 0 : $value[0];
$end = empty($value[1]) ? 0 : $value[1];
$id_arr = [];
if ($start > 0 && $end > 0) {
$id_arr = Coupons::where([["nominal_value", "between", [$start, $end]]])->column('id');
} else if ($start > 0 && $end == 0) {
$id_arr = Coupons::where([["nominal_value", ">=", $start]])->column('id');
} else if ($start == 0 && $end > 0) {
$id_arr = Coupons::where([["nominal_value", "<=", $end]])->column('id');
}
if ($id_arr) {
$query->whereIn('coupons_id', $id_arr);
}
}
/**
* 搜索器:用户优惠券是否可用
* @param $value
* @param $data
*/
public function searchIsShowAttr($query, $value, $data)
{
if ($value) {
$query->where("is_show", $value);
}
}
/**
* 搜索器:用户优惠券创建时间
* @param $value
* @param $data
*/
public function searchCreateTimeAttr($query, $value, $data)
{
$start = empty($value[0]) ? 0 : strtotime($value[0]);
$end = empty($value[1]) ? 0 : strtotime($value[1]);
if ($start > 0 && $end > 0) {
$query->where([["create_time", "between", [$start, $end]]]);
} else if ($start > 0 && $end == 0) {
$query->where([["create_time", ">=", $start]]);
} else if ($start == 0 && $end > 0) {
$query->where([["create_time", "<=", $end]]);
}
}
public function site()
{
return $this->hasOne(\app\model\site\Site::class, 'site_id', 'site_id');
}
public function user()
{
return $this->hasOne(\addon\hygl\app\model\user\User::class, 'id', 'user_id');
}
public function coupons()
{
return $this->hasOne(Coupons::class, 'id', 'coupons_id');
}
// public function user(){
// return $this->hasOne(User::class, 'user_id', 'id')->joinType('left')->withField('name,id')->bind(['user_id_name'=>'name']);
// }
}