getSetting(); Yii::$app->services->setting->addons->set( $this->mall_id, OperationCenterEnum::ADDONS_NAME_OPERATION_CENTER, [static::BASIC => $setting] ); // 添加日志 SettingLog::addSettingLog($this->mall_id, $before_setting, $setting); $this->setCacheSetting($setting); } catch (\Exception $e) { return $this->error($e->getMessage()); } return true; } /** * 获取配置信息 * * @param string $key * @return array */ public function getSetting() { if (empty($this->setting)) { $this->setting = $this->getCacheSetting(); $this->jsonFormat(); } return $this->setting; } /** * @return array */ public function getDbSetting() { return Yii::$app->services->setting->addons->get( $this->mall_id, OperationCenterEnum::ADDONS_NAME_OPERATION_CENTER, static::BASIC ); } /** * @return string */ private function getCacheField() { return OperationCenterEnum::OPERATION_CENTER . $this->mall_id . 'ceche'; } /** * @return array */ private function getCacheSetting() { $redis = Yii::$app->redis; $setting = $redis->get($this->getCacheField()); if (empty($setting)) { $setting = $this->getDbSetting(); $this->setCacheSetting($setting); } else { $setting = Json::decode($setting); } return $setting; } /** * @param array $setting * @return void */ private function setCacheSetting(array $setting) { $redis = Yii::$app->redis; $redis->setex($this->getCacheField(), 60, Json::encode($setting)); } /** * json格式化 * * @return void */ private function jsonFormat() { foreach ($this->json_fields as $field) { if (!empty($this->setting[$field])) { $this->setting[$field] = !empty($this->setting[$field]) && is_string($this->setting[$field]) ? Json::decode($this->setting[$field]) : ($this->setting[$field] ?? []); } } } /** * @return string */ public function getSwtich() { return $this->getSetting()['switch'] ?? 0; } /** * @return array */ public function getApplyingFor() { return $this->getSetting()['applying_for'] ?? []; } /** * 获取申请配置 * * @return array */ public function getApplyConfig() { return [ 'switch' => $this->getSwtich(), 'applying_for' => $this->getApplyingFor(), ]; } /** * @return boolean */ public function isOpen() { return (boolean)$this->getSwtich(); } /** * 获取佣金计算方式 * * @return int */ public function getComputingMethod() { return $this->getSetting()['computing_method']; } /** * 结算模式 * * @return int */ public function getComputeType() { return $this->getSetting()['compute_type']; } /** * @return int */ public function getLastSettingId() { return SettingLog::getLastSettingId($this->mall_id) ?? 0; } /** * 是否结算 * * @param integer $is_finish * @return boolean */ public function isSettlement(int $is_finish = 0) { $compute_type = $this->getComputeType(); // 订单完成后 && 订单完成 if ($compute_type == 1 && $is_finish == 1) return true; // 订单支付后 && 订单支付 if ($compute_type == 2 && $is_finish == 0) return true; return false; } /** * @return array */ public function getCommissionLevels() { return $this->getSetting()['commission_levels']; } /** * 是否拥有该佣金 * * @param integer $level * @return boolean */ public function hasCommission(int $level) { return in_array( $level, $this->getCommissionLevels() ); } /** * @return int */ public function getOrderLimit() { return $this->getSetting()['order_limit'] ?? 0; } }