255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'key' => 'Key', 'value' => 'Value', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } /** * 字符串转数字 * * @param [type] $key * @param [type] $str * @return void */ public static function strToNumber($key, $str) { $default = ['title', 'settlement_method', 'explain']; if (in_array($key, $default)) { return round($str, 2); } return $str; } /** * 保存数据 * * @return void */ public static function setData($mall_id, $params) { try { $setting_list = []; foreach ($params as $index => $item) { $setting_list[] = [ 'key' => $index, 'value' => $item ]; } foreach ($setting_list as $item) { $setting = self::findOne(['mall_id' => $mall_id, 'key' => $item['key']]); if (!$setting) { $setting = new self(); } $setting->key = $item['key']; $setting->value = $item['value']; $setting->mall_id = $mall_id; $setting->status = 1; $setting->save(); } return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } /** * @param null $key * @return bool|string|void */ public static function getValueByKey($key = null, $mall_id = null) { if (!$key) { return false; } if (!$mall_id) { $mall_id = Yii::$app->mall->id; } if (!$mall_id) { return false; } $model = self::findOne(['mall_id' => $mall_id, 'status' => 1, 'key' => $key]); if ($model) { return $model->value; } return false; } }