123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace App\Services\Data;
- use App\Models\JxStarVideoFlowOrderList;
- use App\Models\JxStarVideoOrderList;
- use App\Models\JxStarVideoTaskList;
- use App\Models\SupplementOrderTask;
- use App\Models\SupplementOrderTaskRecord;
- use App\Models\Sys\SysCustomerAdver;
- use App\Models\Sys\SysUsers;
- use App\Support\Log;
- class TaskService
- {
- /**
- * 获取星视频列表
- * */
- public static function getStarVideoList($customerId, $keyword, $startDate, $endDate, $page, $pageSize)
- {
- #获取广告主id
- $advertiserIds = SysCustomerAdver::where('customer_id', $customerId)->where('enable', 1)
- ->pluck('advertiser_id');
- if(empty($advertiserIds)) return [[], 0];
- if($keyword) {
- if(is_numeric($keyword)) { // 按任务ID或订单id搜索
- $taskId = JxStarVideoOrderList::getTaskIdByOrderId($advertiserIds, $keyword);
- if($taskId) $keyword = $taskId; // 通过订单id搜索时,将搜索条件切换为任务id
- } else { // 通过达人昵称搜索任务id
- $taskIds = JxStarVideoOrderList::getTaskIdByStarName($advertiserIds, $keyword);
- if(empty($taskIds)) $keyword = $taskIds;
- }
- }
- # 查询星视频任务列表
- list($list, $count) = JxStarVideoTaskList::getStartVideoList(
- $advertiserIds, $keyword, $startDate, $endDate, $page, $pageSize
- );
- if(!$count) return [[], 0];
- # 检出任务id,通过任务id查询订单信息
- $taskOrderList = JxStarVideoOrderList::getOrderListByTaskIds($advertiserIds, $list->pluck('task_id'));
- foreach ($list as $item) {
- # 补充订单信息
- $orderList = $taskOrderList->where('task_id', $item->task_id)
- ->where('advertiser_id', $item->advertiser_id)
- ->values()->all();
- if(!empty($orderList)) {
- foreach($orderList as &$val) {
- $val->order_id = (string)$val->order_id;
- }
- }
- $item->order_list = $orderList;
- }
- return [$list, $count];
- }
- /**
- * 配置批量创建助推订单规则
- * */
- public static function setCreateTask($params)
- {
- #获取广告主id
- $advertiserIds = SysCustomerAdver::where('customer_id', $params['cust_id'])->where('enable', 1)
- ->pluck('advertiser_id');
- if(empty($advertiserIds)) return 1080;
- $params['advertiser_id'] = implode(',', $advertiserIds->toArray());
- # 配置入表
- return SupplementOrderTask::setConfig($params);
- }
- /**
- * 获取批量创建助推订单的规则详情
- * */
- public static function getTaskDetail($configId, $customerId)
- {
- $detail = SupplementOrderTask::where('id', $configId)->where('cust_id', $customerId)->first();
- $detail->promotion_duration = $detail->promotion_duration / 1000;
- $detail->amount = $detail->amount / 10;
- $detail->unit_price = $detail->unit_price / 10;
- return $detail;
- }
- /**
- * 获取自动生成配置对应的助推订单
- * */
- public static function getOrderList($configId, $customerId)
- {
- $supplementOrderData = SupplementOrderTaskRecord::select('config_id', 'advertiser_id', 'task_id', 'order_id', 'supplement_order_id', 'status', 'message')
- ->where('config_id', $configId)
- ->get();
- if($supplementOrderData->isEmpty()) return [];
- $supplementOrderIds = $supplementOrderData->pluck('supplement_order_id');
- $taskIds = $supplementOrderData->pluck('task_id');
- # 查询助推订单信息
- $supplementOrderList = JxStarVideoFlowOrderList::whereIn('supplement_order_id', $supplementOrderIds)
- ->get();
- # 查询星视频任务信息
- $starVideoList = JxStarVideoTaskList::whereIn('task_id', $taskIds)->get();
- foreach ($supplementOrderData as $datum) {
- $orderInfo = $supplementOrderList->where('supplement_order_id', $datum->supplement_order_id)->first();
- $taskInfo = $starVideoList->where('task_id', $datum->task_id)->first();
- $datum->order_status = $orderInfo->status ?? 0;
- $datum->promotion_begin_time = $orderInfo->promotion_begin_time ?? null;
- $datum->target_type = $orderInfo->target_type ?? null;
- $datum->unit_type = $orderInfo->unit_type ?? null;
- $datum->unit_price = $orderInfo->unit_price ?? null;
- $datum->amount = $orderInfo->amount ?? null;
- $datum->star_release_time = $orderInfo->star_release_time ?? null;
- $datum->star_name = $orderInfo->star_name ?? null;
- $datum->consume_amount = $orderInfo->consume_amount ?? null;
- $datum->task_name = $taskInfo->task_name ?? null;
- }
- return $supplementOrderData;
- }
- /**
- * 获取任务列表
- * */
- public static function getTaskList($customerId, $page, $pageSize)
- {
- list($list, $count) = SupplementOrderTask::getTaskList($customerId, $page, $pageSize);
- $adminIdList = $list->pluck('admin_id');
- $adminList = SysUsers::select('id', 'name')->whereIn('id', $adminIdList)->get();
- foreach ($list as $item) {
- $adminInfo = $adminList->where('id', $item->admin_id)->first();
- $item->creator = $adminInfo->name ?? '';
- }
- return [$list, $count];
- }
- /**
- * 停用自动创建配置
- * */
- public static function stopConfig($configId, $adminId)
- {
- $configInfo = SupplementOrderTask::where('id', $configId)->first();
- if($configInfo->status != 1) return 1082;
- $configInfo->status = 4;
- $configInfo->admin_id = $adminId;
- $result = $configInfo->save();
- return $result ? 0 : 1084;
- }
- /**
- * 星视频任务设置备注
- * */
- public static function setRemark($advertiserId, $taskId, $remark)
- {
- $rst = JxStarVideoTaskList::where('advertiser_id', $advertiserId)->where('task_id', $taskId)
- ->update(['remark' => $remark]);
- return $rst ? 0 : 1085;
- }
- }
|