Entryhost.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\Redis;
  4. use think\Model;
  5. class Entryhost extends Model
  6. {
  7. // 表名
  8. protected $table = 'entryhost';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. // 追加属性
  15. protected $append = [
  16. 'status_text'
  17. ];
  18. public function getInfo($id=null){
  19. $redis = Redis::instance();
  20. if($id){
  21. $modulename = request()->module();
  22. //获取指定入口域名
  23. if($modulename == 'admin' && PHP_SAPI != 'cli'){ //如果是后台
  24. $obj = $this->where('id',$id)->find();
  25. $arr = is_object($obj) ? $obj->toArray() : [];
  26. }else{
  27. $key = 'EH:'.$id;
  28. if($redis->exists($key)){
  29. $arr = $redis->hgetall($key);
  30. }else{
  31. $arr = $this->where('id',$id)->find();
  32. if($arr){
  33. $arr = $arr->toArray();
  34. $redis->hmset($key,$arr);
  35. $redis->expire($key,3600);
  36. }
  37. }
  38. }
  39. return $arr;
  40. }
  41. return false;
  42. }
  43. //获取所有可用的支付域名
  44. public function getHosts(){
  45. $modulename = request()->module();
  46. if($modulename == 'admin' && PHP_SAPI != 'cli'){
  47. $res = $this->column('host');
  48. }else{
  49. $redis = Redis::instance();
  50. $key = 'ENTRYHOST';
  51. if ($ret = $redis->get($key)) {
  52. $res = json_decode($ret, true);
  53. }else{
  54. $res = $this->column('host');
  55. $redis->setex($key,86400,json_encode($res));
  56. }
  57. }
  58. return $res;
  59. }
  60. public function getStatusList()
  61. {
  62. return ['0' => __('Status 0'),'1' => __('Status 1')];
  63. }
  64. public function getStatusTextAttr($value, $data)
  65. {
  66. $value = $value ? $value : $data['status'];
  67. $list = $this->getStatusList();
  68. return isset($list[$value]) ? $list[$value] : '';
  69. }
  70. }