Nav apraksta

JxTransformRecord.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class JxTransformRecord extends Model
  5. {
  6. protected $table = 'jx_transform_record';
  7. public $timestamps = false;
  8. protected static $unguarded = true;
  9. const PLATFORM_LIST = [1 => '大航海'];
  10. /**
  11. * 获取订单列表
  12. *
  13. * 该方法根据提供的参数筛选订单,并分页返回订单列表及总数
  14. * 主要涉及根据订单金额、回传状态、客户和广告主等条件进行筛选
  15. *
  16. * @param array $params 筛选条件数组,包含金额范围、回传状态、客户ID和广告主ID等
  17. * @param int $page 当前页码,用于计算偏移量
  18. * @param int $pageSize 每页显示的记录数
  19. *
  20. * @return array 返回包含订单总数和订单列表的数组
  21. */
  22. public static function getTransformList($params, $page, $pageSize)
  23. {
  24. # 初始化查询模型
  25. $queryModel = self::query();
  26. # 按用户行为类型筛选
  27. if (is_numeric($params['transform_type'])) {
  28. $queryModel->where('transform_type', $params['transform_type']);
  29. }
  30. # 按回传状态筛选
  31. if (is_numeric($params['report_action_type'])) {
  32. $queryModel->where('report_action_type', $params['report_action_type']);
  33. }
  34. # 按客户筛选
  35. if ($params['customer_id']) {
  36. $queryModel->where('customer_id', $params['customer_id']);
  37. }
  38. # 按广告主筛选
  39. if ($params['advertiser_id']) {
  40. $queryModel->where('advertiser_id', $params['advertiser_id']);
  41. }
  42. # 按起始时间筛选
  43. if ($params['start_time']) {
  44. $queryModel->where('created_at', '>=', $params['start_time'] . ' 00:00:00');
  45. }
  46. # 按结束时间筛选
  47. if ($params['end_time']) {
  48. $queryModel->where('created_at', '<=', $params['end_time'] . ' 23:59:59');
  49. }
  50. # 计算满足条件的订单总数
  51. $count = $queryModel->count();
  52. # 执行查询,获取当前页的订单列表
  53. $list = $queryModel->select('id', 'platform', 'transform_type', 'callback_url', 'report_action_type', 'report_order_status', 'customer_id', 'advertiser_id', 'created_at', 'task_id')
  54. ->offset(($page - 1) * $pageSize)->limit($pageSize)
  55. ->orderBy('id', 'desc')
  56. ->get();
  57. # 返回订单总数和订单列表
  58. return [$list, $count];
  59. }
  60. public static function saveData($data) {
  61. return self::create($data);
  62. }
  63. public static function getInfo($adPlacementLogId, $transformType) {
  64. return self::query()->where('ad_placement_log_id', $adPlacementLogId)->where('transform_type', $transformType)->first();
  65. }
  66. }