Няма описание

WXPopulation.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class WXPopulation extends Model
  5. {
  6. protected $table = 'wx_population';
  7. public $timestamps = false;
  8. protected static $unguarded = true;
  9. /**
  10. * 人群包列表
  11. */
  12. public static function populationList($advertiserIdList, $page, $pageSize) {
  13. $model = self::query()->whereIn('advertiser_id', $advertiserIdList)->where('enable', 1);
  14. $countModel = clone $model;
  15. $count = $countModel->count();
  16. $data = $model->selectRaw('id, advertiser_id, orientation_id, orientation_name')->offset(($page - 1) * $pageSize)
  17. ->limit($pageSize)->get();
  18. return [$data, $count];
  19. }
  20. public static function populationListTest($advertiserIdList, $page, $pageSize) {
  21. $data = [
  22. [
  23. 'id' => 1, 'advertiser_id' => 50277633, 'orientation_id' => 162018525, 'orientation_name' => '美团APP已安装'
  24. ],
  25. [
  26. 'id' => 2, 'advertiser_id' => 50277633, 'orientation_id' => 161633748, 'orientation_name' => '百补'
  27. ]
  28. ];
  29. return [$data, 2];
  30. }
  31. /**
  32. * 人群包列表
  33. * */
  34. public static function getPopulationList($advertiserId, $orientationId, $orientationName, $page, $pageSize)
  35. {
  36. $queryModel = self::query();
  37. # 按广告账户搜索
  38. if($advertiserId)
  39. $queryModel->where('advertiser_id', 'like', '%'.$advertiserId.'%');
  40. # 按人群包id搜索
  41. if($orientationId)
  42. $queryModel->where('orientation_id', 'like', '%'.$orientationId.'%');
  43. # 按人群包名称搜索
  44. if($orientationName)
  45. $queryModel->where('orientation_name', 'like', '%'.$orientationName.'%');
  46. $count = $queryModel->count();
  47. $list = $queryModel->select('id', 'advertiser_id', 'orientation_id', 'orientation_name', 'enable')->offset(($page - 1) * $pageSize)
  48. ->limit($pageSize)->orderBy('id', 'desc')
  49. ->get();
  50. return [$list, $count];
  51. }
  52. }