cxgj/models/PaymentTypes.php
2023-11-27 09:45:13 +08:00

165 lines
4.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%payment_types}}".
*
* @property int $id ID
* @property int $cx_mch_id 平台商户ID
* @property string $name 支付方式CN
* @property string $short_name 支付方式EN
* @property int $is_show 是否显示0=否1=是
* @property int $is_open 是否启用0=否1=是
* @property int $created_at 添加时间
* @property int $updated_at 更新时间
*/
class PaymentTypes extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%payment_types}}';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['cx_mch_id', 'is_show', 'is_open', 'created_at', 'updated_at'], 'integer'],
[['name', 'short_name'], 'required'],
[['name', 'short_name'], 'string', 'max' => 50],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'cx_mch_id' => '平台商户ID',
'name' => '支付方式CN',
'short_name' => '支付方式EN',
'is_show' => '是否显示0=否1=是',
'is_open' => '是否启用0=否1=是',
'created_at' => '添加时间',
'updated_at' => '更新时间',
];
}
public function beforeSave($insert) {
if(parent::beforeSave($insert)){
if($this->isNewRecord){
$this->created_at = time();
}
$this->updated_at = time();
return true;
} else {
return false;
}
}
public static function getPayType($type)
{
$labels = self::payTypeLabels();
return isset($labels[$type]) ? $labels[$type] : "未知";
}
public static function payTypeLabels()
{
$pay_types = self::payTypes();
$list = [];
foreach ($pay_types as $key => $val){
$list[$val['id']] = $val['name'];
}
return $list;
}
/**
* @param integer $id 支付类型ID
* return string|null
*/
public static function payTypeIdToKey($id)
{
$pay_types = self::payTypes();
foreach ($pay_types as $key => $val){
if($val['id'] == $id){
return $val['short_name'];
}
}
return null;
}
/**
* @param string $key 支付类型简称
* return integer|null
*/
public static function payTypeKeyToId($key)
{
$pay_types = self::payTypes();
return isset($pay_types[$key]) ? $pay_types[$key]['id'] : null;
}
public static function payTypes()
{
//系统常量类app\\components\\SysConst有定义
$list = [];
$list['balance'] = [
'id' => 0,
'short_name' => 'balance',
'name' => '余额支付',
'disabled' => false,
];
$list['wxpay'] = [
'id' => 1,
'short_name' => 'wxpay',
'name' => '微信支付',
'disabled' => false,
];
$list['alipay'] = [
'id' => 2,
'short_name' => 'alipay',
'name' => '支付宝',
'disabled' => true,
];
$list['bank'] = [
'id' => 3,
'short_name' => 'bank',
'name' => '银行卡支付',
'disabled' => true,
];
$list['integral'] = [
'id' => 4,
'short_name' => 'integral',
'name' => '积分支付',
'disabled' => true,
];
$list['unionpay'] = [
'id' => 5,
'short_name' => 'unionpay',
'name' => '银联支付',
'disabled' => true,
];
$list['wxpay_points'] = [
'id' => 6,
'short_name' => 'unionpay',
'name' => '微信支付分',
'disabled' => true,
];
//@TODO 其他支付
return $list;
}
}