mall_id); $alipay = !empty($data['alipay']) ? $data['alipay'] : []; $data = array_merge($data, $alipay); $data['use_scene'] = empty($data['use_scene']) ? '' : implode(',', $data['use_scene']); $data['ali_config'] = Json::encode($alipay); $data['tax_config'] = Json::encode($data['tax']); $data['ly_config'] = Json::encode($data['ly']); $data['mall_id'] = $this->mall_id; Yii::$app->services->setting->addons->set( $this->mall_id,'AvoidTax', ['basic' => $data['basic']] ); if ($model->load($data, '') && $model->save()) { $this->setCacheConfig( $this->getDbConfig() ); return true; } else { return $this->error(array_values($model->getFirstErrors())[0]); } } /** * 获取配置 * * @return array */ public function getConfig() { $basic = Yii::$app->services->setting->addons->get($this->mall_id,'AvoidTax', 'basic'); if(isset($basic['withdrawal_no_check'])){ $basic['withdrawal_no_check'] = intval($basic['withdrawal_no_check']); }else{ $basic['withdrawal_no_check'] = 0; } if ($cache = $this->getCacheConfig()) { $cache['basic'] = $basic; return $cache; } $cache = $this->getDbConfig(); $this->setCacheConfig($cache); $cache['basic'] = $basic; return $cache; } /** * 获取配置的配置类型 * * @return int */ public function getType() { return $this->getConfig()['type']; } /** * 个人版 * * @return boolean */ public function isPersonalType() { return $this->getType() == TaxConfig::PERSONAL; } /** * 服务商版本 * * @return boolean */ public function isServiceType() { return $this->getType() == TaxConfig::SERVICE; } /** * 获取配置的AlipayUserId * * @return string */ public function getAlipayUserId() { return $this->getConfig()['ali_config']['alipay_user_id']; } /** * 获取缓存里面的配置 * * @return array|null */ public function getCacheConfig() { return Json::decode(Yii::$app->redis->get( $this->getCacheField() )); } /** * 设置缓存配置 * * @param array $config * @return void */ public function setCacheConfig(array $config, int $seconds = 10) { Yii::$app->redis->setex( $this->getCacheField(), $seconds, Json::encode($config) ); } /** * 获取数据库里的配置 * * @return array * @throws Exception */ public function getDbConfig() { $config = TaxConfig::getConfig($this->mall_id); if (empty($config)) throw new Exception('未设置配置信息'); $config['type'] = (int) $config['type']; $config['api_type'] = (int) $config['api_type']; $config['settle'] = (int) $config['settle']; $config['payment_flow_status'] = (int) ($config['payment_flow_status'] ?? 0); $config['ali_config'] = Json::decode($config['ali_config']); $config['tax_config'] = Json::decode($config['tax_config']); $config['ly_config'] = Json::decode($config['ly_config']); return $config; } /** * 获取支付宝配置 * * @return array * @throws Exception */ public function getAlipayConfig() { $type = $this->getType(); // 个人 if ($type == TaxConfig::PERSONAL) { return $this->getConfig()['ali_config']; } // 服务商 if ($type == TaxConfig::SERVICE) { return (new TaxConfig())->getServiceConfig(); } throw new Exception('配置有误'); } /** * API类型 * * @return integer */ public function getApiType() { return $this->getConfig()['api_type']; } /** * 获取lyconfig * * @return array */ public function getLYConfig() { return $this->getConfig()['ly_config']; } /** * 获取xinlong * * @return array */ public function getXLConfig() { return $this->getConfig()['tax_config']; } /** * 缓存字段 * * @return string */ protected function getCacheField() { return 'tax_config_mall_' . $this->mall_id; } /** * 获取费用 * * @return float */ public function getTaxFee() { return $this->getTaxConfig()['taxFee']; } /** * xlapi * * @return boolean */ public function isXLApiType() { return $this->getApiType() === TaxConfig::XIONLONG; } /** * lyapi * * @return boolean */ public function isLYApiType() { return $this->getApiType() === TaxConfig::LUYONG; } /** * accountId * * @return string */ public function getAccountId() { return $this->getLYConfig()['accountId']; } /** * xl uid * * @return string */ public function getUid() { return $this->getXLConfig()['uid']; } /** * @return int */ public function getPaymentFlowStatus() { return $this->getConfig()['payment_flow_status'] ?? 0; } /** * 获取手续费打款账户 * * @return array */ public function getTaxConfig() { // xinlong if ($this->getApiType() == TaxConfig::XIONLONG) { $config = $this->getXLConfig(); } // luyong if ($this->getApiType() == TaxConfig::LUYONG) { $config = $this->getLYConfig(); } return $config; } }