12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Models;
- use App\Log;
- use Illuminate\Database\Eloquent\Model;
- class AdPlacement extends Model
- {
- protected $table = 'ad_placement';
- public $timestamps = false;
- protected static $unguarded = true;
- CONST SYNC_AD_PLACEMENT_LIST = 'DouApp::syncAdPlacementList';
- CONST AD_PLACEMENT_TYPE = [
- 1 => 'Banner广告',
- 2 => '视频激励广告',
- 3 => '信息流广告',
- 4 => '插屏广告',
- 5 => '视频前贴片广告',
- 6 => '视频后贴片广告'
- ];
- public static function saveData($appId, $adPlacementList) {
- \DB::begintransaction();
- foreach($adPlacementList as $adPlacementInfo) {
- $con = [
- 'app_id' => $appId,
- 'ad_placement_id' => $adPlacementInfo['ad_placement_id'] ?? '',
- ];
- $attr = [
- 'ad_placement_name' => $adPlacementInfo['ad_placement_name'] ?? '',
- 'ad_placement_type' => $adPlacementInfo['ad_placement_type'] ?? '',
- 'status' => $adPlacementInfo['status'],
- ];
- $res = self::query()->updateOrCreate($con, $attr);
- if(!$res) {
- Log::logError('保存广告位列表异常', ['app_id' => $appId, 'ad_placement_list' => $adPlacementList], 'adPlacement');
- \DB::rollback();
- return false;
- }
- }
- \DB::commit();
- return true;
- }
- public static function searchData($search, $page, $pageSize) {
- $model = self::query()->where('enable', 1);
- if(isset($search['app_id']) && !empty($search['app_id'])) {
- $model->where('app_id', $search['app_id']);
- }
- if(isset($search['status']) && is_numeric($search['status'])) {
- $model = $model->where('status', $search['status']);
- }
- if(isset($search['type']) && !empty($search['type'])) {
- $model = $model->where('ad_placement_type', $search['type']);
- }
- if(isset($search['keyword']) && !empty($search['keyword'])) {
- $model = $model->where('ad_placement_name', 'like', '%'.$search['keyword'].'%');
- }
- $count = $model->count();
- $data = $model->selectRaw('id, ad_placement_id, ad_placement_type as type, ad_placement_name, status,'
- .' app_id')->orderBy('sort', 'desc')->orderBy('id', 'desc')
- ->offset(($page - 1) * $pageSize)->limit($pageSize)->get();
- return [$data, $count];
- }
- public static function updateData($appId, $adPlacementId, $status) {
- return self::query()->where('app_id', $appId)->where('ad_placement_id', $adPlacementId)
- ->where('enable', 1)->update(['status' => $status]);
- }
- }
|