Bez popisu

TaskService.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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\Models\WXPopulation;
  11. use App\Support\Log;
  12. use kwaiSDK\Api\JuXing\SupplementOrderV1;
  13. class TaskService
  14. {
  15. /**
  16. * 获取星视频列表
  17. * */
  18. public static function getStarVideoList($customerId, $keyword, $remark, $startDate, $endDate, $startTime, $endTime, $page, $pageSize)
  19. {
  20. #获取广告主id
  21. $advertiserIds = SysCustomerAdver::where('customer_id', $customerId)->where('enable', 1)
  22. ->pluck('advertiser_id');
  23. if(empty($advertiserIds)) return [[], 0];
  24. if($keyword) {
  25. if(is_numeric($keyword)) { // 按任务ID或订单id搜索
  26. $taskId = JxStarVideoOrderList::getTaskIdByOrderId($advertiserIds, $keyword);
  27. if($taskId) $keyword = $taskId; // 通过订单id搜索时,将搜索条件切换为任务id
  28. } else { // 通过达人昵称搜索任务id
  29. $taskIds = JxStarVideoOrderList::getTaskIdByStarName($advertiserIds, $keyword);
  30. if(empty($taskIds)) $keyword = $taskIds;
  31. }
  32. }
  33. # 查询星视频任务列表
  34. list($list, $count) = JxStarVideoTaskList::getStartVideoList(
  35. $advertiserIds, $keyword, $remark, $startDate, $endDate, $page, $pageSize
  36. );
  37. if(!$count) return [[], 0];
  38. # 检出任务id,通过任务id查询订单信息
  39. $taskOrderList = JxStarVideoOrderList::getOrderListByTaskIds($advertiserIds, $list->pluck('task_id'), $startTime, $endTime);
  40. Log::info('订单信息', ['list' => $taskOrderList], '0205');
  41. foreach ($list as $index=>$item) {
  42. # 补充订单信息
  43. $orderList = $taskOrderList->where('task_id', $item->task_id)
  44. ->where('advertiser_id', $item->advertiser_id)
  45. ->values()->all();
  46. if(!empty($orderList)) {
  47. foreach($orderList as &$val) {
  48. $val->order_id = (string)$val->order_id;
  49. }
  50. $item->order_list = $orderList;
  51. } else {
  52. if(!$startTime && !$endTime) {
  53. $item->order_list = $orderList;
  54. } else {
  55. $count = $taskOrderList->count();
  56. unset($list[$index]);
  57. }
  58. }
  59. }
  60. return [$list->values(), $count];
  61. }
  62. /**
  63. * 配置批量创建助推订单规则
  64. * */
  65. public static function setCreateTask($params)
  66. {
  67. #获取广告主id
  68. $advertiserIds = SysCustomerAdver::where('customer_id', $params['cust_id'])->where('enable', 1)
  69. ->pluck('advertiser_id');
  70. if(empty($advertiserIds)) return 1080;
  71. $params['advertiser_id'] = implode(',', $advertiserIds->toArray());
  72. # 配置入表
  73. return SupplementOrderTask::setConfig($params);
  74. }
  75. /**
  76. * 获取批量创建助推订单的规则详情
  77. * */
  78. public static function getTaskDetail($configId, $customerId)
  79. {
  80. $detail = SupplementOrderTask::where('id', $configId)->where('cust_id', $customerId)->first();
  81. $detail->promotion_duration = $detail->promotion_duration / 1000;
  82. $detail->amount = $detail->amount / 10;
  83. $detail->unit_price = $detail->unit_price / 10;
  84. return $detail;
  85. }
  86. /**
  87. * 获取自动生成配置对应的助推订单
  88. * */
  89. public static function getOrderList($configId, $customerId)
  90. {
  91. $supplementOrderData = SupplementOrderTaskRecord::select('config_id', 'advertiser_id', 'task_id', 'order_id', 'supplement_order_id', 'status', 'message')
  92. ->where('config_id', $configId)
  93. ->get();
  94. if($supplementOrderData->isEmpty()) return [];
  95. $supplementOrderIds = $supplementOrderData->pluck('supplement_order_id');
  96. $taskIds = $supplementOrderData->pluck('task_id');
  97. # 查询助推订单信息
  98. $supplementOrderList = JxStarVideoFlowOrderList::whereIn('supplement_order_id', $supplementOrderIds)
  99. ->get();
  100. # 查询星视频任务信息
  101. $starVideoList = JxStarVideoTaskList::whereIn('task_id', $taskIds)->get();
  102. foreach ($supplementOrderData as $datum) {
  103. $orderInfo = $supplementOrderList->where('supplement_order_id', $datum->supplement_order_id)->first();
  104. $taskInfo = $starVideoList->where('task_id', $datum->task_id)->first();
  105. $datum->order_status = $orderInfo->status ?? 0;
  106. $datum->promotion_begin_time = $orderInfo->promotion_begin_time ?? null;
  107. $datum->target_type = $orderInfo->target_type ?? null;
  108. $datum->unit_type = $orderInfo->unit_type ?? null;
  109. $datum->unit_price = $orderInfo->unit_price ?? null;
  110. $datum->amount = $orderInfo->amount ?? null;
  111. $datum->star_release_time = $orderInfo->star_release_time ?? null;
  112. $datum->star_name = $orderInfo->star_name ?? null;
  113. $datum->consume_amount = $orderInfo->consume_amount ?? null;
  114. $datum->task_name = $taskInfo->task_name ?? null;
  115. }
  116. return $supplementOrderData;
  117. }
  118. /**
  119. * 获取任务列表
  120. * */
  121. public static function getTaskList($customerId, $page, $pageSize)
  122. {
  123. list($list, $count) = SupplementOrderTask::getTaskList($customerId, $page, $pageSize);
  124. $adminIdList = $list->pluck('admin_id');
  125. $adminList = SysUsers::select('id', 'name')->whereIn('id', $adminIdList)->get();
  126. foreach ($list as $item) {
  127. $adminInfo = $adminList->where('id', $item->admin_id)->first();
  128. $item->creator = $adminInfo->name ?? '';
  129. }
  130. return [$list, $count];
  131. }
  132. /**
  133. * 停用自动创建配置
  134. * */
  135. public static function stopConfig($configId, $adminId)
  136. {
  137. $configInfo = SupplementOrderTask::where('id', $configId)->first();
  138. if($configInfo->status != 1) return 1082;
  139. $configInfo->status = 4;
  140. $configInfo->admin_id = $adminId;
  141. $result = $configInfo->save();
  142. return $result ? 0 : 1084;
  143. }
  144. /**
  145. * 复用自动创建配置
  146. * */
  147. public static function reuseConfig($configId, $adminId)
  148. {
  149. $configInfo = SupplementOrderTask::where('id', $configId)->first();
  150. $configInfo->status = 1;
  151. $configInfo->admin_id = $adminId;
  152. $configInfo->exec_time = date('Y-m-d H:i:s', time() + 60 * 10);
  153. $configInfo->created_at = date('Y-m-d H:i:s');
  154. unset($configInfo->id);
  155. $result = SupplementOrderTask::create($configInfo->toArray());
  156. return $result ? 0 : 1086;
  157. }
  158. /**
  159. * 星视频任务设置备注
  160. * */
  161. public static function setRemark($advertiserId, $taskId, $remark)
  162. {
  163. $rst = JxStarVideoTaskList::where('advertiser_id', $advertiserId)->where('task_id', $taskId)
  164. ->update(['remark' => $remark]);
  165. return $rst ? 0 : 1085;
  166. }
  167. /**
  168. * 人群包列表
  169. */
  170. public static function populationList($custId, $page, $pageSize, &$errCode) {
  171. #获取广告主id
  172. $advertiserIds = SysCustomerAdver::where('customer_id', $custId)->where('enable', 1)
  173. ->pluck('advertiser_id');
  174. if(empty($advertiserIds)) {
  175. $errCode = 1080;
  176. return [[], 0];
  177. }
  178. $advertiserIdList = $advertiserIds->toArray();
  179. list($data, $count) = WXPopulation::populationList($advertiserIdList, $page, $pageSize);
  180. return [$data, $count];
  181. }
  182. }