12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use think\Model;
- class Entryhost extends Model
- {
- // 表名
- protected $table = 'entryhost';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'status_text'
- ];
- public function getInfo($id=null){
- $redis = Redis::instance();
- if($id){
- $modulename = request()->module();
- //获取指定入口域名
- if($modulename == 'admin' && PHP_SAPI != 'cli'){ //如果是后台
- $obj = $this->where('id',$id)->find();
- $arr = is_object($obj) ? $obj->toArray() : [];
- }else{
- $key = 'EH:'.$id;
- if($redis->exists($key)){
- $arr = $redis->hgetall($key);
- }else{
- $arr = $this->where('id',$id)->find();
- if($arr){
- $arr = $arr->toArray();
- $redis->hmset($key,$arr);
- $redis->expire($key,3600);
- }
- }
- }
- return $arr;
- }
- return false;
- }
- //获取所有可用的支付域名
- public function getHosts(){
- $modulename = request()->module();
- if($modulename == 'admin' && PHP_SAPI != 'cli'){
- $res = $this->column('host');
- }else{
- $redis = Redis::instance();
- $key = 'ENTRYHOST';
- if ($ret = $redis->get($key)) {
- $res = json_decode($ret, true);
- }else{
- $res = $this->column('host');
- $redis->setex($key,86400,json_encode($res));
- }
- }
- return $res;
- }
- public function getStatusList()
- {
- return ['0' => __('Status 0'),'1' => __('Status 1')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- }
|