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' => true, ]; $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' => false, ]; //@TODO 其他支付 return $list; } }