PlatformModel.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * PlatformModel.php UTF-8
  4. * 投放平台管理
  5. *
  6. * @date : 2018/7/26 21:41
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : guxiannong <gxn@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\distribution;
  13. use huo\model\common\CommonModel;
  14. class PlatformModel extends CommonModel {
  15. protected $name = 'platform';
  16. // 开启自动写入时间戳字段
  17. protected $autoWriteTimestamp = true;
  18. // /**
  19. // * 基础查询
  20. // *
  21. // * @param $query
  22. // */
  23. // protected function base($query) {
  24. // $query->where('is_delete', 2);
  25. // }
  26. public function updateData($gmh_data, $_map = null) {
  27. $_data = $gmh_data;
  28. $_data['update_time'] = time();
  29. $_rs = self::update($_data, $_map, true);
  30. if (false == $_rs) {
  31. return false;
  32. } else {
  33. return true;
  34. }
  35. }
  36. /**
  37. * 获取单条记录
  38. *
  39. * @param int $id
  40. *
  41. * @param bool $base
  42. *
  43. * @return array|false
  44. * @throws \think\Exception
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. * @throws \think\exception\DbException
  48. */
  49. public function getInfoById($id, $base = true) {
  50. $_map['id'] = $id;
  51. $_info = $this->useGlobalScope($base)->where($_map)->find();
  52. if (false === $_info) {
  53. return false;
  54. }
  55. if (is_object($_info)) {
  56. return $_info->toArray();
  57. } else {
  58. return $_info;
  59. }
  60. }
  61. /**
  62. * @param array $where
  63. * @param int $_offset
  64. *
  65. * @return \think\Paginator
  66. * @throws \think\exception\DbException
  67. */
  68. public function getList($where = array(), $_offset = 10) {
  69. $_offset = isset($where['list_rows']) ? $where['list_rows'] : $_offset;
  70. $_order = isset($where['list_order']) ? $where['list_order'] : 'id desc';
  71. if (isset($where['id']) && !empty($where['id'])) {
  72. $_map['id'] = $where['id'];
  73. }
  74. if (isset($where['is_delete']) && !empty($where['is_delete'])) {
  75. $_map['is_delete'] = $where['is_delete'];
  76. } else {
  77. $_map['is_delete'] = 2;
  78. }
  79. if (isset($where['name']) && !empty($where['name'])) {
  80. $_map['name'] = array('like', '%'.$where['name'].'%');
  81. }
  82. $_field = "*";
  83. $items = $this->field($_field)
  84. ->where($_map)
  85. ->order($_order)
  86. ->paginate($_offset);
  87. return $items;
  88. }
  89. /**
  90. * 添加一条记录
  91. *
  92. * @param $data
  93. *
  94. * @return bool|mixed
  95. */
  96. public function addData($data) {
  97. if (empty($data)) {
  98. return false;
  99. }
  100. $_obj = self::create($data, true);
  101. if (false == $_obj) {
  102. return false;
  103. }
  104. return $_obj->id;
  105. }
  106. /**
  107. * 名称对应表
  108. *
  109. * @param array $where
  110. * @param string $_field
  111. *
  112. * @return array
  113. * @internal param bool $inc_nice
  114. *
  115. */
  116. public function getIdNames($where, $_field = 'name') {
  117. $_platforms = $this->where($where)
  118. ->column($_field, 'id');
  119. return $_platforms;
  120. }
  121. }