12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use app\main\service\GdtService;
- use think\Log;
- use think\Model;
- class DataApiConfig extends Model
- {
- // 表名
- protected $table = 'data_api_config';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'is_all_text',
- 'status_text'
- ];
-
-
- public function getIsAllList()
- {
- return ['0' => '否','1' => '是'];
- }
- public function getStatusList()
- {
- return ['0' => __('Status 0'),'1' => __('Status 1')];
- }
- public function getIsAllTextAttr($value, $data)
- {
- $value = $value ? $value : $data['is_all'];
- $list = $this->getIsAllList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 拉取API配置
- * @param $client_id
- * @param bool $fromDb
- * @return array|mixed
- * @throws \think\Exception
- */
- public function getInfo($client_id, $fromDb = false)
- {
- $redisKey = "DATAAPI:".$client_id;
- if ($fromDb == false) {
- $data = Redis::instance()->get($redisKey);
- if ($data) {
- return json_decode($data, true);
- } else {
- $fromDb = true;
- }
- }
- if ($fromDb) {
- $row = $this->where('client_id', 'eq', $client_id)->find();
- if ($row) {
- $data = $row->toArray();
- } else {
- $data = [];
- }
- Redis::instance()->set($redisKey, json_encode($data), 3600);
- return $data;
- }
- return [];
- }
- }
|