104 lines
3.1 KiB
PHP
104 lines
3.1 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 企油通企业模型
|
||
// +----------------------------------------------------------------------
|
||
// | 一个接入方 appId 下可挂多个企业(见《企油通接口对接文档.md》7.22)。
|
||
// | 企业级参数:business_license / passageway / institution_id 等存本表;
|
||
// | 接入方级参数:appId、RSA 私钥、接口域名仍在 .env,私钥不入库。
|
||
// +----------------------------------------------------------------------
|
||
declare (strict_types=1);
|
||
|
||
namespace app\common\model\qyt;
|
||
|
||
use cores\BaseModel;
|
||
|
||
class Enterprise extends BaseModel
|
||
{
|
||
protected $name = 'qyt_enterprise';
|
||
|
||
protected $pk = 'enterprise_id';
|
||
|
||
/** 通道:配置键 => 企油通 passageway 编码 */
|
||
const PASSAGEWAY_CODE = [
|
||
'alipay' => 1,
|
||
'pingan' => 2,
|
||
];
|
||
|
||
/** 通道名称 */
|
||
const PASSAGEWAY_NAME = [
|
||
'alipay' => '支付宝企业码',
|
||
'pingan' => '平安银行',
|
||
];
|
||
|
||
/** 企业状态(文档 2.6) */
|
||
const STATUS_TEXT = [
|
||
'pending' => '待完善',
|
||
'submitted' => '待审核',
|
||
'approved' => '审核通过',
|
||
'rejected' => '审核拒绝',
|
||
'frozen' => '已冻结',
|
||
];
|
||
|
||
/**
|
||
* 企业详情
|
||
* @param int|array $where
|
||
* @return static|null
|
||
*/
|
||
public static function detail($where)
|
||
{
|
||
!is_array($where) && $where = ['enterprise_id' => (int) $where];
|
||
return static::get($where);
|
||
}
|
||
|
||
/**
|
||
* 取默认企业(合作商未绑定时的兜底)
|
||
* @return static|null
|
||
*/
|
||
public static function getDefault()
|
||
{
|
||
return static::where('is_enable', 1)->where('is_default', 1)
|
||
->order('enterprise_id', 'asc')->find();
|
||
}
|
||
|
||
/**
|
||
* 解析某个合作商本次下单应使用的企业
|
||
* 优先级:合作商绑定的企业 -> 默认企业;都取不到返回 null,由调用方拒单
|
||
* @param int $enterpriseId 合作商绑定的企业ID,0 表示未绑定
|
||
* @return static|null
|
||
*/
|
||
public static function resolve(int $enterpriseId = 0)
|
||
{
|
||
if ($enterpriseId > 0) {
|
||
$one = static::where('enterprise_id', $enterpriseId)->where('is_enable', 1)->find();
|
||
if ($one) {
|
||
return $one;
|
||
}
|
||
}
|
||
return static::getDefault();
|
||
}
|
||
|
||
/** 当前通道的企油通 passageway 编码 */
|
||
public function passagewayCode(): int
|
||
{
|
||
return self::PASSAGEWAY_CODE[$this->getData('passageway')] ?? self::PASSAGEWAY_CODE['alipay'];
|
||
}
|
||
|
||
/** 当前通道中文名 */
|
||
public function passagewayName(): string
|
||
{
|
||
return self::PASSAGEWAY_NAME[$this->getData('passageway')] ?? '';
|
||
}
|
||
|
||
/** 状态中文(访问器,后台列表直接可用) */
|
||
public function getStatusTextAttr($value, $data): string
|
||
{
|
||
return self::STATUS_TEXT[$data['status'] ?? ''] ?? ($data['status'] ?? '');
|
||
}
|
||
|
||
/** 通道中文(访问器) */
|
||
public function getPassagewayTextAttr($value, $data): string
|
||
{
|
||
return self::PASSAGEWAY_NAME[$data['passageway'] ?? ''] ?? '';
|
||
}
|
||
}
|