$sjId, 'delStatus' => 0, 'type' => 1, 'status' => 1, 'startTime<' => $time, 'endTime>' => $time ], 'inTurn DESC', '*'); return !empty($list) ? self::groupBaseInfo($list) : []; } //广告列表 ssh 2019.12. public static function getAdList($where) { $data = self::getList('*', $where, 'inTurn DESC,updateTime DESC'); $list = $data['list']; if (!empty($list)) { $imgUrl = imgUtil::getPrefix(); foreach ($list as $key => $val) { //图片提供完整地址给前端,同时原有addImg字段不占用,定义新字段adImgUrl $list[$key]['adImgUrl'] = $imgUrl . $val['adImg']; $style = $val['style']; $url = $val['url']; if ($style == 1) { //商品地址后面再补写 $url = ''; } $list[$key]['url'] = $url; } } $data['list'] = $list; return $data; } //添加广告 public static function addAd($data) { //永久有效 $time = time(); $neverExpireTime = Yii::$app->params['neverExpireTime']; if (isset($data['endTime']) && empty($data['endTime'])) { $data['startTime'] = $time; $data['endTime'] = $neverExpireTime; } else { $data['startTime'] = strtotime($data['startTime']); $data['endTime'] = strtotime($data['endTime']); } return self::add($data); } //组装通用的信息 public static function groupBaseInfo($list) { $imgUrl = imgUtil::getPrefix(); foreach ($list as $key => $val) { $style = $val['style']; $url = $val['url']; if ($style == 1) { $url = ''; } $list[$key]['url'] = $url; $list[$key]['adImgUrl'] = $imgUrl . $val['adImg']; } return $list; } //单个广告的信息 public static function getDetail($id) { $info = self::getById($id); if (empty($info)) { util::fail('找不到广告'); } $list = self::groupBaseInfo([$info]); return current($list); } //点击数+1 public static function clickAd($id) { return self::counters(['viewTimes' => 1], ['id' => $id]); } //更新广告 public static function updateAd($id, $data) { $time = time(); //广告类型不允许修改 unset($data['type']); $neverExpireTime = Yii::$app->params['neverExpireTime']; if (isset($data['endTime']) && empty($data['endTime'])) { $data['startTime'] = $time; $data['endTime'] = $neverExpireTime; } else { $data['startTime'] = strtotime($data['startTime']); $data['endTime'] = strtotime($data['endTime']); } return self::updateById($id, $data); } //开店广告初始化 ssh 2020.2.14 public static function initAdd($sjId) { $time = time(); $list = [ ['adName' => '培训图', 'adImg' => '/example/mall/1.jpg', 'type' => 0, 'startTime' => 0, 'endTime' => 4102416000, 'addTime' => $time, 'sjId' => $sjId, 'status' => 1], ['adName' => '花礼', 'adImg' => '/example/mall/2.jpg', 'type' => 0, 'startTime' => 0, 'endTime' => 4102416000, 'addTime' => $time, 'sjId' => $sjId, 'status' => 1], ['adName' => '花艺', 'adImg' => '/example/mall/3.jpg', 'type' => 0, 'startTime' => 0, 'endTime' => 4102416000, 'addTime' => $time, 'sjId' => $sjId, 'status' => 1], ['adName' => '门店图片', 'adImg' => '/example/shop/1.jpg', 'type' => 1, 'startTime' => 0, 'endTime' => 4102416000, 'addTime' => $time, 'sjId' => $sjId, 'status' => 1], ]; foreach ($list as $val) { self::add($val); } } //删除广告 ssh 2020.5.21 public static function deleteAd($id) { self::updateById($id, ['delStatus' => 1]); } }