123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- /**
- * PlatformModel.php UTF-8
- * 投放平台管理
- *
- * @date : 2018/7/26 21:41
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : guxiannong <gxn@huosdk.com>
- * @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;
- }
- }
|