select('redirect_url', 'book_id', 'send_time', 'distribution_channel_id', 'name','promotion_point','force_show_qrcode')->first(); } /** * 根据id获取信息 * @param $id * @return mixed */ static function getById($id) { return SendOrder::find($id); } //获取推广总uv、pv static function getChannelPromotionTotalUvPv($distribution_channel_id, $date) { //return WapVisitStatService::getChannelPromotionTotalUvPv($distribution_channel_id,$date); $send_orders = SendOrder::getSendOrders(null, $distribution_channel_id, null, null, '', '', '', true); $uv = 0; $pv = 0; foreach ($send_orders as $send_order) { $uv += (float)Redis::hget('send_order_uv_' . $send_order->id, $date); $pv += (float)Redis::hget('send_order_pv_' . $send_order->id, $date); } return compact('uv', 'pv'); } /** * 获取date的实际派单数 */ static function getActualSendOrderNum($distribution_channel_id, $date) { return SendOrder::whereBetween('send_time', [$date, date('Y-m-d', strtotime($date) + 86400)])->where('distribution_channel_id', $distribution_channel_id)->count(); } /** * 获取继续阅读的uv * @param $distribution_channel_id * @param $date * @return array */ static function getContinueTotalReadUv($send_order_id) { return (float)Redis::hget('send_order:continue:' . $send_order_id, 'total'); } /** * 设置成本 * @param $id 派单id * @param $distribution_channel_id 渠道id * @param $cost 成本 * @return mixed */ static function setSendOrderCost($id, $distribution_channel_id, $cost) { return SendOrder::setSendOrderCost($id, $distribution_channel_id, $cost); } /** * 获取派单下的首充用户数 * $id 派单id * @param $id */ static function getFirstChargeUserNum($id) { return SendOrder::getFirstChargeUserNum($id); } /** * 获取派单下的非首充用户数 * $id 派单id * @param $id */ static function getRepetitiousChargeUserNum($id) { return SendOrder::getRepetitiousChargeUserNum($id); } /** * 获取派单uv大于20的时间 * @param $sendOrderId 派单id * @return float|int 时间 */ static function getUv20Time($sendOrderId) { $uv20Time = ''; $periodTotalUV = 0; $uvInfos = SendOrderService::getUvInfo($sendOrderId); if (isset($uvInfos['total'])) { unset($uvInfos['total']); } ksort($uvInfos); foreach ($uvInfos as $key => $v) { $periodTotalUV += $v; //如果uv总数大于20 if ($periodTotalUV > 20) { $uv20Time = $key; break; } } return $uv20Time; } /** * 新获取派单列表 * @param $bookId 推广书籍id * @param $distribution_channel_id 推广渠道id * @param $name 派单名称 * @param $bookName 书名 * @param $sendOrderId 派单id * @param string $start_date 开始时间 * @param string $end_date 结束时间 * @param string $isAll 是否获取所有 * @return mixed */ static function search($params, $isAll = false) { return SendOrder:: search($params, $isAll); } /* * 更新派单时间 */ static function updateSendOrderTime($send_order_id) { return SendOrder::where('id', $send_order_id)->update(['send_time' => date('Y-m-d H:i:s')]); /*$send_time = SendOrder::where('id',$send_order_id)->select('send_time')->first(); if($send_time && $send_time->send_time){ return true; }else{ return SendOrder::where('id',$send_order_id)->update(['send_time'=>date('Y-m-d H:i:s')]); }*/ } /** * 获取实际派单数 */ static function getRealSendOrderCount($distribution_channel_id = '', $date) { return SendOrder::getSendOrderCount($distribution_channel_id, $date); } static function getChannelPromotionBooks($distribution_channel_id = [], $endData, $book_name = '', $channel_name = '', $isAll = false) { $obj = SendOrder::select('send_orders.book_name', "companies.name as nickname", DB::raw("GROUP_CONCAT(distinct send_orders.distribution_channel_id) as distribution_channel_id"), DB::raw("count(*) as count")) ->join("distribution_channels", 'send_orders.distribution_channel_id', "=", "distribution_channels.id") ->join("channel_users", 'distribution_channels.channel_user_id', "=", "channel_users.id") ->join('companies', 'companies.id', "=", "channel_users.company_id") ->where("send_orders.created_at", "<=", $endData) ->groupBy('send_orders.book_name') ->groupBy('distribution_channels.channel_user_id'); if ($book_name) { $obj = $obj->where('send_orders.book_name', $book_name); } if ($channel_name) { $obj = $obj->where('companies.name', 'like', '%' . $channel_name . '%'); } if ($distribution_channel_id) { $obj = $obj->whereIn('send_orders.distribution_channel_id', $distribution_channel_id); } if ($isAll) { return $obj->get(); } else { return $obj->paginate(); } } static function getExtraStat($send_order_id) { return SendOrderExtraStat::getBySendOrderId($send_order_id); } static function getPeriodActualSendOrdersNum($channel_id,$start_time,$end_time) { return SendOrder::where([ ['distribution_channel_id','=',$channel_id], ['send_time','>=',$start_time], ['send_time','<=',$end_time], ])->count(); } static function getCompanyPromotionBooks($company_id,$start_time,$end_time) { $res = DB::select("select * from (select bcs.bid,bcs.book_name,count(so.id) as promotion_times from channel_users cu left join distribution_channels dc on dc.channel_user_id=cu.id left join send_orders so on so.distribution_channel_id=dc.id left join book_configs bcs on bcs.bid=so.book_id where cu.company_id=".$company_id." and so.book_id is not null and so.send_time between '".$start_time."' and '".$end_time."' group by so.book_id) tmp order by tmp.promotion_times desc"); return $res; } //成本统计 static function getCostStats($distribution_channels) { return SendOrder::whereIn('distribution_channel_id',$distribution_channels) ->where('is_enable',1) ->whereNotNull('send_time') ->sum('cost'); } }