1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Model\Advert\V1;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- class Advert extends Model
- {
- /**
- * [getAdvertById 根据广告id获取广告信息]
- * @Author mzb
- * @DateTime 2018-07-25T11:40:20+0800
- * @param [type] $advertId [description]
- * @param integer $status [description]
- * @return [type] [description]
- */
- public static function getAdvertById($advertId = [], $status = [2], $time = null)
- {
- $data = DB::table('advert')->select('id', 'name', 'advert_text', 'img_url', 'advert_url', 'type')->whereIn('id', $advertId)->where(function ($sql) use ($status, $time) {
- if (!is_null($status)) {
- $sql->whereIn('status', $status);
- }
- if (!is_null($time)) {
- $sql->where('start_time', '<=', $time)->where('end_time', '>=', $time);
- }
- })->get()->toArray();
- return $data;
- }
- /**
- * [addBrowseRecords 广告浏览入库]
- * @Author mzb
- * @DateTime 2018-07-25T12:01:13+0800
- * @param [type] $spaceSign [description]
- */
- public static function addBrowseRecords($spaceSign, $advertId, $appAdvertId)
- {
- $time = time();
- $success = DB::table('advert_statistics')->insert(['space_id' => $spaceSign, 'created_at' => $time, 'updated_at' => $time, 'status' => 1, 'advert_id' => $advertId, 'app_advert_id' => $appAdvertId]);
- return $success;
- }
- /**
- * [getAdverSpaceInfoBySign 获取广告位详细信息]
- * @Author mzb
- * @DateTime 2018-07-25T13:27:57+0800
- * @param [type] $spaceSign [description]
- * @param integer $status [description]
- * @return [type] [description]
- */
- public static function getAdverSpaceInfoBySign($spaceId, $status = 1)
- {
- $data = DB::table('advert_space')->select('id', 'name', 'app_advert_id', 'status')->where('id', $spaceId)->where(function ($sql) use ($status) {
- if (!is_null($status)) {
- $sql->where('status', $status);
- }
- })->first();
- return $data;
- }
- /**
- * [getAdvertIdsBySpaceId 获取广告id]
- * @Author mzb
- * @DateTime 2018-07-31T09:41:54+0800
- * @param [type] $spaceId [description]
- * @param integer $status [description]
- * @return [type] [description]
- */
- public static function getAdvertIdsBySpaceId($spaceId, $status = [1])
- {
- $data = DB::table('space_advert')->where('space_id', $spaceId)->where(function ($sql) use ($status) {
- if (!is_null($status)) {
- $sql->whereIn('status', $status);
- }
- })->pluck('advert_id');
- return $data;
- }
- }
|