123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- <?php
- namespace App\Modules\SendOrder\Services;
- use App\Modules\SendOrder\Models\SendOrder;
- use App\Modules\SendOrder\Models\SendOrderExtraStat;
- use App\Modules\Statistic\Services\WapVisitStatService;
- use DB;
- use Redis;
- class SendOrderService
- {
- static function searchForDaliy($params, $isAll = false)
- {
- return SendOrder::searchForDaliy($params, $isAll);
- }
-
- static function updateRemark($id, $distribution_channel_id, $remark)
- {
- return SendOrder::updateRemark($id, $distribution_channel_id, $remark);
- }
-
- static function updateStarNum($id, $distribution_channel_id, $starNum)
- {
- return SendOrder::updateStarNum($id, $distribution_channel_id, $starNum);
- }
-
- static function updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark)
- {
- return SendOrder::updateStarNumAndRemark($id, $distribution_channel_id, $starNum, $remark);
- }
-
- static function updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter = [])
- {
- return SendOrder::updateSendOrderInfo($id, $distribution_channel_id, $name, $pre_send_date, $channel_type, $cost, $promotion_type, $subscribe_chapter);
- }
-
- static function getPromotionCountByBid($bid, $channelId)
- {
- return SendOrder::getPromotionCountByBid($bid, $channelId);
- }
-
- static function getPromotionCountByChannelId($channelId)
- {
- return SendOrder::getPromotionCountByChannelId($channelId);
- }
-
- static function getChannelPromotionCount($channelId, $begin_time, $end_time)
- {
- return SendOrder::getChannelPromotionCount($channelId, $begin_time, $end_time);
- }
-
- static function getChannelRealPromotionCount($channelId, $begin_time, $end_time)
- {
- return SendOrder::getChannelRealPromotionCount($channelId, $begin_time, $end_time);
- }
-
- static function getRealPromotionCount($params)
- {
- return SendOrder::getRealPromotionCount($params);
- }
-
- static function getPromotionCount($params)
- {
- return SendOrder::getPromotionCount($params);
- }
-
- static function getTotalPromotionCountByChannelIds($channelIds)
- {
- return SendOrder::getTotalPromotionCountByChannelIds($channelIds);
- }
-
- static function getDuraingPromotionCountByChannelId($channelId, $start_time = '', $end_time = '')
- {
- return SendOrder::getDuraingPromotionCountByChannelId($channelId, $start_time, $end_time);
- }
-
- static function getSendOrders($bookId, $distribution_channel_id, $name = null, $bookName = null, $sendOrderId, $start_time = '', $end_time = '', $isAll = false)
- {
- return SendOrder::getSendOrders($bookId, $distribution_channel_id, $name, $bookName, $sendOrderId, $start_time, $end_time, $isAll);
- }
-
- static function getManageSendOrders($params = [], $is_all = false)
- {
- return SendOrder::getManageSendOrders($params, $is_all);
- }
-
- static function createFromChapter($data)
- {
- return SendOrder::createFromChapter($data);
- }
-
- static function createFromPage($data)
- {
- return SendOrder::createFromPage($data);
- }
-
- static function createFromDirectory($data)
- {
- return SendOrder::createFromDirectory($data);
- }
-
- static function getPv($id)
- {
- return WapVisitStatService::getSendOrderTotalPv($id);
-
- }
-
- static function getNewFansNum($send_order_id)
- {
- return DB::table('force_subscribe_users')
- ->where('send_order_id', $send_order_id)
- ->count();
- }
- static function getBrowserUvAndPv($id)
- {
- return WapVisitStatService::getBrowserSendOrderTotalPvAndUv($id);
- }
-
- static function getUv($id)
- {
- return WapVisitStatService::getSendOrderTotalUv($id);
-
- }
-
- static function getUvInfo($id)
- {
- return WapVisitStatService::getSendOrderUv($id);
-
- }
-
- static function getPvInfo($id)
- {
- return WapVisitStatService::getSendOrderPv($id);
-
- }
-
- static function removeSendOrder($id, $distribution_channel_id)
- {
- return SendOrder::removeSendOrder($id, $distribution_channel_id);
- }
-
- static function getRedirectUrlById($id)
- {
- return SendOrder::where('id', $id)->select('redirect_url', 'book_id', 'send_time', 'distribution_channel_id', 'name', 'promotion_point')->first();
- }
-
- static function getById($id)
- {
- return SendOrder::find($id);
- }
-
- static function 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');
- }
-
- 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();
- }
-
- static function getContinueTotalReadUv($send_order_id)
- {
- return (float) Redis::hget('send_order:continue:' . $send_order_id, 'total');
- }
-
- static function setSendOrderCost($id, $distribution_channel_id, $cost)
- {
- return SendOrder::setSendOrderCost($id, $distribution_channel_id, $cost);
- }
-
- static function getFirstChargeUserNum($id)
- {
- return SendOrder::getFirstChargeUserNum($id);
- }
-
- static function getRepetitiousChargeUserNum($id)
- {
- return SendOrder::getRepetitiousChargeUserNum($id);
- }
-
- 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;
-
- if ($periodTotalUV > 20) {
- $uv20Time = $key;
- break;
- }
- }
- return $uv20Time;
- }
-
- 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')]);
-
- }
-
- 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');
- }
-
- static function searchForDaily($params, $isAll = false)
- {
- return SendOrder::searchForDaily($params, $isAll);
- }
-
- static function getBookdSendNum($start_date,$end_date)
- {
- return SendOrder::getBookdSendNum($start_date,$end_date);
- }
- }
|