No Description

Advert.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Model\Advert\V1;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Support\Facades\DB;
  5. class Advert extends Model
  6. {
  7. /**
  8. * [getAdvertById 根据广告id获取广告信息]
  9. * @Author mzb
  10. * @DateTime 2018-07-25T11:40:20+0800
  11. * @param [type] $advertId [description]
  12. * @param integer $status [description]
  13. * @return [type] [description]
  14. */
  15. public static function getAdvertById($advertId = [], $status = [2], $time = null)
  16. {
  17. $data = DB::table('advert')->select('id', 'name', 'advert_text', 'img_url', 'advert_url', 'type')->whereIn('id', $advertId)->where(function ($sql) use ($status, $time) {
  18. if (!is_null($status)) {
  19. $sql->whereIn('status', $status);
  20. }
  21. if (!is_null($time)) {
  22. $sql->where('start_time', '<=', $time)->where('end_time', '>=', $time);
  23. }
  24. })->get()->toArray();
  25. return $data;
  26. }
  27. /**
  28. * [addBrowseRecords 广告浏览入库]
  29. * @Author mzb
  30. * @DateTime 2018-07-25T12:01:13+0800
  31. * @param [type] $spaceSign [description]
  32. */
  33. public static function addBrowseRecords($spaceSign, $advertId, $appAdvertId)
  34. {
  35. $time = time();
  36. $success = DB::table('advert_statistics')->insert(['space_id' => $spaceSign, 'created_at' => $time, 'updated_at' => $time, 'status' => 1, 'advert_id' => $advertId, 'app_advert_id' => $appAdvertId]);
  37. return $success;
  38. }
  39. /**
  40. * [getAdverSpaceInfoBySign 获取广告位详细信息]
  41. * @Author mzb
  42. * @DateTime 2018-07-25T13:27:57+0800
  43. * @param [type] $spaceSign [description]
  44. * @param integer $status [description]
  45. * @return [type] [description]
  46. */
  47. public static function getAdverSpaceInfoBySign($spaceId, $status = 1)
  48. {
  49. $data = DB::table('advert_space')->select('id', 'name', 'app_advert_id', 'status')->where('id', $spaceId)->where(function ($sql) use ($status) {
  50. if (!is_null($status)) {
  51. $sql->where('status', $status);
  52. }
  53. })->first();
  54. return $data;
  55. }
  56. /**
  57. * [getAdvertIdsBySpaceId 获取广告id]
  58. * @Author mzb
  59. * @DateTime 2018-07-31T09:41:54+0800
  60. * @param [type] $spaceId [description]
  61. * @param integer $status [description]
  62. * @return [type] [description]
  63. */
  64. public static function getAdvertIdsBySpaceId($spaceId, $status = [1])
  65. {
  66. $data = DB::table('space_advert')->where('space_id', $spaceId)->where(function ($sql) use ($status) {
  67. if (!is_null($status)) {
  68. $sql->whereIn('status', $status);
  69. }
  70. })->pluck('advert_id');
  71. return $data;
  72. }
  73. }