39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Auto_product_setting_model extends HD_Model
|
|
{
|
|
private $table_name = 'lc_auto_product_setting';
|
|
private $cacheKey = 'PRODUCTS_SETTING_%d_%s';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this->table_name, 'default');
|
|
}
|
|
|
|
public function setValue($productId, $key, $value)
|
|
{
|
|
$cache = load_cache();
|
|
$data = [
|
|
'product_id' => $productId,
|
|
'name' => $key,
|
|
'value' => is_array($value) ? json_encode($value,JSON_UNESCAPED_UNICODE) : $value,
|
|
];
|
|
$this->replace($data);
|
|
$cache->delete(sprintf($this->cacheKey, $productId, $key));
|
|
}
|
|
|
|
public function getValue($productId, $name)
|
|
{
|
|
$cache = load_cache();
|
|
$cacheKey = sprintf($this->cacheKey, $productId, $name);
|
|
$result = $cache->get($cacheKey);
|
|
if (!$cache->exists($cacheKey)) {
|
|
$row = $this->get(['product_id' => $productId, 'name' => $name]);
|
|
$result = $row['value'];
|
|
$cache->save($cacheKey, $result, 2*3600);
|
|
}
|
|
return $result;
|
|
}
|
|
}
|