94 lines
2.2 KiB
PHP
94 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace app\common\model;
|
|
|
|
use app\store\model\store\User;
|
|
use cores\BaseModel;
|
|
|
|
/**
|
|
* 充值卡模型
|
|
* Class Card
|
|
* @package app\common\model
|
|
*/
|
|
class Card extends BaseModel
|
|
{
|
|
protected $name = 'card';
|
|
// 定义主键
|
|
protected $pk = 'card_id';
|
|
|
|
/**
|
|
* 关联用户表
|
|
* @return \think\model\relation\BelongsTo
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('app\common\model\User','user_id','user_id');
|
|
}
|
|
|
|
/**
|
|
* 获取器:图片地址
|
|
* @param $value
|
|
* @return string
|
|
*/
|
|
public function getFilePathAttr($value): string
|
|
{
|
|
return $value; // $value ? request()->domain().'/'.$value : ''
|
|
}
|
|
|
|
/**
|
|
* 充值卡详情
|
|
* @param $where
|
|
* @param array $with
|
|
* @return static|null
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public static function detail($where, $with = [])
|
|
{
|
|
!is_array($where) && $where = ['card_id' => (int)$where];
|
|
return static::get($where, $with);
|
|
}
|
|
|
|
/**
|
|
* 获取全部
|
|
* @param array $user
|
|
* @return mixed
|
|
*/
|
|
public static function getAll($user = [])
|
|
{
|
|
$model = new static;
|
|
if(isset($user['is_super']) && $user['is_super'] == 0) {
|
|
$users = User::getScope($user);
|
|
$model->where(function ($query) use($users) {
|
|
$query->where('store_user_id', 'in', $users);
|
|
});
|
|
return $model->order(['card_id' => 'asc'])->where(function ($query) use($users) {
|
|
$query->where('store_user_id', 'in', $users);
|
|
})->select();
|
|
}else{
|
|
return $model->order(['card_id' => 'asc'])->select();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取指定
|
|
* @param array $filter
|
|
* @return mixed
|
|
*/
|
|
public static function getQuery($filter): array
|
|
{
|
|
$model = new static;
|
|
return $model->where($filter)->order(['card_id' => 'asc'])->select()->toArray();
|
|
}
|
|
|
|
/**
|
|
* 切换使用状态
|
|
* @param $is_used
|
|
* @return false|int
|
|
*/
|
|
public function changeStatus($is_used)
|
|
{
|
|
return $this->save(['is_used' => $is_used]);
|
|
}
|
|
}
|