123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- // +----------------------------------------------------------------------
- // | 文件说明:用户-幻灯片
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Author: wuwu <15093565100@163.com>
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Date: 2017-5-25
- // +----------------------------------------------------------------------
- namespace huo\model\slide;
- use huo\model\common\CommonModel;
- use think\exception\PDOException;
- class SlideModel extends CommonModel {
- /**
- * 全局查询范围status=1显示状态
- *
- * @param $query
- */
- protected function base($query) {
- $query->where('status', 2)->where('delete_time', 0);
- }
- /**
- * SlideItemModel 一对多关联模型 关联分类下的幻灯片
- *
- */
- protected function items() {
- return $this->hasMany(SlideItemModel::className(), 'slide_id', 'id')
- ->order('list_order ASC');
- }
- /**
- * SlideList 幻灯片获取
- *
- * @param array $map
- *
- * @param string $page
- *
- * @return false|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getSlideList($map, $page = '1,10') {
- $_page = $page;
- if (empty($page)) {
- $_page = '1,10';
- }
- $data = $this->relation('items')->field(true)->where($map)->page($_page)->select();
- return $data;
- }
- public function getSlideIdsByDevice($device) {
- if (empty($device)) {
- return false;
- }
- return $this->where(['device' => $device])->column(['id']);
- }
- public function getSlideCodesByDevice($device) {
- if (empty($device)) {
- return false;
- }
- return $this->where(['device' => $device])->column('code');
- }
- public function getSlideIdByCode($code) {
- if (empty($code)) {
- return false;
- }
- return $this->where(['code' => $code])->value('id');
- }
- public function getCodeById($id = 0) {
- if (empty($id)) {
- return 0;
- }
- return $this->where(['id' => $id])->limit('1')->value('code');
- }
- public function getTypeIdById($id = 0) {
- if (empty($id)) {
- return 0;
- }
- return $this->where(['id' => $id])->limit('1')->value('type_id');
- }
- /**
- * 添加数据
- *
- * @param $data
- *
- * @return bool
- */
- public function addData($data) {
- if (empty($data)) {
- return false;
- }
- $_data = $data;
- $_obj = self::create($_data, true);
- if ($_obj) {
- return true;
- }
- return false;
- }
- /**
- * 删除数据
- *
- * @param array $_map 删除条件
- *
- * @return int
- */
- public function deleteDataByMap($_map) {
- $_id = self::where($_map)->column('id');
- self::startTrans();
- try {
- self::where($_map)->delete();
- (new SlideItemModel())->where(['slide_id' => ['in', $_id]])->delete();
- // 提交事务
- self::commit();
- } catch (\Exception $e) {
- // 回滚事务
- self::rollback();
- return false;
- }
- return true;
- }
- }
|