企油通 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 requireIdCard(): bool { return $this->getData('passageway') === 'pingan'; } /** 状态中文(访问器,后台列表直接可用) */ 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'] ?? ''] ?? ''; } }