初始化项目

This commit is contained in:
2026-09-01 22:15:50 +08:00
commit b5a26a8848
11217 changed files with 1710987 additions and 0 deletions
+102
View File
@@ -0,0 +1,102 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use app\store\model\store\User;
use cores\BaseModel;
use think\model\relation\BelongsTo;
/**
* 商户模型
* Class Merchant
* @package app\common\model
*/
class Merchant extends BaseModel
{
protected $name = 'merchant';
// 定义主键
protected $pk = 'merchant_id';
/**
* 获取上级经销商信息
* @return BelongsTo
*/
public function referrer(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\{$module}\\model\\Merchant", 'parent_merchant_id');
}
/**
* 商户详情
* @param $where
* @param array $with
* @return static|null
* @throws \think\exception\DbException
*/
public static function detail($where, $with = [])
{
!is_array($where) && $where = ['merchant_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['merchant_id']?json_decode($user['merchant_id'],true):[];
return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($users, $arr) {
$query->where('store_user_id', 'in', $users)
->whereOr('merchant_id', 'in', $arr);
})->select();*/
return $model->order(['merchant_id' => 'asc'])->where(function ($query) use($user) {
$query->where('merchant_id', '=', $user['merchant_id'])
->whereOr('parent_merchant_id', '=', $user['merchant_id']);
})->select();
}else{
return $model->order(['merchant_id' => 'asc'])->select();
}
}
/**
* 获取指定
* @param array $filter
* @return mixed
*/
public static function getQuery($filter): array
{
$model = new static;
return $model->where($filter)->order(['merchant_id' => 'asc'])->select()->toArray();
}
/**
* 累积商户可用余额
* @param int $merchantId
* @param float $money
* @return mixed
*/
public static function setIncBalance(int $merchantId, float $money)
{
return (new static)->setInc($merchantId, 'balance', $money);
}
/**
* 消减商户可用余额
* @param int $merchantId
* @param float $money
* @return mixed
*/
public static function setDecBalance(int $merchantId, float $money)
{
return (new static)->setDec([['merchant_id', '=', $merchantId]], 'balance', $money);
}
}