第二次更新
This commit is contained in:
@@ -63,12 +63,37 @@ class Setting extends SettingModel
|
||||
$callback = [
|
||||
'store' => function ($values) {
|
||||
return $this->validStore($values);
|
||||
}
|
||||
},
|
||||
SettingEnum::QYT => function ($values) {
|
||||
return $this->validQyt($values);
|
||||
},
|
||||
];
|
||||
// 验证商城设置
|
||||
return isset($callback[$key]) ? $callback[$key]($values) : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证企油通对接设置
|
||||
* 只做「填错了会让发放整体失败」的强校验,留空一律回落 .env,不强制必填
|
||||
* @param array $values
|
||||
* @return bool
|
||||
*/
|
||||
private function validQyt(array $values)
|
||||
{
|
||||
foreach (['base_url' => '接口域名', 'h5_base_url' => 'H5落地页地址'] as $key => $name) {
|
||||
$url = trim((string) ($values[$key] ?? ''));
|
||||
if ($url !== '' && !preg_match('#^https?://#i', $url)) {
|
||||
$this->error = "{$name}必须以 http:// 或 https:// 开头";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (rtrim(trim((string) ($values['base_url'] ?? '')), '/') !== trim((string) ($values['base_url'] ?? ''))) {
|
||||
$this->error = '接口域名结尾不要带斜杠';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证商城设置
|
||||
* @param array $values
|
||||
|
||||
@@ -13,6 +13,7 @@ declare (strict_types=1);
|
||||
namespace app\store\model\partners;
|
||||
|
||||
use app\common\model\partners\Order as OrderModel;
|
||||
use app\common\service\QytOil;
|
||||
|
||||
/**
|
||||
* 合作商订单
|
||||
@@ -21,6 +22,18 @@ use app\common\model\partners\Order as OrderModel;
|
||||
*/
|
||||
class Order extends OrderModel
|
||||
{
|
||||
/**
|
||||
* 身份证号脱敏(仅后台展示层)
|
||||
* 注意:本访问器只挂在 store 模型上;发放流程用的是 app\common\model\partners\Order,
|
||||
* 取到的仍是明文,不会把打码后的身份证号发给企油通。
|
||||
* @param string|null $value
|
||||
* @return string
|
||||
*/
|
||||
public function getIdCardAttr($value): string
|
||||
{
|
||||
return QytOil::maskIdCard((string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取余额变动明细列表
|
||||
* @param array $param
|
||||
@@ -64,7 +77,7 @@ class Order extends OrderModel
|
||||
'driver_name' => '', // 司机姓名
|
||||
'orderNo' => '', // 单号:油卡编号/下单平台单号/批次号/运单号
|
||||
'oil_status' => -1, // 分油(发放)状态
|
||||
'oil_status_zsy' => -1, // 企油通发放态 0未提交 2成功 3失败
|
||||
'oil_status_zsy' => -1, // 企油通发放态 0未提交 1发放中 2成功 3失败
|
||||
'use_status' => -1, // 加油核销状态
|
||||
'betweenTime' => [] // 起止时间
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 后台 · 企油通企业模型
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model\qyt;
|
||||
|
||||
use app\common\model\qyt\Enterprise as EnterpriseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
class Enterprise extends EnterpriseModel
|
||||
{
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
$filter = [];
|
||||
if (!empty($param['name'])) {
|
||||
$filter[] = ['company_name|business_license', 'like', '%' . trim($param['name']) . '%'];
|
||||
}
|
||||
if (isset($param['status']) && $param['status'] !== '' && $param['status'] !== 'all') {
|
||||
$filter[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (isset($param['passageway']) && $param['passageway'] !== '' && $param['passageway'] !== 'all') {
|
||||
$filter[] = ['passageway', '=', $param['passageway']];
|
||||
}
|
||||
return $this->where($filter)
|
||||
->order(['is_default' => 'desc', 'sort' => 'asc', 'enterprise_id' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部启用中的企业(下拉选择用)
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return (new static)->where('is_enable', 1)
|
||||
->order(['is_default' => 'desc', 'sort' => 'asc'])
|
||||
->field(['enterprise_id', 'company_name', 'business_license', 'passageway', 'status', 'is_default'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function add(array $data): bool
|
||||
{
|
||||
if (!$this->validForm($data)) {
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
$data['create_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
return $this->transaction(function () use ($data) {
|
||||
$ok = $this->save($data) !== false;
|
||||
// 设为默认时,把其他企业的默认标记清掉
|
||||
$ok && !empty($data['is_default']) && $this->clearOtherDefault((int) $this->enterprise_id);
|
||||
return $ok;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
if (!$this->validForm($data, (int) $this['enterprise_id'])) {
|
||||
return false;
|
||||
}
|
||||
$data['update_time'] = time();
|
||||
return $this->transaction(function () use ($data) {
|
||||
$ok = $this->save($data) !== false;
|
||||
$ok && !empty($data['is_default']) && $this->clearOtherDefault((int) $this['enterprise_id']);
|
||||
return $ok;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除:已产生订单的企业不允许删除,改用停用
|
||||
*/
|
||||
public function remove(): bool
|
||||
{
|
||||
$used = Db::name('partners_order')->where('qyt_enterprise_id', $this['enterprise_id'])->count();
|
||||
if ($used > 0) {
|
||||
$this->error = "该企业已产生 {$used} 笔订单,不能删除;如需停用请把「启用」关掉";
|
||||
return false;
|
||||
}
|
||||
$bound = Db::name('partners')->where('qyt_enterprise_id', $this['enterprise_id'])->count();
|
||||
if ($bound > 0) {
|
||||
$this->error = "还有 {$bound} 个合作商绑定了该企业,请先改绑";
|
||||
return false;
|
||||
}
|
||||
if ($this['is_default']) {
|
||||
$this->error = '默认企业不能删除,请先把默认设到其他企业';
|
||||
return false;
|
||||
}
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为默认
|
||||
*/
|
||||
public function setDefault(): bool
|
||||
{
|
||||
if (!$this['is_enable']) {
|
||||
$this->error = '已停用的企业不能设为默认';
|
||||
return false;
|
||||
}
|
||||
return $this->transaction(function () {
|
||||
$this->save(['is_default' => 1, 'update_time' => time()]);
|
||||
$this->clearOtherDefault((int) $this['enterprise_id']);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/** 清掉其他企业的默认标记 */
|
||||
protected function clearOtherDefault(int $keepId): void
|
||||
{
|
||||
Db::name('qyt_enterprise')
|
||||
->where('enterprise_id', '<>', $keepId)
|
||||
->where('is_default', 1)
|
||||
->update(['is_default' => 0, 'update_time' => time()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单校验
|
||||
*/
|
||||
protected function validForm(array $data, int $selfId = 0): bool
|
||||
{
|
||||
if (empty($data['company_name'])) {
|
||||
$this->error = '请填写企业名称';
|
||||
return false;
|
||||
}
|
||||
$license = trim((string) ($data['business_license'] ?? ''));
|
||||
if ($license === '') {
|
||||
$this->error = '请填写统一社会信用代码';
|
||||
return false;
|
||||
}
|
||||
if (!preg_match('/^[0-9A-Z]{18}$/', $license)) {
|
||||
$this->error = '统一社会信用代码应为 18 位大写字母或数字,请检查是否混入了空格或括号';
|
||||
return false;
|
||||
}
|
||||
$exist = Db::name('qyt_enterprise')->where('business_license', $license);
|
||||
$selfId > 0 && $exist->where('enterprise_id', '<>', $selfId);
|
||||
if ($exist->count() > 0) {
|
||||
$this->error = '该统一社会信用代码已存在';
|
||||
return false;
|
||||
}
|
||||
if (!isset(self::PASSAGEWAY_CODE[$data['passageway'] ?? ''])) {
|
||||
$this->error = '支付通道取值不合法';
|
||||
return false;
|
||||
}
|
||||
// 支付宝企业码通道必须有机构号,否则每一单都会在下发时失败并退款
|
||||
if (($data['passageway'] ?? '') === 'alipay' && trim((string) ($data['institution_id'] ?? '')) === '') {
|
||||
$this->error = '支付宝企业码通道必须填写机构号(institution_id)';
|
||||
return false;
|
||||
}
|
||||
if (!empty($data['contact_mobile']) && !preg_match('/^1[3-9]\d{9}$/', (string) $data['contact_mobile'])) {
|
||||
$this->error = '企业联系人电话格式不正确';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user