Files
oil/server-tp6/app/common/model/Partners.php
T
2026-09-01 22:15:50 +08:00

91 lines
2.4 KiB
PHP

<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 合作商模型
* Class Partners
* @package app\common\model
*/
class Partners extends BaseModel
{
protected $name = 'partners';
// 定义主键
protected $pk = 'partners_id';
/**
* 合作商详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['partners_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);
$arr = $user['partners_id']?json_decode($user['partners_id'],true):[];
$model->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('partners_id', 'in', $arr);
});
return $model->order(['partners_id' => 'asc'])->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('partners_id', 'in', $arr);
})->select();
}else{
return $model->order(['partners_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['partners_id' => 'asc'])->select()->toArray();
}
/**
* 累积合作商可用余额
* @param int $partnersId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $partnersId, float $money)
{
return (new static)->setInc($partnersId, 'balance', $money);
}
/**
* 消减合作商可用余额
* @param int $partnersId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $partnersId, float $money)
{
return (new static)->setDec([['partners_id', '=', $partnersId]], 'balance', $money);
}
}