* @version : HUOSDK 8.0 */ namespace huo\model\distribution; use huo\model\common\CommonModel; class PlatformModel extends CommonModel { protected $name = 'platform'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; // /** // * 基础查询 // * // * @param $query // */ // protected function base($query) { // $query->where('is_delete', 2); // } public function updateData($gmh_data, $_map = null) { $_data = $gmh_data; $_data['update_time'] = time(); $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } /** * 获取单条记录 * * @param int $id * * @param bool $base * * @return array|false * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getInfoById($id, $base = true) { $_map['id'] = $id; $_info = $this->useGlobalScope($base)->where($_map)->find(); if (false === $_info) { return false; } if (is_object($_info)) { return $_info->toArray(); } else { return $_info; } } /** * @param array $where * @param int $_offset * * @return \think\Paginator * @throws \think\exception\DbException */ public function getList($where = array(), $_offset = 10) { $_offset = isset($where['list_rows']) ? $where['list_rows'] : $_offset; $_order = isset($where['list_order']) ? $where['list_order'] : 'id desc'; if (isset($where['id']) && !empty($where['id'])) { $_map['id'] = $where['id']; } if (isset($where['is_delete']) && !empty($where['is_delete'])) { $_map['is_delete'] = $where['is_delete']; } else { $_map['is_delete'] = 2; } if (isset($where['name']) && !empty($where['name'])) { $_map['name'] = array('like', '%'.$where['name'].'%'); } $_field = "*"; $items = $this->field($_field) ->where($_map) ->order($_order) ->paginate($_offset); return $items; } /** * 添加一条记录 * * @param $data * * @return bool|mixed */ public function addData($data) { if (empty($data)) { return false; } $_obj = self::create($data, true); if (false == $_obj) { return false; } return $_obj->id; } /** * 名称对应表 * * @param array $where * @param string $_field * * @return array * @internal param bool $inc_nice * */ public function getIdNames($where, $_field = 'name') { $_platforms = $this->where($where) ->column($_field, 'id'); return $_platforms; } }