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

100 lines
2.4 KiB
PHP

<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
/**
* 商户模型
* Class Company
* @package app\common\model
*/
class Company extends BaseModel
{
protected $name = 'company';
// 定义主键
protected $pk = 'company_id';
/**
* 公司详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['company_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(['company_id' => 'asc'])->where(function ($query) use($users) {
$query->where('store_user_id', 'in', $users);
})->select();
}else{
return $model->order(['company_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['company_id' => 'asc'])->select()->toArray();
}
/**
* 累积公司可用余额
* @param int $companyId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $companyId, float $money)
{
return (new static)->setInc($companyId, 'balance', $money);
}
/**
* 消减公司可用余额
* @param int $companyId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $companyId, float $money)
{
return (new static)->setDec([['company_id', '=', $companyId]], 'balance', $money);
}
/**
* 切换状态
* @param $status
* @return false|int
*/
public function changeStatus($status)
{
if($bool = $this->save(['status' => $status])){
$bool = true;
}
return $bool;
}
}