询单改造

This commit is contained in:
mzl
2025-07-22 15:13:27 +08:00
parent 5e395eceae
commit e5ab965e65
12 changed files with 1103 additions and 81 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class Country extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'country';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'cn_addr', 'en_addr', 'en_full_name', 'two_letter', 'three_letter', 'num_code', 'steering', 'c_time', 'u_time'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace app\common\model;
use support\Model;
use app\common\model\User;
use app\common\model\Country;
class InquiryLog extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'inquiry_log';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = [
'id', 'order_no', 'enter_user_id', 'recipient',
'quality', 'channel', 'email', 'tel', 'whatsapp',
'country', 'contacts', 'content', 'status',
'r_time', 't_time', 'created_at', 'updated_at'
];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
public function enter()
{
return $this->hasOne(User::class, 'id', 'enter_user_id');
}
public function recipient()
{
return $this->hasOne(User::class, 'id', 'recipient');
}
// public function enter()
// {
// return $this->belongsTo(User::class, 'enter_user_id');
// }
// public function recipient()
// {
// return $this->belongsTo(User::class, 'recipient');
// }
public function country()
{
return $this->hasOne(Country::class, 'id', 'country');
}
}
+33 -75
View File
@@ -152,43 +152,22 @@ class CrudUtil
* @return Model
* @throws BusinessException
*/
// public static function findByPk(string $modelClass, $id, array $with = []): Model
// {
// $m = $modelClass::with($with)->find($id);
// if (!$m) {
// throw new BusinessException("记录 ID={$id} 不存在", 404);
// }
// return $m;
// }
public static function findByPk(string $modelClass, $id, array $with = []): Model
{
$m = $modelClass::with($with)->find($id);
if (!$m) {
throw new BusinessException("记录 ID={$id} 不存在", 404);
}
return $m;
}
/**
* 任意条件单条查询,支持 dataLimit
*
* @param string $modelClass
* @param array $where
* @param array $with
* @param array $dataLimit
* @param Builder $query
* @return Model
* @throws BusinessException
*/
// public static function findOneBy(
// string $modelClass,
// array $where,
// array $with = [],
// array $dataLimit = []
// ): Model {
// $config = compact('modelClass');
// $config['model'] = $modelClass;
// $config['where'] = $where;
// $config['with'] = $with;
// $config['dataLimit'] = $dataLimit;
// $m = self::buildQuery($config)->first();
// if (!$m) {
// throw new BusinessException("未找到符合条件的记录", 404);
// }
// return $m;
// }
public static function findOneBy(Builder $q): Model
{
return $q->first();
@@ -225,43 +204,32 @@ class CrudUtil
* @return Model
* @throws BusinessException
*/
// public static function updateByPk(
// string $modelClass,
// $id,
// array $data,
// array $dataLimit = []
// ): Model {
// /** @var Model $m */
// $m = $modelClass::find($id);
// if (!$m) {
// throw new BusinessException("记录 ID={$id} 不存在", 404);
// }
// // dataLimit 校验
// if (!empty($dataLimit)) {
// self::applyDataLimitOnMutate($m, $dataLimit, $data);
// }
// $m->fill($data)->save();
// return $m;
// }
public static function updateByPk(
string $modelClass,
$id,
array $data,
array $dataLimit = []
): Model {
/** @var Model $m */
$m = $modelClass::find($id);
if (!$m) {
throw new BusinessException("记录 ID={$id} 不存在", 404);
}
// dataLimit 校验
if (!empty($dataLimit)) {
self::applyDataLimitOnMutate($m, $dataLimit, $data);
}
$m->fill($data)->save();
return $m;
}
/**
* 非主键条件更新(批量),支持 dataLimit
*
* @param string $modelClass
* @param array $where
* @param Builder $query
* @param array $data
* @param array $dataLimit
* @return int 受影响行数
*/
// public static function updateBy(
// string $modelClass,
// array $where,
// array $data,
// array $dataLimit = []
// ): int {
// $config = ['model'=>$modelClass, 'where'=>$where, 'dataLimit'=>$dataLimit];
// return self::buildQuery($config)->update($data);
// }
public static function updateBy(Builder $q, array $data): int
{
return $q->update($data);
@@ -274,27 +242,17 @@ class CrudUtil
* @param array $ids
* @return int 删除条数
*/
// public static function deleteByPk(string $modelClass, array $ids): int
// {
// return $modelClass::destroy($ids);
// }
public static function deleteByPk(string $modelClass, array $ids): int
{
return $modelClass::destroy($ids);
}
/**
* 非主键条件删除,支持 dataLimit
*
* @param string $modelClass
* @param array $where
* @param array $dataLimit
* @param Builder $query
* @return int 删除条数
*/
// public static function deleteBy(
// string $modelClass,
// array $where,
// array $dataLimit = []
// ): int {
// $config = ['model'=>$modelClass, 'where'=>$where, 'dataLimit'=>$dataLimit];
// return self::buildQuery($config)->delete();
// }
public static function deleteBy(Builder $q): int
{
return $q->delete();
@@ -0,0 +1,29 @@
<?php
namespace app\common\validate;
use think\Validate;
class InquiryLogValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}