Merge branch 'develop'

This commit is contained in:
mzl
2025-09-16 10:53:57 +08:00
parent b399f85707
commit 62c32d25ff
210 changed files with 15388 additions and 95 deletions
@@ -0,0 +1,44 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\ApprovalFlowsService;
class ApprovalFlowsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new ApprovalFlowsService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
public function desc()
{
// type sequential(顺序会签), parallel(并行会签), any(或签)
}
}
@@ -0,0 +1,33 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\ApprovalInstancesService;
class ApprovalInstancesController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new ApprovalInstancesService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,90 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\ApprovalRecordsService;
use app\admin\service\SysDictService;
use app\common\model\SysDictItem;
use support\Request;
class ApprovalRecordsController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new ApprovalRecordsService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['records']) && count($data['records']) > 0) {
foreach ($data['records'] as $key => &$record) {
$result = [
'id' => $record['id'],
'flows_name' => $record['approvalInstance']['flows']['name'],
'instance_id' => $record['instance_id'],
'biz_id' => $record['approvalInstance']['biz_id'],
'biz_desc' => '备货单【'.$record['approvalInstance']['bizInfo']['order_no'].'】',
'biz_type' => $record['approvalInstance']['flow_type'],
'initiator_name' => $record['approvalInstance']['initiator']['name'],
'initiator_avatar' => $record['approvalInstance']['initiator']['avatar'],
'approver_name' => $record['approver']['name'],
'approver_avatar' => $record['approver']['avatar'],
'step_index' => $record['step_index'],
'action' => $record['action'],
'action_desc' => SysDictItem::where('item_value', $record['action'])->where('status', 1)->value('item_label'),
'status' => $record['status'],
'status_desc' => SysDictItem::where('item_value', $record['status'])->where('status', 1)->value('item_label'),
'comment' => $record['comment'],
'approved_at' => $record['approved_at'],
'finished_at' => $record['approvalInstance']['finished_at'],
'deadline_at' => $record['approvalInstance']['deadline_at'],
'created_at' => $record['created_at']
];
$record = $result;
}
}
return $data;
}
public function approve(Request $request)
{
try {
$res = $this->service->serviceApprove($request);
return $this->success([], $res['msg']);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function logs(Request $request)
{
try {
$instanceId = $request->get('instance_id');
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$res = $appro->getSimpleTimeline($instanceId, 'name', 'prepend');
return $this->success($res);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\service\OssService;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\BrandService;
class BrandController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new BrandService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (!empty($data['logo']))
$data['logo_full'] = (new OssService)->generatePrivateUrl($data['logo']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (empty($data['logo']))
$data['logo_full'] = (new OssService)->generatePrivateUrl($data['logo']);
return $data;
}
}
@@ -0,0 +1,48 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\BrandSeriesService;
class BrandSeriesController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new BrandSeriesService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
}
@@ -0,0 +1,251 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\StockOrdersService;
use support\Request;
class StockOrdersController extends BaseController
{
protected $noNeedLogin = ['print'];
protected $noNeedHeaderData = ['print'];
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new StockOrdersService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['eta_ship_date'])) $data['eta_ship_date'] = date('Y-m-d', $data['eta_ship_date']);
if (isset($data['biz_date'])) $data['biz_date'] = date('Y-m-d', $data['biz_date']);
if (isset($data['latest_arrival_date'])) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']);
if (isset($data['id'])) {
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
$appro = $appro->getBriefStatusByBiz($data['id'], null, 'name');
$map = ['processing'=>'审批中','pending'=>'审批中','approved'=>'已通过','rejected'=>'已拒绝','revoked'=>'已撤回'];
if ($appro) {
$data['appro_status'] = [
'status' => $appro['status'],
'status_desc' => $map[$appro['status']],
'name' => isset($appro['step'])?$appro['step']['name']:''
];
}
}
return $data;
}
protected function showFormat($data)
{
if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['eta_ship_date'])) $data['eta_ship_date'] = date('Y-m-d', $data['eta_ship_date']);
if (isset($data['biz_date'])) $data['biz_date'] = date('Y-m-d', $data['biz_date']);
if (isset($data['latest_arrival_date'])) $data['latest_arrival_date'] = date('Y-m-d', $data['latest_arrival_date']);
if (!empty($data['contract'])) {
$data['contract_url'] = (new \app\common\service\OssService)->generatePrivateUrl($data['contract']);
}
if (count($data['moneyValues']) > 0) {
$data['cif_total_amount'] = [
'exchange_rate' => $data['moneyValues']['exchange_rate'],
'amount' => $data['moneyValues']['amount'],
'currency' => $data['moneyValues']['currency'],
'id' => $data['moneyValues']['id']
];
}
foreach ($data['items'] as &$item) {
foreach ($item['moneyValues'] as $mv) {
$item[$mv['field']] = [
'exchange_rate' => $mv['exchange_rate'],
'amount' => $mv['amount'],
'currency' => $mv['currency'],
'id' => $mv['id']
];
}
unset($item['moneyValues']);
foreach ($item['options'] as $opt) {
$item['modify_list'][] = [
"id" => $opt['id'],
"order_item_id" => $opt['order_item_id'],
"option_id" => $opt['option_id'],
"option_name_snapshot" => $opt['option_name_snapshot'],
"option_price" => $opt['option_price']
];
}
unset($item['options']);
}
unset($item);
foreach ($data['accounts'] as $acc) {
$data['account_list'][] = [
"id" => $acc['id'],
"order_id" => $acc['order_id'],
"seq_no" => $acc['seq_no'],
"remit_country_id" => $acc['remit_country_id'],
"remit_country_name_snapshot" => $acc['remit_country_name_snapshot'],
"remit_date" => date('Y-m-d', $acc['remit_date']),
"currency_code" => $acc['currency_code'],
"currency_name_snapshot" => $acc['currency_name_snapshot'],
"account_id" => $acc['account_id'],
"account_name_snapshot" => $acc['account_name_snapshot'],
"remitter_name" => $acc['remitter_name'],
"amount" => $acc['amount']
];
}
unset($data['accounts']);
$data['veh_list'] = $data['items'];
unset($data['items']);
return $data;
}
protected function printFormat($data)
{
$data['file_url_full'] = (!empty($data['file_url'])) ? (new \app\common\service\OssService)->generatePrivateUrl($data['file_url']) : '';
return $data;
}
public function print(Request $request)
{
try {
$raw = $this->service->servicePrint($request);
$data = $this->transformData($raw, method_exists($this, 'printFormat')
? [$this, 'printFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function detail(Request $request)
{
try {
$raw = $this->service->serviceDetail($request);
$data = $this->transformData($raw, method_exists($this, 'detailFormat')
? [$this, 'detailFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function desc(Request $request)
{
$data = [
'id' => '', //'主键',
'order_no' => '', //'备货单编号(业务唯一)',
'pi_no' => '', //'PI号'/'阿里订单号',
'biz_date' => '', //'单据日期(时间戳)',
'salesperson_id' => '', //'业务员ID(关联数据)',
'salesperson_snapshot' => '', //'业务员姓名快照',
'clearance_country_id' => '', //'清关目的国ID(关联数据)',
'clearance_country_snapshot' => '', //'清关目的国名称快照',
// 'ali_order_no' => '', //'阿里订单号',
'customer_source_id' => '', //'客户来源ID(关联数据)',
'customer_source_snapshot' => '', //'客户来源名称快照',
'customer_id' => '', //'客户ID(关联数据)',
'customer_snapshot' => '', //'客户名称快照',
'customer_country_id' => '', //'客户所在国ID(关联数据)',
'customer_country_snapshot' => '', //'客户所在国名称快照',
'declarant_name' => '', //'清关人(文本)',
'eta_ship_date' => '', //'预计发运日(时间戳)',
'shipping_method' => '', //'出运方式(如海运/空运/铁路等)',
'cif_total_amount' => '', //'0.00' COMMENT '合计到岸价(CIF)',
'domestic_port_id' => '', //'国内收货港ID(关联数据)',
'domestic_port_snapshot' => '', //'国内收货港名称快照',
'trade_term_id' => '', //'贸易条款ID(关联数据,EXW/FOB/CIF等)',
'trade_term_snapshot' => '', //'贸易条款名称快照',
'clearance_port_id' => '', //'清关目的港ID(关联数据)',
'clearance_port_snapshot' => '', //'清关目的港名称快照',
'latest_arrival_date' => '', //'最迟到港时间(时间戳)',
'contract_exchange_rate' => '', //'合同汇率(下单锁定)',
'settlement_currency' => '', //'CNY' COMMENT '结算币种',
'remark' => '', //'备注',
// 'real_veh' => '', //'0' COMMENT '实车ID',
'is_final' => '', //'0' COMMENT '是否终版1是0否',
'status' => '', //'draft' COMMENT '单据状态:draft/submitted/approved/void/reversed等',
];
// (?<=\x60 )[^\r\n']*(?=')
$items = [
// 'id' => '', // '主键',
// 'order_id' => '', // '所属备货单ID',
// 'product_code' => '', // '商品编号(可作外部编码)',
// 'sku_snapshot' => '', // '商品/车型名称快照',
// 'unit_price_value_id' => '', // '单价',
// 'handling_fee_value_id' => '', // '操作费',
// 'fob_transport_fee_value_id' => '', // 'FOB内陆运费',
// 'port_misc_fee_value_id' => '', // '港杂费',
// 'retrofit_fee_value_id' => '', // '改装费',
// 'total_price_value_id' => '', // '合计(按订单结算币计算)',
'vin' => '', // '车架号',
'sku_id' => '', // '商品/车型ID(关联数据)',
'model_snapshot' => '', // '车型(若与sku一致可复用;此处为显示快照)',
'quantity' => '', // '1.000000' COMMENT '数量',
'color_interior_id' => '', // '颜色内饰ID(关联数据)',
'color_interior_snapshot' => '', // '颜色内饰名称快照',
'color_exterior_id' => '', // '颜色外饰ID(关联数据)',
'color_exterior_snapshot' => '', // '颜色外饰名称快照',
'remark' => '', // '备注',
'unit_price' => '', // '0.000000' COMMENT '单价(含/不含税按业务口径约定)',
'handling_fee' => '', // '0.000000' COMMENT '手续费(按单车)',
'fob_transport_fee' => '', // '0.000000' COMMENT 'FOB运输费(按单车)',
'port_misc_fee' => '', // '0.000000' COMMENT '港杂(按单车)',
'retrofit_fee' => '', // '0.000000' COMMENT '改装费(按单车)',
'total_price' => '', // '0.000000' COMMENT '总价(quantity*unit_price,写时落地)',
'official_price' => '', // 官方指导价
'discount_price' => '', // 优惠价
'modify_list' => [
// 'order_item_id' => '', // '所属明细ID',
'option_id' => '', // '配置项ID(关联数据)',
'option_name_snapshot' => '', // '配置项名称快照',
'option_price' => '', // '配置项价格(可选,写时快照)',
]
];
$account = [
'order_id' => '', // '所属备货单ID',
// 'seq_no' => '', // '1' COMMENT '账户序号(行号)',
'remit_country_id' => '', // '汇款国ID(关联数据)',
'remit_country_name_snapshot' => '', // '汇款国名称快照',
'remit_date' => '', // '汇款日期(时间戳)',
'currency_code' => '', // 'USD' COMMENT '币种代码(如USD/CNY/AED等)',
'currency_name_snapshot' => '', // '币种名称快照(可选)',
'account_id' => '', // '账户ID(关联数据)',
'account_name_snapshot' => '', // '账户名称/开户名快照',
'remitter_name' => '', // '汇款人',
'amount' => '', // '0.00' COMMENT '金额',
];
}
}
@@ -0,0 +1,59 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\Corp;
use app\common\model\SysCurrency;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysAccountService;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\Currency;
class SysAccountController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysAccountService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['currency_id']) && $data['currency_id'])
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
if (isset($data['corp_id']) && $data['corp_id'])
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['currency_id']))
$data['currency_name'] = SysCurrency::where('id', $data['currency_id'])->value('currency_name');
if (isset($data['corp_id']) && $data['corp_id'])
$data['corp_name'] = Corp::where('id', $data['corp_id'])->value('name');
return $data;
}
}
@@ -0,0 +1,63 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\Country;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysCurrencyService;
class SysCurrencyController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysCurrencyService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['last_updated']))
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
if (isset($data['country_id'])){
$data['country_name'] = Country::where('id',$data['country_id'])->value('item_label');
} else {
$data['country_name'] = '';
}
return $data;
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['last_updated']))
$data['last_updated'] = date('Y-m-d H:i:s', $data['last_updated']);
if (isset($data['country_id'])){
$data['country_name'] = Country::where('id',$data['country_id'])->value('item_label');
} else {
$data['country_name'] = '';
}
return $data;
}
}
@@ -0,0 +1,60 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictCategoryService;
use support\Request;
class SysDictCategoryController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictCategoryService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
public function preset(Request $request)
{
try {
$params = $request->all();
$result = (new SysDictCategoryService)->getList($params);
return $this->success($result, '获取字典项列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}
@@ -0,0 +1,95 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\SysDictItem;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictService;
use support\Request;
class SysDictController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['sysDictItem']))
$data['sysDictItem'] = SysDictItem::where('dict_id',$data['id'])->get();
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['category_id'])){
$data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label');
} else {
$data['category'] = '';
}
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
$data['sysDictItem'] = SysDictItem::where('dict_id',$data['id'])->get();
return $data;
}
public function listScopeFormat($data)
{
$rdata = [];
foreach ($data as $item) {
$rdata[$item['dict_code']] = $item['sysDictItem'];
}
return $rdata;
}
public function listScope(Request $request)
{
try {
$raw = $this->service->serviceListAllScope($request);
$data = $this->transformData($raw, method_exists($this, 'listScopeFormat')
? [$this, 'listScopeFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function group(Request $request)
{
try {
$raw = $this->service->group($request);
$data = $this->transformData($raw, method_exists($this, 'groupFormat')
? [$this, 'groupFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictItemService;
class SysDictItemController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictItemService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
}
@@ -0,0 +1,53 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\Country;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysPortService;
class SysPortController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysPortService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['country_id']))
if (isset($data['country_id']))
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr');
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
$data['country_name'] = Country::where('id', $data['country_id'])->value('cn_addr');
return $data;
}
}
+12
View File
@@ -154,4 +154,16 @@ class UserController extends BaseController
return $this->error($e->getMessage());
}
}
public function updateSign(Request $request)
{
try {
$data = $request->post();
$this->service->serviceUpdateSign($request, $data);
return $this->success([], '签名成功');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}
@@ -0,0 +1,48 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\VehColorService;
class VehColorController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehColorService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
}
@@ -0,0 +1,48 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\VehModificationService;
class VehModificationController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehModificationService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\admin\model\ApprovalFlows;
class ApprovalFlowsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalFlows::class;
}
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\admin\model\ApprovalInstances;
class ApprovalInstancesLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalInstances::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\admin\model\ApprovalRecords;
class ApprovalRecordsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalRecords::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\Brand;
class BrandLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Brand::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\BrandSeries;
class BrandSeriesLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = BrandSeries::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysAccount;
class SysAccountLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysAccount::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysCurrency;
class SysCurrencyLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysCurrency::class;
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDictCategory;
class SysDictCategoryLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictCategory::class;
public function getList()
{
return SysDictCategory::where('status', 1)->orderBy('sort','desc')->get(['id', 'category_name']);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDictItem;
class SysDictItemLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictItem::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDict;
class SysDictLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDict::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysPort;
class SysPortLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysPort::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehColor;
class VehColorLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehColor::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehModification;
class VehModificationLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehModification::class;
}
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace app\admin\model;
use support\Model;
class ApprovalFlows extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'approval_flows';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'name', 'type', 'steps', 'is_active', 'timeout_hours', 'timeout_action', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
protected $casts = [
'steps' => 'array',
];
}
+107
View File
@@ -0,0 +1,107 @@
<?php
namespace app\admin\model;
use app\common\model\StockOrders;
use app\common\model\User;
use support\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class ApprovalInstances extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'approval_instances';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
// protected $fillable = ['id', 'flow_type', 'biz_id', 'biz_type', 'form_data', 'initiator_id', 'status', 'current_step', 'finished_at', 'deadline_at', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
protected $fillable = [
'flow_type',
'biz_id',
'biz_type',
'form_data',
'initiator_id',
'status',
'current_step',
'finished_at',
'deadline_at',
];
protected $casts = [
'form_data' => 'array', // 自动转换 JSON 字段为数组
'finished_at' => 'datetime',
'deadline_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 一个审批实例可以有多个审批记录
*/
public function approvalRecords(): HasMany
{
return $this->hasMany(ApprovalRecords::class, 'instance_id');
}
/**
* 获取当前步骤的所有审批记录(pending 状态)
*/
public function currentStepRecords()
{
return $this->approvalRecords()
->where('step_index', $this->current_step)
->where('status', 'pending');
}
public function flows()
{
return $this->belongsTo(ApprovalFlows::class, 'flow_type', 'type');
}
public function initiator()
{
return $this->belongsTo(User::class, 'initiator_id', 'id');
}
public function bizInfo()
{
return $this->hasOne(StockOrders::class, 'id', 'biz_id');
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace app\admin\model;
use app\common\model\User;
use support\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ApprovalRecords extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'approval_records';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
// protected $fillable = ['id', 'instance_id', 'approver_id', 'step_index', 'action', 'status', 'comment', 'approved_at', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
protected $fillable = [
'instance_id',
'approver_id',
'step_index',
'action',
'status',
'comment',
'approved_at',
];
protected $casts = [
'approved_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 一条审批记录属于一个审批实例
*/
public function approvalInstance(): BelongsTo
{
return $this->belongsTo(ApprovalInstances::class, 'instance_id');
}
/**
* 关联审批人
*/
public function approver()
{
return $this->belongsTo(User::class, 'approver_id');
}
}
@@ -0,0 +1,62 @@
<?php
namespace app\admin\service;
use app\admin\validate\ApprovalFlowsValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\admin\model\ApprovalFlows;
use support\Request;
class ApprovalFlowsService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalFlows::class;
/**
* 验证器
*/
protected $validator = ApprovalFlowsValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
$config['order']['id'] = 'desc';
break;
case 'show':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
}
@@ -0,0 +1,31 @@
<?php
namespace app\admin\service;
use app\admin\validate\ApprovalInstancesValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\admin\model\ApprovalInstances;
class ApprovalInstancesService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalInstances::class;
/**
* 验证器
*/
protected $validator = ApprovalInstancesValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
}
@@ -0,0 +1,91 @@
<?php
namespace app\admin\service;
use app\admin\validate\ApprovalRecordsValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\admin\model\ApprovalRecords;
use support\Request;
class ApprovalRecordsService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = ApprovalRecords::class;
/**
* 验证器
*/
protected $validator = ApprovalRecordsValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
$config['order']['id'] = 'desc';
$config['with'] = [
'approvalInstance',
'approver',
'approvalInstance.flows',
'approvalInstance.initiator',
'approvalInstance.bizInfo'
];
// $config['dataLimit']['type'] = 'relation';
// $config['dataLimit']['userId'] = $request->user->uid;
// $config['dataLimit']['userField'] = 'approver_id';
break;
case 'show':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'logs':
$config['where']['instance_id'] = $p['instance_id'];
$config['order']['id'] = 'desc';
break;
}
return $config;
}
public function serviceApprove(Request $request)
{
$param = $request->all();
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
return $appro->approve($param['instance_id'], $request->user->uid, $param['action'], $param['comment']);
}
public function serviceLogs(Request $request)
{
$config = $this->buildQueryConfig($request, 'logs');
$item = $this->logicListAll($config);
return $this->postProcess('Logs', $item);
}
}
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace app\admin\service;
use app\admin\validate\BrandSeriesValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\BrandSeries;
use support\Request;
class BrandSeriesService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = BrandSeries::class;
/**
* 验证器
*/
protected $validator = BrandSeriesValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
$config['where']['brand_id'] = $p['brand_id'];
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['series_code','series_name'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace app\admin\service;
use app\admin\validate\BrandValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\Brand;
use support\Request;
class BrandService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Brand::class;
/**
* 验证器
*/
protected $validator = BrandValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['brand_code','brand_name'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
}
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysAccountValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysAccount;
use support\Request;
class SysAccountService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysAccount::class;
/**
* 验证器
*/
protected $validator = SysAccountValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 状态
if (isset($p['type']) && $p['type']) {
$config['where']['type'] = $p['type'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['account_name','account_number','bank_name','bank_branch','description'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysCurrencyValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysCurrency;
use app\common\utils\translation\service\TranslationService;
use app\queue\utils\Translat;
use support\Request;
class SysCurrencyService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysCurrency::class;
/**
* 验证器
*/
protected $validator = SysCurrencyValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构造 CrudUtil 查询配置
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'default':
$config['order']['id'] = 'desc';
case 'index':
break;
case 'show':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
public $translatFields = ['currency_name'];
public function afterServiceStore($res)
{
$sourceLocale = locale();
$data = $res->toArray();
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
(new TranslationService())->queueTranslations(
'sys_currency',
$res['id'],
$sourceLocale,
$traitsourceFields
);
}
}
@@ -0,0 +1,40 @@
<?php
namespace app\admin\service;
use app\admin\logic\SysDictCategoryLogic;
use app\admin\validate\SysDictCategoryValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysDictCategory;
use support\exception\BusinessException;
class SysDictCategoryService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictCategory::class;
/**
* 验证器
*/
protected $validator = SysDictCategoryValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 获取系统list
*/
public function getList($params)
{
return (new SysDictCategoryLogic)->getList();
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysDictItemValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysDictItem;
use app\common\utils\translation\service\TranslationService;
use app\queue\utils\Translat;
use support\Request;
class SysDictItemService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictItem::class;
/**
* 验证器
*/
protected $validator = SysDictItemValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
// ====== ====== 筛选 ====== ======
$config['where']['dict_id'] = $p['id'];
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['item_label','item_value','remark'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
break;
case 'show':
$config['where']['id'] = $p['id'];
break;
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
}
return $config;
}
public $translatFields = ['item_label','remark'];
public function afterServiceStore($res)
{
$sourceLocale = locale();
$data = $res->toArray();
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
(new TranslationService())->queueTranslations(
'sys_dict_item',
$res['id'],
$sourceLocale,
$traitsourceFields
);
}
}
+240
View File
@@ -0,0 +1,240 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysDictValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysDict;
use app\common\model\SysDictCategory;
use app\common\utils\translation\service\TranslationService;
use app\queue\utils\Translat;
use support\Request;
class SysDictService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDict::class;
/**
* 验证器
*/
protected $validator = SysDictValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'index'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 分类筛选
if (isset($p['category_id']) && !empty($p['category_id'])) {
$config['where']['category_id'] = $p['category_id'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['dict_name','dict_code','description'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
// ====== ====== 关联 ====== ======
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
case 'show':
$config['where']['id'] = $p['id'];
// ====== ====== 关联 ====== ======
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
case 'update':
case 'destroy':
$config['where']['id'] = $p['id'];
break;
case 'store':
break;
case 'scope':
$config['order']['id'] = 'desc';
// 决定查id还是code
$scopeType = 0;
if (isset($p['scope_type']) && $p['scope_type'] > 0) {
$scopeType = 1;
}
if (isset($p['scope']) && !empty($p['scope'])) {
if ($scopeType == 1) {
$config['where']['dict_code'] = ['in', explode(',', $p['scope'])];
} else {
$config['where']['id'] = ['in', explode(',', $p['scope'])];
}
}
$config['with']['sysDictItem'][] = 'dict_id';
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
case 'group':
$config['order']['id'] = 'desc';
$config['where']['id'] = 1;
$config['with']['sysDictItem'][] = 'dict_id';
$config['with']['sysDictItem'][] = 'item_label';
$config['with']['sysDictItem'][] = 'item_value';
break;
}
return $config;
}
public function group(Request $request)
{
$config = $this->buildQueryConfig($request, 'group');
$result = $this->logicShow($config);
return $this->postProcess('group', $result);
}
public function serviceListAllScope(Request $request)
{
$config = $this->buildQueryConfig($request, 'scope');
$result = $this->logicListAll($config);
return $this->postProcess('ListAllScope', $result);
}
public function afterServiceListAllScope($data)
{
// $data->each(function (&$item) {
// });
return $data;
}
public $translatFields = ['dict_name', 'description'];
public function afterServiceStore($res)
{
$sourceLocale = locale();
$data = $res->toArray();
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
(new TranslationService())->queueTranslations(
'sys_dict',
$res['id'],
$sourceLocale,
$traitsourceFields
);
}
/*
示例用法:
// 1) 获取分类为“车辆类型”的所有字典
$list = $dictService->getDictsByCategoryName('车辆类型');
// => [['dict_code' => 'SUV', 'dict_name' => '越野车'], …]
// 2) 获取某分类下某个 code 的名称
$name = $dictService->getDictName('车辆类型', 'SUV');
// => "越野车"
// 3) 获取某分类下拉选项
$options = $dictService->getDictOptions('车辆类型');
// => ['SUV' => '越野车', 'SEDAN' => '轿车', …]
// 4) 通过 code 直接拿名称(不管分类)
$name = $dictService->getNameByCode('SUV');
// => "越野车"
*/
/**
* 根据分类名获取字典列表
*/
public function getDictsByCategoryName(string $categoryName): array
{
$category = SysDictCategory::where('category_name', $categoryName)
->where('status', 1)
->first();
if (!$category) {
return [];
}
return $category->dicts()->get(['dict_code', 'dict_name'])->toArray();
}
/**
* 根据分类名 + 字典code 获取字典项名称
*/
public function getDictName(string $categoryName, string $dictCode): ?string
{
$dict = SysDict::whereHas('category', function ($q) use ($categoryName) {
$q->where('category_name', $categoryName)->where('status', 1);
})
->where('dict_code', $dictCode)
->where('status', 1)
->whereNull('deleted_at')
->first();
return $dict?->dict_name;
}
/**
* 根据分类名获取下拉键值对
* 返回格式:['code1' => '名称1', 'code2' => '名称2']
*/
public function getDictOptions(string $categoryName): array
{
$dicts = $this->getDictsByCategoryName($categoryName);
$options = [];
foreach ($dicts as $item) {
$options[$item['dict_code']] = $item['dict_name'];
}
return $options;
}
/**
* 根据字典 code 获取对应的名称(不依赖分类)
*/
public function getNameByCode(string $dictCode): ?string
{
$dict = SysDict::where('dict_code', $dictCode)
->where('status', 1)
->whereNull('deleted_at')
->first();
return $dict?->dict_name;
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysPortValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysPort;
use app\common\utils\translation\service\TranslationService;
use app\queue\utils\Translat;
use support\Request;
class SysPortService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysPort::class;
/**
* 验证器
*/
protected $validator = SysPortValidate::class;
public $translatFields = ['port_name','description'];
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['port_code','port_name'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
// 场景
if (isset($p['scene']) && $p['scene']) {
if($p['country_id'] == 'domestic'){
$config['where']['country_id'] = 45;
}else{
$config['where']['country_id'] = ['<>', 45];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
if(empty($data['lat']))
unset($data['lat']);
if(empty($data['lng']))
unset($data['lng']);
return $data;
}
public function afterServiceStore($res)
{
$sourceLocale = locale();
$data = $res->toArray();
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
(new TranslationService())->queueTranslations(
'sys_port_translation',
$res['id'],
$sourceLocale,
$traitsourceFields
);
}
/**
* 添加前置处理
*/
public function beforeServiceUpdate($data, Request $request)
{
if(empty($data['lat']))
unset($data['lat']);
if(empty($data['lng']))
unset($data['lng']);
return $data;
}
}
+13
View File
@@ -90,6 +90,9 @@ class UserService
if (isset($p['id']) && $p['id']) {
$config['where']['id'] = $p['id'];
}
if (isset($p['corp_id']) && $p['corp_id']) {
$config['where']['corp_id'] = $p['corp_id'];
}
$config['fields'] = ['id','sn', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'report_to', 'status', 'created_at'];
@@ -113,6 +116,7 @@ class UserService
$config['where']['id'] = $p['id'];
break;
case 'edit':
case 'updateSign':
$config['where']['id'] = $request->user->uid;
break;
}
@@ -154,4 +158,13 @@ class UserService
$user = $this->logicUpdateBy($config,$data);
return $user;
}
public function serviceUpdateSign(Request $request, array $data)
{
$config = $this->buildQueryConfig($request, 'updateSign');
$user = $this->logicUpdateBy($config,$data);
return $user;
}
}
+105
View File
@@ -0,0 +1,105 @@
<?php
namespace app\admin\service;
use app\admin\validate\VehColorValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\VehColor;
use app\common\utils\translation\service\TranslationService;
use app\queue\utils\Translat;
use support\Request;
class VehColorService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehColor::class;
/**
* 验证器
*/
protected $validator = VehColorValidate::class;
public $translatFields = ['color_text'];
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
public function afterServiceStore($res)
{
$sourceLocale = locale();
$data = $res->toArray();
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
(new TranslationService())->queueTranslations(
'veh_color_translation',
$res['id'],
$sourceLocale,
$traitsourceFields
);
}
/**
* 生成唯一的7位颜色编码
* 格式:C + (O/I) + 5位字母数字组合
*
* @param int $type 类型:2=I,其他=O
* @return string 7位唯一编码
*/
public function generateUniqueColorCode($type)
{
$secondChar = $type ==2 ? 'I' : 'O';
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$maxAttempts = 10; // 防止无限循环
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
// 生成后5位随机字符
$suffix = '';
for ($i = 0; $i < 5; $i++) {
$suffix .= $chars[rand(0, strlen($chars) - 1)];
}
$colorCode = 'C' . $secondChar . $suffix;
// 检查是否已存在
$existing = VehColor::where('color_code', $colorCode)->first();
if (!$existing) {
return $colorCode;
}
}
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
$timestamp = substr(time(), -5);
return 'C' . $secondChar . $timestamp;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$type = $data['type'] ?? 0;
$data['color_code'] = $this->generateUniqueColorCode($type);
$data['created_by'] = $request->user->uid;
$data['updated_by'] = $request->user->uid;
return $data;
}
/**
* 添加前置处理
*/
public function beforeServiceUpdate($data, Request $request)
{
$data['updated_by'] = $request->user->uid;
return $data;
}
}
@@ -0,0 +1,126 @@
<?php
namespace app\admin\service;
use app\admin\validate\VehModificationValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\VehModification;
use support\Request;
class VehModificationService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehModification::class;
/**
* 验证器
*/
protected $validator = VehModificationValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 状态
if (isset($p['type']) && $p['type']) {
$config['where']['type'] = $p['type'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['code','name'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
/**
* 生成唯一的7位颜色编码
* 格式:C + (O/I) + 5位字母数字组合
*
* @param int $type 类型
* @return string 7位唯一编码
*/
public function generateUniqueModificationCode($type)
{
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$maxAttempts = 10; // 防止无限循环
for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
// 生成后5位随机字符
$suffix = '';
for ($i = 0; $i < 5; $i++) {
$suffix .= $chars[rand(0, strlen($chars) - 1)];
}
$code = 'C' . $type . $suffix;
// 检查是否已存在
$existing = VehModification::where('code', $code)->first();
if (!$existing) {
return $code;
}
}
// 如果1000次尝试后仍然重复,使用时间戳确保唯一性
$timestamp = substr(time(), -5);
return 'C' . $type . $timestamp;
}
/**
* 添加前置处理
*/
public function beforeServiceStore($data, Request $request)
{
$type = $data['type'] ?? 0;
$data['code'] = $this->generateUniqueModificationCode($type);
return $data;
}
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class ApprovalFlowsValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class ApprovalInstancesValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class ApprovalRecordsValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class BrandSeriesValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class BrandValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysAccountValidate extends Validate
{
// 规则
protected $rule = [
'corp_id' => 'require|integer|gt:0',
];
// 提示
protected $message = [
'corp_id.require' => 'ID不能为空',
'corp_id.integer' => 'ID必须是整数',
'corp_id.gt' => 'ID必须大于0',
];
// 场景
protected $scene = [
'store' => [
'corp_id'
],
'update' => [
'corp_id'
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysCurrencyValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysDictCategoryValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysDictItemValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysDictValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysPortValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class VehColorValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class VehModificationValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}
+103
View File
@@ -3,6 +3,15 @@
namespace app\common\controller;
use app\admin\service\RoleService;
use app\common\service\BrandSeriesService;
use app\common\service\BrandService;
use app\common\service\SysAccountService;
use app\common\service\SysCurrencyService;
use app\common\service\SysDictItemService;
use app\common\service\SysDictService;
use app\common\service\SysPortService;
use app\common\service\VehColorService;
use app\common\service\VehModificationService;
use support\Request;
use app\common\service\CorpService;
use app\common\service\CorpFeishuAppService;
@@ -76,6 +85,100 @@ class PresetController extends BaseController
}
}
public function currency()
{
try {
$result = (new SysCurrencyService)->getList();
return $this->success($result, '获取货币列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function brand()
{
try {
$result = (new BrandService)->getList();
return $this->success($result, '获取品牌列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function series(Request $request)
{
try {
$params = $request->all();
$result = (new BrandSeriesService)->getList($params);
return $this->success($result, '获取车系列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function account()
{
try {
$result = (new SysAccountService)->getList();
return $this->success($result, '获取账号列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function dict()
{
try {
$result = (new SysDictService)->getList();
return $this->success($result, '获取字典列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function dictItem(Request $request)
{
try {
$params = $request->all();
$result = (new SysDictItemService)->getList($params);
return $this->success($result, '获取字典项列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function port(Request $request)
{
try {
$params = $request->all();
$result = (new SysPortService)->getList($params);
return $this->success($result, '获取港口列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function color(Request $request)
{
try {
$params = $request->all();
$result = (new VehColorService)->getList($params);
return $this->success($result, '获取颜色列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function modification()
{
try {
$result = (new VehModificationService)->getList();
return $this->success($result, '获取货币列表');
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function cacheClear()
{
+174 -3
View File
@@ -3,8 +3,12 @@
namespace app\common\controller;
use app\common\service\OssService;
use app\common\service\UploadedFilesService;
use app\common\service\UploadService;
use app\common\traits\ResponseTrait;
use support\Log;
use support\Request;
use support\exception\BusinessException;
use Shopwwi\WebmanFilesystem\Facade\Storage;
class UploadController
@@ -22,15 +26,41 @@ class UploadController
$scene = $request->input('scene', 'image');
$file = $request->file('file');
if ($file && $file->isValid()) {
$pathUrl = '/uploads/'.$scene.'/'.date('Ymd').'/'.md5($file->getUploadName() . time()).'.'.$file->getUploadExtension();
$fileName = md5($file->getUploadName() . time()).'.'.$file->getUploadExtension();
$pathUrl = '/uploads/'.$scene.'/'.date('Ymd').'/'.$fileName;
$fullPathUrl = public_path() . $pathUrl;
$file->move($fullPathUrl);
$data = [
'domain' => getenv('MAIN_DOMAIN'),
'file_url' => $pathUrl,
'full_url' => getenv('MAIN_DOMAIN') . $pathUrl,
'scene' => $scene,
];
// 记录文件信息到数据库
try {
$uploadedFilesService = new UploadedFilesService();
$partition = $scene;
$category = $request->input('category', 'general');
$fileInfo = [
'file_name' => basename($fileName),
'file_path' => $pathUrl,
'file_size' => $file->getSize(),
'file_type' => $file->getUploadMimeType(),
'original_name' => $file->getUploadName(),
];
$recordResult = $uploadedFilesService->recordFileInfo($fileInfo, $request, $partition, $category);
$data['file_id'] = $recordResult['id'];
$data['partition'] = $partition;
$data['category'] = $category;
} catch (\Throwable $e) {
// 记录失败不影响上传结果,只记录日志
Log::error('记录文件信息失败: ' . $e->getMessage());
}
return $this->success($data, 'upload success');
}
return $this->error('file not found');
@@ -43,15 +73,22 @@ class UploadController
public function uploadFile(Request $request)
{
try {
$scene = $request->input('scene');
$file = $request->file('file');
if (!$file || !$file->isValid()) {
return $this->error('上传失败');
}
if (empty($scene)) {
// return $this->error('上传场景不能为空');
$sceneUrl = '';
}else{
$sceneUrl = $scene . '/';
}
$originalName = $file->getUploadName();
$result = Storage::adapter('oss')
->path('vehicle_album/'.date('Ymd'))
->path('x_server/' . $sceneUrl . date('Ymd'))
->size(1024*1024*5)
->upload($file);
@@ -63,6 +100,11 @@ class UploadController
'file_url' => $ossservice->generatePrivateUrl($result->file_name)
];
// 记录文件信息到数据库
$category = $request->input('category', 'general');
$res = $this->recordFileInfo($result,$request,$file,$scene,$category);
$data = array_merge($data, $res);
return $this->success($data);
}catch (\Throwable $e){
return $this->error($e->getMessage());
@@ -73,14 +115,21 @@ class UploadController
public function uploadImage(Request $request)
{
try {
$scene = $request->input('scene');
$file = $request->file('image');
if (!$file || !$file->isValid()) {
return $this->error('上传失败');
}
if (empty($scene)) {
// return $this->error('上传场景不能为空');
$sceneUrl = '';
}else{
$sceneUrl = $scene . '/';
}
$result = Storage::adapter('oss')
->path('vehicle_album/'.date('Ymd'))
->path('x_server/' . $sceneUrl . date('Ymd'))
->size(1024*1024*5)
->extYes(['image/jpeg','image/png'])
->extNo(['image/gif'])
@@ -94,6 +143,11 @@ class UploadController
'url' => $ossservice->generatePrivateUrl($result->file_name)
];
// 记录文件信息到数据库
$category = $request->input('category', 'general');
$res = $this->recordFileInfo($result,$request,$file,$scene,$category);
$data = array_merge($data, $res);
return json(['errno' => 0, 'data' => $data]);
// return $this->success($data);
} catch (\Throwable $e) {
@@ -102,6 +156,123 @@ class UploadController
}
}
public function recordFileInfo($result, $request, $file, $scene, $category)
{
try {
$uploadedFilesService = new UploadedFilesService();
$partition = $scene;
$fileInfo = [
'file_name' => basename($result->file_name),
'file_path' => $result->file_name, // OSS存储路径
'file_size' => $file->getSize(),
'file_type' => $file->getUploadMimeType(),
'original_name' => $file->getUploadName(),
];
$recordResult = $uploadedFilesService->recordFileInfo($fileInfo, $request, $partition, $category);
$data = [];
$data['file_id'] = $recordResult['id'];
$data['partition'] = $partition;
$data['category'] = $category;
return $data;
} catch (\Throwable $e) {
// 记录失败不影响上传结果,只记录日志
Log::error('记录文件信息失败: ' . $e->getMessage());
return [];
}
}
/**
* 获取文件信息
*
* @param Request $request
* @return \support\Response
*/
public function getFileInfo(Request $request)
{
try {
$fileId = $request->input('id');
if (!$fileId) {
return $this->error('文件ID不能为空');
}
$uploadedFilesService = new UploadedFilesService();
$fileInfo = $uploadedFilesService->getFileInfo($fileId);
if (!$fileInfo) {
return $this->error('文件不存在');
}
return $this->success($fileInfo);
} catch (\Throwable $e) {
return $this->error('获取文件信息失败: ' . $e->getMessage());
}
}
/**
* 删除文件
*
* @param Request $request
* @return \support\Response
*/
public function deleteFile(Request $request)
{
try {
$fileId = $request->input('id');
$path = $request->input('path');
$uploadedFilesService = new UploadedFilesService();
if(!empty($path) && empty($fileId)){
$where = ['file_path' => $path];
$file = $uploadedFilesService->getFile($where);
$fileId = $file->id;
}elseif(empty($path) && !empty($fileId)){
$where = ['id' => $fileId];
$file = $uploadedFilesService->getFile($where);
$path = $file->file_path;
}
if (!$fileId) {
return $this->error('文件ID与路径不能为空');
}
// 删除 OSS 上的文件
$ossService = new OssService();
$ossService->deleteFile($path);
$result = $uploadedFilesService->deleteFile($fileId);
if ($result) {
return $this->success([], '文件删除成功');
} else {
return $this->error('文件删除失败');
}
} catch (\Throwable $e) {
return $this->error('文件删除失败: ' . $e->getMessage());
}
}
/**
* 获取分区配置
*
* @param Request $request
* @return \support\Response
*/
public function getPartitionConfig(Request $request)
{
try {
$uploadedFilesService = new UploadedFilesService();
$config = $uploadedFilesService->getPartitionConfig();
return $this->success($config);
} catch (\Throwable $e) {
return $this->error('获取分区配置失败: ' . $e->getMessage());
}
}
public function proxy(Request $request)
{
$filePath = $request->get('file'); // 原OSS文件路径
@@ -0,0 +1,56 @@
<?php
namespace app\common\controller;
use app\common\model\User;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\VehColorService;
class VehColorController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehColorService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['created_by']) && $data['created_by'])
$data['created_by_name'] = User::where('id', $data['created_by'])->value('name');
if (isset($data['updated_by']) && $data['updated_by'])
$data['updated_by_name'] = User::where('id', $data['updated_by'])->value('name');
return $data;
}
/**
* 数据格式化
*
* @param array $data
* @return array
*/
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['created_by']) && $data['created_by'])
$data['created_by_name'] = User::where('id', $data['created_by'])->value('name');
if (isset($data['updated_by']) && $data['updated_by'])
$data['updated_by_name'] = User::where('id', $data['updated_by'])->value('name');
return $data;
}
}
@@ -0,0 +1,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehDictI18nService;
class VehDictI18nController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehDictI18nService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehDictMappingService;
class VehDictMappingController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehDictMappingService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehMoneyValueService;
class VehMoneyValueController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehMoneyValueService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehVehicleListingService;
class VehVehicleListingController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehVehicleListingService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
@@ -0,0 +1,204 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehVehicleSkuService;
use support\exception\BusinessException;
use support\Request;
class VehVehicleSkuController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehVehicleSkuService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
protected function showFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
return $data;
}
public function store(Request $request)
{
try {
$data = $this->validate($this->service->getValidator(), $request->post(), 'store');
$res = $this->service->serviceStore($request, $data);
return $this->success($res, '创建成功');
} catch (\PDOException $e) {
$errorCode = $e->getCode();
$errorMessage = $e->getMessage();
if ($errorCode == '23000') {
if (strpos($errorMessage, "Duplicate entry") !== false && strpos($errorMessage, "uk_fingerprint") !== false) {
return $this->error("该车辆指纹已存在,请勿重复提交");
}
// 其他类型的完整性约束错误
throw new BusinessException("数据完整性错误", 0, $e);
}
// 重新抛出其他类型的异常
throw $e;
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function update(Request $request)
{
try {
$data = $this->validate($this->service->getValidator(), $request->post(), 'update');
$res = $this->service->serviceUpdate($request, $data);
return $this->success([], '更新成功');
} catch (\PDOException $e) {
$errorCode = $e->getCode();
$errorMessage = $e->getMessage();
if ($errorCode == '23000') {
if (strpos($errorMessage, "Duplicate entry") !== false && strpos($errorMessage, "uk_fingerprint") !== false) {
return $this->error("该车辆指纹已存在,请勿重复提交");
}
// 其他类型的完整性约束错误
throw new BusinessException("数据完整性错误", 0, $e);
}
// 重新抛出其他类型的异常
throw $e;
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
public function fields_desc(Request $request)
{
$data = [
'sku_code' , // 'SKU编码,系统生成',
'fingerprint' , // '规格指纹(sha256)去重',
'brand_code' , // '品牌代码,如 BYD、HYUNDAI、KIA',
'brand_name' , // '品牌名称展示,如 比亚迪、现代、起亚',
'series_code' , // '车系代码,如 ELANTRA、SONGPLUS',
'series_name' , // '车系名称展示',
'model_code' , // '车型/配置代码(工厂/内部编码)',
'model_name' , // '车型/配置名称(可读,如 伊兰特 1.5L、海狮07)',
'model_year' , // '年款(YYYY)',
'trim_code' , // '版型代码(TRIM)',
'trim_level_code' , // '配置等级代码(TRIM_LEVEL)',
'edition_code' , // '特别版代码(EDITION)',
'trim' , // '版型/细分配置(如 TOP旗舰版、荣耀版)',
'trim_level' , // '配置等级(豪华型/旗舰型等,便于筛选)',
'edition_name' , // '特别版/纪念版(如 荣耀版、致敬版等)',
'body_type_code' , // '车身类型:SEDAN/SUV/HB/MPV/Pickup',
'drive_type_code' , // '驱动:FWD/RWD/AWD/4WD',
'motor_layout_code' , // '电驱/电机布置(MOTOR_LAYOUT):FWD/RWD/AWD/DM-i/DM-p 等',
'fuel_type_code' , // '能源:GAS/HEV/PHEV/EV/EREV',
'engine_disp_l' , // '排量(L),如 1.5;纯电为空',
'engine_turbo' , // '0' COMMENT '是否涡轮(0/1)',
'engine_power_kw' , // '最大功率(kW)',
'battery_kwh' , // '电池容量(kWh)',
'transmission_code' , // '变速箱:MT/AT/CVT/DCT/1SPEED',
'gears' , // '挡位数(EV多为1)',
'range_km' , // '续航里程(km)',
'range_std_code' , // '续航标准:CLTC/WLTP/EPA/NEDC',
'doors' , // '门数',
'seats' , // '座位数',
'weight_kg' , // '整备质量(kg)',
'dimensions_mm' , // '尺寸(mm):{length,width,height,wheelbase}',
'color_exterior_code' , // '外观色代码',
'color_exterior_text' , // '外观色名称',
'color_interior_code' , // '内饰色代码',
'color_interior_text' , // '内饰色名称',
'options_official' , // '官方选装(结构化 JSON)',
'features' , // '功能/安全/智能配置(结构化 JSON)',
'emission_std_code' , // '排放标准:CHN6/EURO6/EPA',
'origin_country' , // '原产国 ISO-3166-1 alpha-2',
'currency' , // 'CNY' COMMENT '币种 ISO-4217',
'msrp' , // '建议零售价/参考价',
'is_active' , // '1' COMMENT '启用(1)/禁用(0)',
'corp_id' , // '0' COMMENT '租户/公司(全局库可写0)',
'remark' , // '备注',
'created_by' , // '0',
'updated_by' , // '0',
];
$data = [
'fingerprint' , // '规格指纹(sha256)去重',
'brand_name' , // '品牌名称展示,如 比亚迪、现代、起亚',
'series_name' , // '车系名称展示',
'model_name' , // '车型/配置名称(可读,如 伊兰特 1.5L、海狮07)',
'model_year' , // '年款(YYYY)',
'trim' , // '版型/细分配置(如 TOP旗舰版、荣耀版)',
'trim_level' , // '配置等级(豪华型/旗舰型等,便于筛选)',
'edition_name' , // '特别版/纪念版(如 荣耀版、致敬版等)',
'engine_disp_l' , // '排量(L),如 1.5;纯电为空',
'engine_turbo' , // '0' COMMENT '是否涡轮(0/1)',
'engine_power_kw' , // '最大功率(kW)',
'battery_kwh' , // '电池容量(kWh)',
'gears' , // '挡位数(EV多为1)',
'range_km' , // '续航里程(km)',
'doors' , // '门数',
'seats' , // '座位数',
'weight_kg' , // '整备质量(kg)',
'dimensions_mm' , // '尺寸(mm):{length,width,height,wheelbase}',
'color_exterior_text' , // '外观色名称',
'color_interior_text' , // '内饰色名称',
'options_official' , // '官方选装(结构化 JSON)',
'features' , // '功能/安全/智能配置(结构化 JSON)',
'origin_country' , // '原产国 ISO-3166-1 alpha-2',
'currency' , // 'CNY' COMMENT '币种 ISO-4217',
'msrp' , // '建议零售价/参考价',
'is_active' , // '1' COMMENT '启用(1)/禁用(0)',
'corp_id' , // '0' COMMENT '租户/公司(全局库可写0)',
'remark' , // '备注',
'created_by' , // '0',
'updated_by' , // '0',
'body_type', // '车身类型'
'drive_type', // '驱动:FWD/RWD/AWD/4WD',
'motor_layout', // '电机布置(MOTOR_LAYOUT):FWD/RWD/AWD/DM-i/DM-p 等'
'fuel_type', // '能源:GAS/HEV/PHEV/EV/EREV'
'transmission', // '变速箱:MT/AT/CVT/DCT/1SPEED'
'range_std', // '续航标准:CLTC/WLTP/EPA/NEDC'
'emission_std', // '排放标准:CHN6/EURO6/EPA'
'sku_code' , // 'SKU编码,系统生成',
'brand_code' , // '品牌代码,如 BYD、HYUNDAI、KIA',
'series_code' , // '车系代码,如 ELANTRA、SONGPLUS',
'model_code' , // '车型/配置代码(工厂/内部编码)',
'trim_code' , // '版型代码(TRIM)',
'trim_level_code' , // '配置等级代码(TRIM_LEVEL)',
'edition_code' , // '特别版代码(EDITION)',
'color_exterior_code' , // '外观色代码',
'color_interior_code' , // '内饰色代码',
'body_type_code' , // '车身类型:SEDAN/SUV/HB/MPV/Pickup',
'drive_type_code' , // '驱动:FWD/RWD/AWD/4WD',
'motor_layout_code' , // '电驱/电机布置(MOTOR_LAYOUT):FWD/RWD/AWD/DM-i/DM-p 等',
'fuel_type_code' , // '能源:GAS/HEV/PHEV/EV/EREV',
'transmission_code' , // '变速箱:MT/AT/CVT/DCT/1SPEED',
'range_std_code' , // '续航标准:CLTC/WLTP/EPA/NEDC',
'emission_std_code' , // '排放标准:CHN6/EURO6/EPA',
];
}
}
@@ -0,0 +1,33 @@
<?php
namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\VehVehicleUnitService;
class VehVehicleUnitController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new VehVehicleUnitService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\Brand;
class BrandLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Brand::class;
public function getList()
{
return Brand::where('status', 1)->orderBy('sort','desc')->get(['id', 'brand_code', 'brand_name', 'logo', 'description']);
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\BrandSeries;
class BrandSeriesLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = BrandSeries::class;
public function getList($where)
{
return BrandSeries::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'series_code', 'series_name', 'description']);
}
}
+262
View File
@@ -0,0 +1,262 @@
<?php
namespace app\common\logic;
/**
* Fingerprint
*
* 目标:
* - 默认“强制所有字段参与计算”,保证相同记录生成同一指纹
* - 通过统一规范化策略,避免无意义差异(空白、大小写、JSON键序)导致指纹抖动
* - 仅排除技术字段:id、fingerprint(可通过参数自行增删)
*
* 用法:
* $hash = Fingerprint::makeFromArray($payload); // 创建前
* $hash = Fingerprint::makeFromModel($skuModel); // 已有模型
* $hash = Fingerprint::makeFromArray($payload, ['exclude'=>['msrp']]); // 可选排除
*/
class Fingerprint
{
/** 你的 veh_vehicle_sku 所有列(保持与表结构一致,顺序无关但建议完整) */
public const COLS = [
'id','sku_code','fingerprint',
'brand_code','brand_name','series_code','series_name',
'model_code','model_name','model_year',
'trim_code','trim_level_code','edition_code',
'trim','trim_level','edition_name',
'body_type_code','drive_type_code','motor_layout_code','fuel_type_code',
'engine_disp_l','engine_turbo','engine_power_kw','battery_kwh',
'transmission_code','gears','range_km','range_std_code',
'doors','seats','weight_kg','dimensions_mm',
'color_exterior_code','color_exterior_text',
'color_interior_code','color_interior_text',
'options_official','features','emission_std_code',
'origin_country','currency','msrp',
'is_active','corp_id','remark',
'created_by','updated_by','created_at','updated_at',
];
/** 默认剔除:技术/循环依赖字段 */
public const EXCLUDE_DEFAULT = [
'id','sku_code','fingerprint', 'dimensions_mm', 'options_official', 'features',
'origin_country','currency','msrp',
'is_active','corp_id','remark',
'created_by','updated_by','created_at','updated_at'
];
/** 识别为“code类”的字段模式(统一大写) */
private const CODE_FIELD_REGEX = '/(_code|_country|^currency)$/i';
/** 识别为 JSON 字段 */
private const JSON_FIELDS = ['dimensions_mm','options_official','features'];
/**
* 从 Eloquent 模型生成
*/
public static function makeFromModel($model, array $opts = []): string
{
return self::makeFromArray($model->toArray(), $opts);
}
/**
* 从数组生成指纹
* @param array $row 一般为 $_POST 合并后的业务数据或 $model->toArray()
* @param array $opts ['exclude'=>[], 'extra'=>[], 'salt'=>string]
* - exclude: 额外排除的字段(默认仅排除 id,fingerprint)
* - extra : 额外拼入的键值(例如上下文、租户策略),会参与计算
* - salt : 额外加盐字符串
*/
public static function makeFromArray(array $row, array $opts = []): string
{
$exclude = array_values(array_unique(array_merge(self::EXCLUDE_DEFAULT, $opts['exclude'] ?? [])));
$extra = $opts['extra'] ?? [];
$salt = $opts['salt'] ?? '';
// 1) 统一抽取“表中定义的字段” + extra,缺失字段也要纳入(值按 NULL 处理)
$data = [];
foreach (self::COLS as $col) {
if (in_array($col, $exclude, true)) continue;
$data[$col] = array_key_exists($col, $row) ? $row[$col] : null;
}
// extra 也参与
foreach ($extra as $k => $v) {
if (!is_string($k) || $k === '') continue;
$data['__extra__'.$k] = $v;
}
// 2) 规范化(按字段特征)
$canon = [];
foreach ($data as $k => $v) {
$canon[$k] = self::normalize($k, $v);
}
// 3) 键名排序,确保顺序无关
ksort($canon, SORT_STRING);
// 4) 拼成稳定串: key=value | key=value...
$parts = [];
foreach ($canon as $k => $v) {
// 为空也必须占位,避免 key 消失影响其他键的意义
$parts[] = $k.'='.$v;
}
if ($salt !== '') {
$parts[] = '__salt__='.$salt;
}
$plain = implode('|', $parts);
// 5) sha256
return hash('sha256', $plain);
}
/**
* 规范化单个字段
* - NULL -> 特殊占位 "∅"(避免与空串混淆)
* - 布尔/整数/浮点 -> 统一数字字符串
* - code类字段 -> 去首尾空白 & 转大写
* - 普通字符串 -> trim & 压缩连续空白为单空格
* - JSON字段 -> 解析后做“键排序 + 值规范化 + 索引数组可排序”,再无空白编码
*/
private static function normalize(string $field, $value): string
{
if ($value === null) return '∅';
// 数值类型
if (is_int($value)) return (string)$value;
if (is_bool($value)) return $value ? '1' : '0';
if (is_float($value) || (is_string($value) && is_numeric($value) && self::looksLikeNumberField($field))) {
// 统一浮点格式,最多 6 位小数并去尾零
$num = (float)$value;
$s = number_format($num, 6, '.', '');
$s = rtrim(rtrim($s, '0'), '.');
return $s === '' ? '0' : $s;
}
// JSON 字段
if (in_array($field, self::JSON_FIELDS, true)) {
return self::normalizeJson($value);
}
// 字符串
if (is_string($value)) {
$s = trim($value);
// code类:统一大写
if (preg_match(self::CODE_FIELD_REGEX, $field)) {
$s = mb_strtoupper($s, 'UTF-8');
} else {
// 普通文本:压缩连续空白
$s = preg_replace('/\s+/u', ' ', $s);
}
return $s === '' ? '' : $s;
}
// 数组(极少出现,按 JSON 处理)
if (is_array($value)) {
return self::normalizeJson($value);
}
// 其他类型(对象等):转 JSON 后处理
return self::normalizeJson($value);
}
/** 判断这个字段是否“看起来像数值字段” */
private static function looksLikeNumberField(string $field): bool
{
static $numKeys = [
'engine_disp_l','engine_power_kw','battery_kwh','gears',
'range_km','doors','seats','weight_kg','msrp','model_year',
'created_at','updated_at','corp_id','is_active'
];
return in_array($field, $numKeys, true);
}
/**
* JSON 规范化:
* - 字符串:若能 json_decode 则按 JSON;否则当普通字符串再规范化
* - 对象:键名排序;值递归规范化
* - 索引数组:元素递归规范化后,按字符串值排序(视为集合,避免顺序抖动)
* - 最终 json_encode(JSON_UNESCAPED_UNICODE|UNESCAPED_SLASHES)
*/
private static function normalizeJson($val): string
{
// 已是数组/对象
if (is_array($val)) {
$normalized = self::canonArray($val);
return json_encode($normalized, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
// 字符串尝试解析
if (is_string($val)) {
$val = trim($val);
if ($val === '') return '""';
$decoded = json_decode($val, true);
if (json_last_error() === JSON_ERROR_NONE) {
$normalized = self::canonArray($decoded);
return json_encode($normalized, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
// 非 JSON 字符串,按普通字符串规范化
$s = preg_replace('/\s+/u', ' ', $val);
return json_encode($s, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
// 其他类型:直接编码
return json_encode($val, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
/** 递归规范化数组/对象 */
private static function canonArray($arr)
{
if (!is_array($arr)) return $arr;
// 关联数组(对象)
if (self::isAssoc($arr)) {
$out = [];
ksort($arr, SORT_STRING);
foreach ($arr as $k => $v) {
$out[(string)$k] = self::canonValue($v);
}
return $out;
}
// 索引数组(当集合处理:元素字符串化后排序)
$tmp = [];
foreach ($arr as $v) {
$tmp[] = self::canonValue($v);
}
// 将元素转为字符串再排序,确保稳定
usort($tmp, function($a, $b) {
$sa = is_scalar($a) ? (string)$a : json_encode($a, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
$sb = is_scalar($b) ? (string)$b : json_encode($b, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
return strcmp($sa, $sb);
});
return $tmp;
}
private static function canonValue($v)
{
if (is_array($v)) return self::canonArray($v);
if (is_bool($v)) return $v ? 1 : 0;
if (is_int($v)) return $v;
if (is_float($v)) {
$s = number_format($v, 6, '.', '');
$s = rtrim(rtrim($s, '0'), '.');
return $s === '' ? '0' : $s;
}
if (is_string($v)) {
$s = trim($v);
$s = preg_replace('/\s+/u', ' ', $s);
return $s;
}
return $v;
}
private static function isAssoc(array $arr): bool
{
// 有任意一个键不是 0..n 的递增整数,就视为关联数组
$i = 0;
foreach ($arr as $k => $_) {
if ($k !== $i++) return true;
}
return false;
}
}
+101
View File
@@ -0,0 +1,101 @@
<?php
namespace app\common\logic;
final class ModelNaming
{
/** 生成稳定的 model_code(只用 *_code 与关键数字) */
public static function buildModelCode(array $s): string
{
$brand = self::tok($s['brand_code'] ?? '');
$series = self::tok($s['series_code'] ?? '');
$fuel = self::tok($s['fuel_type_code'] ?? 'UNK');
$parts = [$brand, $series];
$key = [];
switch ($fuel) {
case 'EV':
$key[] = 'EV';
if (!empty($s['range_km'])) {
$key[] = (string) (round((int)$s['range_km'] / 10) * 10); // 到十位
} elseif (!empty($s['battery_kwh'])) {
$key[] = self::numToken($s['battery_kwh']) . 'KWH';
}
break;
case 'GAS':
if (!empty($s['engine_disp_l'])) $key[] = self::dispToken($s['engine_disp_l']); // 1.5L -> 15L
if (!empty($s['engine_turbo']) && (int)$s['engine_turbo'] === 1) $key[] = 'T';
if (!empty($s['transmission_code'])) $key[] = self::tok($s['transmission_code']);
break;
case 'HEV':
case 'PHEV':
case 'EREV':
$key[] = $fuel;
if (!empty($s['engine_disp_l'])) $key[] = self::dispToken($s['engine_disp_l']);
if (!empty($s['motor_layout_code'])) $key[] = self::tok($s['motor_layout_code']); // 如 DM-I/DM-P/AWD
break;
default:
$key[] = $fuel;
}
if (!empty($s['drive_type_code'])) $key[] = self::tok($s['drive_type_code']);
$parts[] = implode('_', array_filter($key));
return strtoupper(implode('_', array_filter($parts)));
}
/** 生成中文可读的 model_name(走快照中文,不依赖 i18n) */
public static function buildModelName(array $s): string
{
$seriesName = trim((string)($s['series_name'] ?? $s['series_code'] ?? ''));
$yearPart = !empty($s['model_year']) ? ($s['model_year'] . '款 ') : '';
$fuel = strtoupper($s['fuel_type_code'] ?? '');
$tail = '';
if ($fuel === 'EV') {
$range = !empty($s['range_km']) ? (int)$s['range_km'] . 'KM ' : '';
$drive = trim((string)($s['drive_type'] ?? $s['drive_type_code'] ?? ''));
$tail = "EV {$range}{$drive}";
} elseif ($fuel === 'GAS') {
$disp = (!empty($s['engine_disp_l']))
? rtrim(rtrim(number_format((float)$s['engine_disp_l'], 1, '.', ''), '0'), '.') . 'L '
: '';
$trans = trim((string)($s['transmission'] ?? $s['transmission_code'] ?? ''));
$tail = "{$disp}{$trans}";
} else {
$tail = trim((string)($s['fuel_type'] ?? $fuel));
}
$extras = [];
foreach (['trim','trim_level','edition_name'] as $k) {
if (!empty($s[$k])) $extras[] = trim((string)$s[$k]);
}
$extraStr = $extras ? ' ' . implode(' ', $extras) : '';
return trim($seriesName . ' ' . $yearPart . $tail . $extraStr);
}
/* ===== Helpers ===== */
private static function tok($v): string
{
$v = strtoupper((string)$v);
return preg_replace('/[^A-Z0-9_]/', '', $v ?? '');
}
private static function numToken($v): string
{
return preg_replace('/[^0-9]/', '', (string)$v);
}
/** 1.5L -> 15L;2.0L -> 20L(便于 code 稳定检索) */
private static function dispToken($l): string
{
$x = (float)$l;
return (string)round($x * 10) . 'L';
}
}
+233
View File
@@ -0,0 +1,233 @@
<?php
namespace app\common\logic;
use app\common\model\VehVehicleSku;
/**
* SKU 生成器
* - 输入: 车辆规格数组(以 *_code 为主)
* - 输出: 稳定、人读友好的 sku_code (<= 40 默认)
*/
final class SkuCodeBuilder
{
/** 压缩映射(可按需扩充) */
private const ABBR = [
// level
'FLAGSHIP' => 'FLG',
'PREMIUM' => 'PRM',
'STANDARD' => 'STD',
'DELUXE' => 'DLX',
// edition
'HONOR' => 'HNR',
'CHAMPION' => 'CHP',
'ANNIV' => 'ANV',
// trans
'1SPEED' => '1SP',
// drive/fuel/body 等一般已短,不必压缩
];
/** 入口:生成 sku_code */
public static function build(array $s, array $opts = []): string
{
$maxLen = $opts['max_len'] ?? 40;
$ensureUnique = $opts['ensure_unique'] ?? true;
$tokens = [
'brand' => self::tok($s['brand_code'] ?? ''),
'series' => self::tok($s['series_code'] ?? ''),
'year' => isset($s['model_year']) ? (string)intval($s['model_year']) : '',
'fuel' => self::tok($s['fuel_type_code'] ?? ''),
'drive' => self::tok($s['drive_type_code'] ?? ''),
'spec' => self::buildSpec($s, self::tok($s['fuel_type_code'] ?? '')),
'level' => self::abbr(self::tok($s['trim_level_code'] ?? '')),
'edition' => self::abbr(self::tok($s['edition_code'] ?? '')),
];
// 过滤空段并按既定顺序拼接
$order = ['brand','series','year','fuel','drive','spec','level','edition'];
$parts = [];
foreach ($order as $k) {
if (!empty($tokens[$k])) $parts[$k] = $tokens[$k];
}
$sku = self::normalizeSku(implode('-', $parts));
if (strlen($sku) > $maxLen) {
$sku = self::shrink($parts, $maxLen); // 传入“带键名的 parts”
}
if ($ensureUnique) {
$sku = self::ensureUnique($sku, $maxLen);
}
return $sku;
}
/** 构造规格位(SPEC),按能源类型差异化 */
private static function buildSpec(array $s, string $fuel): string
{
$fuel = strtoupper($fuel);
if ($fuel === 'EV') {
if (!empty($s['range_km'])) {
$r = (int)$s['range_km'];
$r10 = (int)round($r / 10) * 10; // 到 10 位
return (string)$r10;
}
if (!empty($s['battery_kwh'])) {
return self::numToken($s['battery_kwh']) . 'KWH';
}
return '';
}
if ($fuel === 'GAS') {
$bits = [];
if (!empty($s['engine_disp_l'])) {
$bits[] = self::dispToken($s['engine_disp_l']); // 1.5L -> 15L
}
if (!empty($s['engine_turbo']) && intval($s['engine_turbo']) === 1) {
$bits[] = 'T';
}
if (!empty($s['transmission_code'])) {
$bits[] = self::abbr(self::tok($s['transmission_code']));
}
return implode('', $bits); // 如 15LTCVT
}
// HEV/PHEV/EREV 等
$bits = [];
if (!empty($s['engine_disp_l'])) {
$bits[] = self::dispToken($s['engine_disp_l']); // 可空
}
if (!empty($s['motor_layout_code'])) {
$bits[] = self::tok($s['motor_layout_code']); // 如 AWD / DM-I / DM-P
}
return implode('', $bits);
}
/** 冲突检测并追加短校验(全局唯一) */
private static function ensureUnique(string $sku, int $maxLen): string
{
if (!VehVehicleSku::where('sku_code', $sku)->exists()) {
return $sku;
}
// 用 crc32 生成 5~6 位 base36 校验(稳定且短)
$crc = self::base36Crc($sku);
$suffix = '-X' . $crc;
if (strlen($sku . $suffix) > $maxLen) {
$sku = substr($sku, 0, max(0, $maxLen - strlen($suffix)));
$sku = rtrim($sku, '-'); // 避免尾部 '-'
}
$sku .= $suffix;
// 若极端情况下仍冲突,追加递增计数
$i = 2;
$candidate = $sku;
while (VehVehicleSku::where('sku_code', $candidate)->exists()) {
$extra = '-'.$i;
$cut = max(0, $maxLen - strlen($extra));
$candidate = substr($sku, 0, $cut) . $extra;
$i++;
}
return $candidate;
}
/** 把 token 数组尽量压到 maxLen(逐步压缩策略) */
private static function shrink(array $partsByKey, int $maxLen): string
{
// 1) 先对 series/level/edition 做激进压缩
$p = $partsByKey;
foreach (['series','level','edition'] as $k) {
if (!empty($p[$k])) $p[$k] = self::heavyAbbr($p[$k]);
}
$sku = self::normalizeSku(implode('-', $p));
if (strlen($sku) <= $maxLen) return $sku;
// 2) 依次移除不太关键的信息:edition → level(若存在)
if (!empty($p['edition'])) { unset($p['edition']); }
$sku = self::normalizeSku(implode('-', $p));
if (strlen($sku) <= $maxLen) return $sku;
if (!empty($p['level'])) { unset($p['level']); }
$sku = self::normalizeSku(implode('-', $p));
if (strlen($sku) <= $maxLen) return $sku;
// 3) 压缩 spec(如去 KM/KWH,仅保留核心)
if (!empty($p['spec'])) { $p['spec'] = self::compactSpec($p['spec']); }
$sku = self::normalizeSku(implode('-', $p));
if (strlen($sku) <= $maxLen) return $sku;
// 4) 仍超长:从右向左截断次要段(spec/drive/year),保留前三段(brand/series/fuel)优先
$dropOrder = ['spec','drive','year'];
$q = $p;
foreach ($dropOrder as $k) {
if (!empty($q[$k])) { unset($q[$k]); }
$sku = self::normalizeSku(implode('-', $q));
if (strlen($sku) <= $maxLen) return $sku;
}
// 5) 最后兜底:硬截到 maxLen,后续 ensureUnique 会追加 -X 校验并避免冲突
return substr(self::normalizeSku(implode('-', $p)), 0, $maxLen);
}
/* ===== Helpers ===== */
private static function tok($v): string
{
$v = strtoupper((string)$v);
return preg_replace('/[^A-Z0-9_]/', '', $v ?? '');
}
private static function abbr(string $t): string
{
return self::ABBR[$t] ?? $t;
}
private static function heavyAbbr(string $t): string
{
// 更激进:去除元音,连字符化
$t = str_replace(['STANDARD','FLAGSHIP','PREMIUM','DELUXE'], ['STD','FLG','PRM','DLX'], $t);
$t = preg_replace('/[AEIOU]/', '', $t);
return $t;
}
private static function compactSpec(string $s): string
{
// 规则:去 KM/KWH 等单位,只保留数字与核心字母
$s = strtoupper($s);
$s = str_replace(['KM','KWH'], '', $s);
return $s;
}
private static function numToken($v): string
{
return preg_replace('/[^0-9]/', '', (string)$v);
}
/** 1.5L -> 15L;2.0L -> 20L */
private static function dispToken($l): string
{
$x = (float)$l;
return (string)round($x * 10) . 'L';
}
private static function base36Crc(string $s): string
{
$crc = sprintf('%u', crc32($s)); // 无符号
$n = (int)$crc;
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$res = '';
do {
$res = $chars[$n % 36] . $res;
$n = intdiv($n, 36);
} while ($n > 0);
return substr($res, -6); // 取后6位足够
}
private static function normalizeSku(string $s): string
{
// 连续的 '-' 合并,首尾修剪
$s = preg_replace('/-+/', '-', $s);
$s = trim($s, '-');
return $s;
}
}
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\StockOrderAccounts;
class StockOrderAccountsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = StockOrderAccounts::class;
}
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\StockOrderItemOptions;
class StockOrderItemOptionsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = StockOrderItemOptions::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\StockOrderItems;
class StockOrderItemsLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = StockOrderItems::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\StockOrders;
class StockOrdersLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = StockOrders::class;
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysAccount;
class SysAccountLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysAccount::class;
public function getList()
{
return SysAccount::where('status', 1)->orderBy('sort','desc')->get(['id', 'account_name', 'currency_id', 'account_number', 'bank_name', 'bank_branch', 'description']);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace app\common\logic;
use app\common\model\SysCurrency;
use app\common\traits\crud\CrudLogicTrait;
class SysCurrencyLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysCurrency::class;
public function getList()
{
return SysCurrency::where('status', 1)->get(['id', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'float_percent_up', 'float_percent_down']);
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDictItem;
class SysDictItemLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDictItem::class;
public function getList($where)
{
return SysDictItem::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'item_label', 'item_value', 'remark', 'dict_id']);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysDict;
class SysDictLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysDict::class;
public function getDictByCode($code)
{
return SysDict::where('status', 1)->where('code', $code)->orderBy('sort','desc')->first(['id']);
}
public function getList()
{
return SysDict::where('status', 1)->get(['id', 'dict_name', 'dict_code', 'description']);
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysPort;
class SysPortLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysPort::class;
public function getList($where)
{
return SysPort::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'port_code', 'port_name', 'country_id', 'description']);
}
}
+169
View File
@@ -0,0 +1,169 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\UploadedFiles;
class UploadedFilesLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = UploadedFiles::class;
/**
* 根据分区获取文件列表
*
* @param string $partition
* @param int $limit
* @param int $page
* @return mixed
*/
public function getFilesByPartition(string $partition, int $limit = 15, int $page = 1)
{
$config = [
'model' => $this->modelClass,
'where' => ['partition' => $partition],
'order' => ['created_at' => 'desc', 'id' => 'desc']
];
return $this->logicList($config, $limit, $page);
}
/**
* 根据分类获取文件列表
*
* @param string $category
* @param int $limit
* @param int $page
* @return mixed
*/
public function getFilesByCategory(string $category, int $limit = 15, int $page = 1)
{
$config = [
'model' => $this->modelClass,
'where' => ['category' => $category],
'order' => ['created_at' => 'desc', 'id' => 'desc']
];
return $this->logicList($config, $limit, $page);
}
/**
* 根据文件类型获取文件列表
*
* @param string $fileType
* @param int $limit
* @param int $page
* @return mixed
*/
public function getFilesByType(string $fileType, int $limit = 15, int $page = 1)
{
$config = [
'model' => $this->modelClass,
'where' => ['file_type' => $fileType],
'order' => ['created_at' => 'desc', 'id' => 'desc']
];
return $this->logicList($config, $limit, $page);
}
/**
* 搜索文件
*
* @param string $keyword
* @param int $limit
* @param int $page
* @return mixed
*/
public function searchFiles(string $keyword, int $limit = 15, int $page = 1)
{
$config = [
'model' => $this->modelClass,
'where' => [
'or' => [
['file_name', 'like', '%' . $keyword . '%'],
['original_name', 'like', '%' . $keyword . '%'],
['category', 'like', '%' . $keyword . '%']
]
],
'order' => ['created_at' => 'desc', 'id' => 'desc']
];
return $this->logicList($config, $limit, $page);
}
/**
* 获取文件统计信息
*
* @return array
*/
public function getFileStatistics(): array
{
$model = new $this->modelClass();
$totalFiles = $model->count();
$totalSize = $model->sum('file_size');
$partitionStats = $model->selectRaw('partition, COUNT(*) as count, SUM(file_size) as size')
->groupBy('partition')
->get()
->toArray();
$categoryStats = $model->selectRaw('category, COUNT(*) as count, SUM(file_size) as size')
->groupBy('category')
->get()
->toArray();
$typeStats = $model->selectRaw('file_type, COUNT(*) as count, SUM(file_size) as size')
->groupBy('file_type')
->get()
->toArray();
return [
'total_files' => $totalFiles,
'total_size' => $totalSize,
'partition_stats' => $partitionStats,
'category_stats' => $categoryStats,
'type_stats' => $typeStats
];
}
/**
* 清理过期文件
*
* @param int $days 保留天数
* @return int 清理的文件数量
*/
public function cleanExpiredFiles(int $days = 30): int
{
$expiredTime = time() - ($days * 24 * 60 * 60);
$config = [
'model' => $this->modelClass,
'where' => [
['created_at', '<', $expiredTime]
]
];
$files = $this->logicListAll($config);
$count = 0;
foreach ($files as $file) {
// 删除物理文件
$fullPath = public_path() . $file->file_path;
if (file_exists($fullPath)) {
unlink($fullPath);
}
// 删除数据库记录
$this->logicDeleteBy(['where' => ['id' => $file->id]]);
$count++;
}
return $count;
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehColor;
class VehColorLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehColor::class;
public function getList($where)
{
return VehColor::where('status', 1)->where($where)->orderBy('sort','desc')->get(['id', 'color_code', 'color_text']);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehDictI18n;
class VehDictI18nLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehDictI18n::class;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehDictMapping;
class VehDictMappingLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehDictMapping::class;
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehModification;
class VehModificationLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehModification::class;
public function getList()
{
return VehModification::where('status', 1)->orderBy('sort','desc')->get(['id', 'code', 'name', 'type', 'price']);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehMoneyValue;
class VehMoneyValueLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehMoneyValue::class;
}
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehVehicleListing;
class VehVehicleListingLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehVehicleListing::class;
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehVehicleSku;
class VehVehicleSkuLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehVehicleSku::class;
/**
* 指纹 = “稳定可复现的事实串”做 sha256
* - 仅纳入稳定维度:品牌/车系/年款/能源/驱动/变速/车身 + 关键数值
* - 不纳入营销名(trim/edition)、颜色文本等
* - corp 维度:若你未来希望租户内去重,可传 $scopeCorp=true
*/
public static function fingerprintMake(array $sku, bool $scopeCorp = false): string
{
$norm = function ($v) {
if ($v === null || $v === '') return '';
if (is_float($v)) return rtrim(rtrim(number_format($v, 3, '.', ''), '0'), '.'); // 规范小数
return (string)$v;
};
$parts = [
$scopeCorp ? ($sku['corp_id'] ?? 0) : '',
strtoupper($sku['brand_code'] ?? ''),
strtoupper($sku['series_code'] ?? ''),
(int)($sku['model_year'] ?? 0),
strtoupper($sku['fuel_type_code'] ?? ''),
strtoupper($sku['drive_type_code']?? ''),
strtoupper($sku['transmission_code'] ?? ''),
strtoupper($sku['body_type_code'] ?? ''),
$norm($sku['engine_disp_l'] ?? null),
(int)($sku['engine_turbo'] ?? 0),
$norm($sku['battery_kwh'] ?? null),
(int)($sku['range_km'] ?? 0),
strtoupper($sku['range_std_code'] ?? ''),
strtoupper($sku['emission_std_code'] ?? ''),
];
$plain = implode('|', $parts);
return hash('sha256', $plain);
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\common\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\VehVehicleUnit;
class VehVehicleUnitLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = VehVehicleUnit::class;
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class Brand extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'brand';
/**
* 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', 'brand_code', 'brand_name', 'logo', 'country', 'description', 'status', 'sort', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class BrandSeries extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'brand_series';
/**
* 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', 'brand_id', 'series_code', 'series_name', 'description', 'status', 'sort', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+58
View File
@@ -0,0 +1,58 @@
<?php
namespace app\common\model;
use support\Model;
class StockOrderAccounts extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_order_accounts';
/**
* 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_id', 'seq_no', 'remit_country_id', 'remit_country_name_snapshot', 'remit_date', 'currency_code', 'currency_name_snapshot', 'account_id', 'account_name_snapshot', 'remitter_name', 'amount', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
/**
* 关联主订单
*/
public function order()
{
return $this->belongsTo(StockOrders::class, 'order_id', 'id');
}
}
@@ -0,0 +1,58 @@
<?php
namespace app\common\model;
use support\Model;
class StockOrderItemOptions extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_order_item_options';
/**
* 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_item_id', 'option_id', 'option_name_snapshot', 'option_price', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
/**
* 关联订单项
*/
public function item()
{
return $this->belongsTo(StockOrderItems::class, 'order_item_id', 'id');
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace app\common\model;
use support\Model;
use app\common\traits\HasMoneyJournal;
class StockOrderItems extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_order_items';
/**
* 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_id', 'product_code', 'sku_id', 'sku_snapshot',
'model_snapshot', 'quantity', 'color_interior_code', 'color_interior_snapshot',
'color_exterior_code', 'color_exterior_snapshot', 'remark', 'vin', 'created_at', 'updated_at',
'mileage', 'unique_id'
];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
/* ========= 关系 ========= */
use HasMoneyJournal;
// 实现抽象方法
protected static function moneyObjectScene(): string
{
return 'stock_order_items';
}
// 便捷访问器(最新一条的原币金额)
public function getUnitPriceAmountAttribute() { return $this->moneyLatest('unit_price')?->amount; }
public function getHandlingFeeAmountAttribute() { return $this->moneyLatest('handling_fee')?->amount; }
public function getFobTransportFeeAmountAttribute() { return $this->moneyLatest('fob_transport_fee')?->amount; }
public function getPortMiscFeeAmountAttribute() { return $this->moneyLatest('port_misc_fee')?->amount; }
public function getRetrofitFeeAmountAttribute() { return $this->moneyLatest('retrofit_fee')?->amount; }
public function getTotalPriceAmountAttribute() { return $this->moneyLatest('total_price')?->amount; }
/**
* 关联主订单
*/
public function order()
{
return $this->belongsTo(StockOrders::class, 'order_id', 'id');
}
/**
* 关联订单项选项
*/
public function options()
{
return $this->hasMany(StockOrderItemOptions::class, 'order_item_id', 'id');
}
/**
* 关联货币价值信息(一个订单项可以有多个货币价值记录)
*/
public function moneyValues()
{
return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')
->where('object_scene', 'stock_order_items'); // 场景标识区分不同对象类型
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php
namespace app\common\model;
use support\Model;
use app\common\traits\HasMoneyJournal;
class StockOrders extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'stock_orders';
/**
* 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', 'pi_no', 'biz_date', 'salesperson_id', 'salesperson_snapshot',
'clearance_country_id', 'clearance_country_snapshot', 'ali_order_no',
'customer_source_id', 'customer_source_snapshot', 'customer_id', 'customer_snapshot',
'customer_country_id', 'customer_country_snapshot', 'declarant_name', 'eta_ship_date',
'shipping_method_id', 'shipping_method_snapshot', 'cif_total_amount', 'domestic_port_id', 'domestic_port_snapshot',
'trade_term_id', 'trade_term_snapshot', 'clearance_port_id', 'clearance_port_snapshot',
'latest_arrival_date', 'contract_exchange_rate', 'settlement_currency', 'status',
'remark', 'created_at', 'updated_at', 'deleted_at',
'object_id', 'contract', 'is_use', 'is_final', 'approval_status', 'file_url', 'pick_up_date', 'collect_all_date', 'profit_total'
];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
use HasMoneyJournal;
// 实现抽象方法
protected static function moneyObjectScene(): string
{
return 'stock_orders';
}
/**
* 关联订单项
*/
public function items()
{
return $this->hasMany(StockOrderItems::class, 'order_id', 'id');
}
/**
* 关联订单账户信息
*/
public function accounts()
{
return $this->hasMany(StockOrderAccounts::class, 'order_id', 'id');
}
/**
* 关联货币价值信息(一个订单可以有多个货币价值记录)
*/
public function moneyValues()
{
return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders');
}
public function salesperson()
{
return $this->hasOne(User::class, 'id', 'salesperson_id');
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class SysAccount extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sys_account';
/**
* 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', 'corp_id', 'currency_id', 'account_name', 'account_number', 'account_holder', 'bank_name', 'bank_branch', 'daily_limit', 'single_limit', 'description', 'status', 'sort', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class SysCurrency extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sys_currency';
/**
* 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', 'country_id', 'currency_code', 'currency_name', 'currency_symbol', 'exchange_rate', 'base_currency', 'float_percent_up', 'float_percent_down', 'status', 'last_updated', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class SysCurrencyTranslation extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sys_currency_translation';
/**
* 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', 'currency_id', 'locale', 'currency_name', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace app\common\model;
use Illuminate\Database\Eloquent\SoftDeletes;
use support\Model;
class SysDict extends Model
{
use SoftDeletes;
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'sys_dict';
/**
* 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', 'category_id', 'dict_name', 'dict_code', 'description', 'status', 'created_at', 'updated_at', 'deleted_at'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
// 定义与 SysDictItem 的一对多关系
public function sysDictItem()
{
return $this->hasMany(SysDictItem::class, 'dict_id', 'id');
}
public function category()
{
return $this->belongsTo(SysDictCategory::class, 'category_id', 'id');
}
/**
* 一个字典有多个字典项
*/
public function items()
{
return $this->hasMany(SysDictItem::class, 'dict_id', 'id');
}
/**
* 通过 dict_code 快速获取所有 item_value
*/
public function scopeGetItemValuesByCode($query, $dictCode)
{
return $query->where('dict_code', $dictCode)
->with('items') // 预加载关联项
->first()?->items->pluck('item_value'); // 返回 item_value 数组
}
/**
* 通过 dict_code 获取完整字典项(含 label + value)
*/
public function scopeGetItemsByCode($query, $dictCode)
{
return $query->where('dict_code', $dictCode)
->with('items')
->first()?->items;
}
}

Some files were not shown because too many files have changed in this diff Show More