71 lines
1.4 KiB
PHP
71 lines
1.4 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
namespace app\common\model;
|
|
|
|
use cores\BaseModel;
|
|
|
|
/**
|
|
* 产码模型
|
|
* Class User
|
|
* @package app\common\model
|
|
*/
|
|
class Code extends BaseModel
|
|
{
|
|
protected $name = 'code';
|
|
// 定义主键
|
|
protected $pk = 'code_id';
|
|
/**
|
|
* 支付码详情
|
|
* @param $where
|
|
* @param array $with
|
|
* @return static|null
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public static function detail($where, $with = [])
|
|
{
|
|
|
|
!is_array($where) && $where = ['code_id' => (int)$where];
|
|
return static::get($where, $with);
|
|
}
|
|
|
|
/**
|
|
* 关联父级用户
|
|
* @return \think\model\relation\BelongsTo
|
|
*/
|
|
public function shop()
|
|
{
|
|
return $this->belongsTo('Shop');
|
|
}
|
|
/**
|
|
* 关联父级用户
|
|
* @return \think\model\relation\BelongsTo
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('app\common\model\store\User','store_user_id','store_user_id');
|
|
}
|
|
|
|
/**
|
|
* 获取全部
|
|
* @return mixed
|
|
*/
|
|
public static function getAll()
|
|
{
|
|
$model = new static;
|
|
return $model->order(['shop_id' => 'asc'])->select();
|
|
}
|
|
|
|
/**
|
|
* 获取产码数量
|
|
* @param array $filter
|
|
* @return int|string
|
|
*/
|
|
public function getCodeTotal($filter=[])
|
|
{
|
|
return $this->field('code_id')
|
|
->where($filter)
|
|
->group('code_id')
|
|
->count();
|
|
}
|
|
}
|