Aucune description

TaskService.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace App\Services\Data;
  3. use App\Models\JxStarVideoFlowOrderList;
  4. use App\Models\JxStarVideoOrderList;
  5. use App\Models\JxStarVideoTaskList;
  6. use App\Models\SupplementOrderTask;
  7. use App\Models\SupplementOrderTaskRecord;
  8. use App\Models\Sys\SysCustomerAdver;
  9. use App\Models\Sys\SysUsers;
  10. use App\Support\Log;
  11. class TaskService
  12. {
  13. /**
  14. * 获取星视频列表
  15. * */
  16. public static function getStarVideoList($customerId, $keyword, $startDate, $endDate, $page, $pageSize)
  17. {
  18. #获取广告主id
  19. $advertiserIds = SysCustomerAdver::where('customer_id', $customerId)->where('enable', 1)
  20. ->pluck('advertiser_id');
  21. if(empty($advertiserIds)) return [[], 0];
  22. if($keyword) {
  23. if(is_numeric($keyword)) { // 按任务ID或订单id搜索
  24. $taskId = JxStarVideoOrderList::getTaskIdByOrderId($advertiserIds, $keyword);
  25. if($taskId) $keyword = $taskId; // 通过订单id搜索时,将搜索条件切换为任务id
  26. } else { // 通过达人昵称搜索任务id
  27. $taskIds = JxStarVideoOrderList::getTaskIdByStarName($advertiserIds, $keyword);
  28. if(empty($taskIds)) $keyword = $taskIds;
  29. }
  30. }
  31. # 查询星视频任务列表
  32. list($list, $count) = JxStarVideoTaskList::getStartVideoList(
  33. $advertiserIds, $keyword, $startDate, $endDate, $page, $pageSize
  34. );
  35. if(!$count) return [[], 0];
  36. # 检出任务id,通过任务id查询订单信息
  37. $taskOrderList = JxStarVideoOrderList::getOrderListByTaskIds($advertiserIds, $list->pluck('task_id'));
  38. foreach ($list as $item) {
  39. # 补充订单信息
  40. $orderList = $taskOrderList->where('task_id', $item->task_id)
  41. ->where('advertiser_id', $item->advertiser_id)
  42. ->values()->all();
  43. if(!empty($orderList)) {
  44. foreach($orderList as &$val) {
  45. $val->order_id = (string)$val->order_id;
  46. }
  47. }
  48. $item->order_list = $orderList;
  49. }
  50. return [$list, $count];
  51. }
  52. /**
  53. * 配置批量创建助推订单规则
  54. * */
  55. public static function setCreateTask($params)
  56. {
  57. #获取广告主id
  58. $advertiserIds = SysCustomerAdver::where('customer_id', $params['cust_id'])->where('enable', 1)
  59. ->pluck('advertiser_id');
  60. if(empty($advertiserIds)) return 1080;
  61. $params['advertiser_id'] = implode(',', $advertiserIds->toArray());
  62. # 配置入表
  63. return SupplementOrderTask::setConfig($params);
  64. }
  65. /**
  66. * 获取批量创建助推订单的规则详情
  67. * */
  68. public static function getTaskDetail($configId, $customerId)
  69. {
  70. $detail = SupplementOrderTask::where('id', $configId)->where('cust_id', $customerId)->first();
  71. $detail->promotion_duration = $detail->promotion_duration / 1000;
  72. $detail->amount = $detail->amount / 10;
  73. $detail->unit_price = $detail->unit_price / 10;
  74. return $detail;
  75. }
  76. /**
  77. * 获取自动生成配置对应的助推订单
  78. * */
  79. public static function getOrderList($configId, $customerId)
  80. {
  81. $supplementOrderData = SupplementOrderTaskRecord::select('config_id', 'advertiser_id', 'task_id', 'order_id', 'supplement_order_id', 'status', 'message')
  82. ->where('config_id', $configId)
  83. ->get();
  84. if($supplementOrderData->isEmpty()) return [];
  85. $supplementOrderIds = $supplementOrderData->pluck('supplement_order_id');
  86. $taskIds = $supplementOrderData->pluck('task_id');
  87. # 查询助推订单信息
  88. $supplementOrderList = JxStarVideoFlowOrderList::whereIn('supplement_order_id', $supplementOrderIds)
  89. ->get();
  90. # 查询星视频任务信息
  91. $starVideoList = JxStarVideoTaskList::whereIn('task_id', $taskIds)->get();
  92. foreach ($supplementOrderData as $datum) {
  93. $orderInfo = $supplementOrderList->where('supplement_order_id', $datum->supplement_order_id)->first();
  94. $taskInfo = $starVideoList->where('task_id', $datum->task_id)->first();
  95. $datum->order_status = $orderInfo->status ?? 0;
  96. $datum->promotion_begin_time = $orderInfo->promotion_begin_time ?? null;
  97. $datum->target_type = $orderInfo->target_type ?? null;
  98. $datum->unit_type = $orderInfo->unit_type ?? null;
  99. $datum->unit_price = $orderInfo->unit_price ?? null;
  100. $datum->amount = $orderInfo->amount ?? null;
  101. $datum->star_release_time = $orderInfo->star_release_time ?? null;
  102. $datum->star_name = $orderInfo->star_name ?? null;
  103. $datum->consume_amount = $orderInfo->consume_amount ?? null;
  104. $datum->task_name = $taskInfo->task_name ?? null;
  105. }
  106. return $supplementOrderData;
  107. }
  108. /**
  109. * 获取任务列表
  110. * */
  111. public static function getTaskList($customerId, $page, $pageSize)
  112. {
  113. list($list, $count) = SupplementOrderTask::getTaskList($customerId, $page, $pageSize);
  114. $adminIdList = $list->pluck('admin_id');
  115. $adminList = SysUsers::select('id', 'name')->whereIn('id', $adminIdList)->get();
  116. foreach ($list as $item) {
  117. $adminInfo = $adminList->where('id', $item->admin_id)->first();
  118. $item->creator = $adminInfo->name ?? '';
  119. }
  120. return [$list, $count];
  121. }
  122. /**
  123. * 停用自动创建配置
  124. * */
  125. public static function stopConfig($configId, $adminId)
  126. {
  127. $configInfo = SupplementOrderTask::where('id', $configId)->first();
  128. if($configInfo->status != 1) return 1082;
  129. $configInfo->status = 4;
  130. $configInfo->admin_id = $adminId;
  131. $result = $configInfo->save();
  132. return $result ? 0 : 1084;
  133. }
  134. /**
  135. * 星视频任务设置备注
  136. * */
  137. public static function setRemark($advertiserId, $taskId, $remark)
  138. {
  139. $rst = JxStarVideoTaskList::where('advertiser_id', $advertiserId)->where('task_id', $taskId)
  140. ->update(['remark' => $remark]);
  141. return $rst ? 0 : 1085;
  142. }
  143. }