|
@@ -28,13 +28,13 @@ class Order extends Model
|
|
|
if (isset($params['status']) && $params['status']) $search_obj->where('status', $params['status']);
|
|
|
if (isset($params['activity_id']) && count($params['activity_id']) > 0) $search_obj->whereIn('activity_id', $params['activity_id']);
|
|
|
if (isset($params['from_type']) && $params['from_type']) $search_obj->where('from_type', $params['from_type']);
|
|
|
- /*\Log::info('filter_:'.json_encode($params));
|
|
|
- \Log::info(json_encode($search_obj));
|
|
|
- \Log::info('my_sql:'.($search_obj->toSql()));*/
|
|
|
+ /*\Log::info('filter_:'.json_encode($params));
|
|
|
+ \Log::info(json_encode($search_obj));
|
|
|
+ \Log::info('my_sql:'.($search_obj->toSql()));*/
|
|
|
// \Log::info('my_sql:'.($search_obj->toSql()));
|
|
|
- if(isset($params['created_at']) && $params['created_at'] ) {
|
|
|
- \Log::info('created_at--:'.date('Y-m-d 00:00:00',strtotime($params['created_at'])));
|
|
|
- $search_obj->whereBetween('orders.created_at',[date('Y-m-d 00:00:00',strtotime($params['created_at'])),date('Y-m-d 23:59:59',strtotime($params['created_at']))]);
|
|
|
+ if (isset($params['created_at']) && $params['created_at']) {
|
|
|
+ \Log::info('created_at--:' . date('Y-m-d 00:00:00', strtotime($params['created_at'])));
|
|
|
+ $search_obj->whereBetween('orders.created_at', [date('Y-m-d 00:00:00', strtotime($params['created_at'])), date('Y-m-d 23:59:59', strtotime($params['created_at']))]);
|
|
|
}
|
|
|
if ($is_all) {
|
|
|
return $search_obj->get();
|
|
@@ -87,7 +87,7 @@ class Order extends Model
|
|
|
static function getChannelToday($distribution_channel_id)
|
|
|
{
|
|
|
$begin_time = date('Y-m-d');
|
|
|
- $end_time = date("Y-m-d", strtotime($begin_time) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($begin_time) + 86400);
|
|
|
return self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_number")])
|
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
@@ -100,8 +100,8 @@ class Order extends Model
|
|
|
static function getChannelTodayData($distribution_channel_id)
|
|
|
{
|
|
|
$begin_time = date('Y-m-d');
|
|
|
- $end_time = date('Y-m-d', strtotime($begin_time) + 86400);
|
|
|
- $paid_info = self::select([DB::Raw("order_type,sum(price) as success_amount,count(1) as paid_num")])
|
|
|
+ $end_time = date('Y-m-d', strtotime($begin_time) + 86400);
|
|
|
+ $paid_info = self::select([DB::Raw("order_type,sum(price) as success_amount,count(1) as paid_num")])
|
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -120,31 +120,31 @@ class Order extends Model
|
|
|
->toArray();
|
|
|
|
|
|
$ret = [
|
|
|
- 'amount' => 0,
|
|
|
- 'paid_num' => 0,
|
|
|
+ 'amount' => 0,
|
|
|
+ 'paid_num' => 0,
|
|
|
'total_order_num' => 0,
|
|
|
|
|
|
- 'recharge_unpaid_number' => 0,
|
|
|
- 'recharge_paid_number' => 0,
|
|
|
+ 'recharge_unpaid_number' => 0,
|
|
|
+ 'recharge_paid_number' => 0,
|
|
|
'recharge_success_amount' => 0,
|
|
|
|
|
|
- 'year_unpaid_number' => 0,
|
|
|
- 'year_paid_number' => 0,
|
|
|
+ 'year_unpaid_number' => 0,
|
|
|
+ 'year_paid_number' => 0,
|
|
|
'year_success_amount' => 0
|
|
|
|
|
|
];
|
|
|
foreach ($paid_info as $item) {
|
|
|
- $ret['amount'] += $item['success_amount'];
|
|
|
- $ret['paid_num'] += $item['paid_num'];
|
|
|
+ $ret['amount'] += $item['success_amount'];
|
|
|
+ $ret['paid_num'] += $item['paid_num'];
|
|
|
$ret['total_order_num'] += $item['paid_num'];
|
|
|
|
|
|
if ($item['order_type'] == 'RECHARGE') {
|
|
|
- $ret['recharge_paid_number'] += $item['paid_num'];
|
|
|
+ $ret['recharge_paid_number'] += $item['paid_num'];
|
|
|
$ret['recharge_success_amount'] += $item['success_amount'];
|
|
|
}
|
|
|
|
|
|
if ($item['order_type'] == 'YEAR') {
|
|
|
- $ret['year_paid_number'] += $item['paid_num'];
|
|
|
+ $ret['year_paid_number'] += $item['paid_num'];
|
|
|
$ret['year_success_amount'] += $item['success_amount'];
|
|
|
}
|
|
|
}
|
|
@@ -162,7 +162,7 @@ class Order extends Model
|
|
|
static function getChannelDateOrderInfo($distribution_channel_id, $date)
|
|
|
{
|
|
|
$begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($begin_time) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($begin_time) + 86400);
|
|
|
return self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_number")])
|
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
@@ -222,11 +222,12 @@ class Order extends Model
|
|
|
if (isset($params['distribution_channel_id']) && $params['distribution_channel_id']) $search_obj->where('distribution_channel_id', $params['distribution_channel_id']);
|
|
|
return $search_obj->count();
|
|
|
}
|
|
|
- static function getByTradeNo($distribution_channel_id,$trade_no)
|
|
|
- {
|
|
|
- return self::where('distribution_channel_id', $distribution_channel_id)->where('trade_no', $trade_no)->first();
|
|
|
+
|
|
|
+ static function getByTradeNo($distribution_channel_id, $trade_no)
|
|
|
+ {
|
|
|
+ return self::where('distribution_channel_id', $distribution_channel_id)->where('trade_no', $trade_no)->first();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//获取派单下的普通用户订单总数
|
|
|
static function getNormalOrderCount($send_order_id)
|
|
|
{
|
|
@@ -243,7 +244,7 @@ class Order extends Model
|
|
|
static function getDayPayUserNumByChannelId($distribution_channel_id, $date)
|
|
|
{
|
|
|
$begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
return self::where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -258,7 +259,7 @@ class Order extends Model
|
|
|
static function getDayVipPayUserNumByChannelId($distribution_channel_id, $date)
|
|
|
{
|
|
|
$begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
return self::where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -272,7 +273,7 @@ class Order extends Model
|
|
|
static function getDayRechargePayUserNumByChannelId($distribution_channel_id, $date)
|
|
|
{
|
|
|
$begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
return self::where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -285,9 +286,9 @@ class Order extends Model
|
|
|
//获取指定日期普通充值未支付订单数、支付订单数、总额
|
|
|
static function getChannelDayTicketRechargeData($distribution_channel_id, $date)
|
|
|
{
|
|
|
- $begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
- $paid_info = self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_num")])
|
|
|
+ $begin_time = $date;
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $paid_info = self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_num")])
|
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -302,8 +303,8 @@ class Order extends Model
|
|
|
->count();
|
|
|
|
|
|
return [
|
|
|
- 'ticket_recharge_paid_num' => $paid_info->paid_num,
|
|
|
- 'ticket_recharge_amount' => (float)$paid_info->success_amount,
|
|
|
+ 'ticket_recharge_paid_num' => $paid_info->paid_num,
|
|
|
+ 'ticket_recharge_amount' => (float)$paid_info->success_amount,
|
|
|
'ticket_recharge_unpaid_num' => $unpaid_count
|
|
|
];
|
|
|
}
|
|
@@ -311,9 +312,9 @@ class Order extends Model
|
|
|
//获取指定日期包年充值未支付订单数、支付订单数、总额
|
|
|
static function getChannelDayYearRechargeData($distribution_channel_id, $date)
|
|
|
{
|
|
|
- $begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
- $paid_info = self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_num")])
|
|
|
+ $begin_time = $date;
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $paid_info = self::select([DB::Raw("sum(price) as success_amount,count(1) as paid_num")])
|
|
|
->where('distribution_channel_id', $distribution_channel_id)
|
|
|
->where('created_at', '>=', $begin_time)
|
|
|
->where('created_at', '<', $end_time)
|
|
@@ -327,8 +328,8 @@ class Order extends Model
|
|
|
->where('status', 'UNPAID')
|
|
|
->count();
|
|
|
return [
|
|
|
- 'year_recharge_paid_num' => $paid_info->paid_num,
|
|
|
- 'year_recharge_amount' => (float)$paid_info->success_amount,
|
|
|
+ 'year_recharge_paid_num' => $paid_info->paid_num,
|
|
|
+ 'year_recharge_amount' => (float)$paid_info->success_amount,
|
|
|
'year_recharge_unpaid_num' => $unpaid_count
|
|
|
];
|
|
|
}
|
|
@@ -337,11 +338,11 @@ class Order extends Model
|
|
|
static function getChannelDayFirstRechargeData($distribution_channel_id, $date)
|
|
|
{
|
|
|
$begin_time = $date;
|
|
|
- $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
+ $end_time = date("Y-m-d", strtotime($date) + 86400);
|
|
|
$first_data = DB::select("select count(distinct uid) count,sum(price) amount from orders a where distribution_channel_id = {$distribution_channel_id} and created_at>'{$begin_time}' and created_at<'{$end_time}' and status ='PAID' and not exists (select uid from orders where a.uid = uid and created_at < '{$begin_time}' and status= 'PAID' and distribution_channel_id = {$distribution_channel_id} limit 1)");
|
|
|
|
|
|
return [
|
|
|
- "count" => (int)$first_data[0]->count,
|
|
|
+ "count" => (int)$first_data[0]->count,
|
|
|
"amount" => (float)$first_data[0]->amount
|
|
|
];
|
|
|
}
|
|
@@ -350,7 +351,7 @@ class Order extends Model
|
|
|
static function getPromotionRegUserRechargeAmount($params = [])
|
|
|
{
|
|
|
$send_order_id = isset($params['send_order_id']) ? $params['send_order_id'] : 0;
|
|
|
- $end_time = isset($params['end_time']) ? $params['end_time'] : date('Y-m-d H:i:s');
|
|
|
+ $end_time = isset($params['end_time']) ? $params['end_time'] : date('Y-m-d H:i:s');
|
|
|
if ($send_order_id) {
|
|
|
$data = DB::select("select sum(price) amount from orders where status='PAID' and created_at <= '{$end_time}' and uid in (select id from users where send_order_id = '{$send_order_id}' )");
|
|
|
return (float)$data[0]->amount;
|
|
@@ -370,7 +371,7 @@ class Order extends Model
|
|
|
|
|
|
$search_obj->where('orders.status', 'PAID');
|
|
|
|
|
|
- $data = $search_obj->select(DB::raw('sum(orders.price) as recharge_amount'), 'official_accounts.nickname', 'official_accounts.appid', 'orders.distribution_channel_id')->get()->toArray();
|
|
|
+ $data = $search_obj->select(DB::raw('sum(orders.price) as recharge_amount'), 'official_accounts.nickname', 'official_accounts.appid', 'orders.distribution_channel_id')->get()->toArray();
|
|
|
$chanenelRechargeAmount = [];
|
|
|
foreach ($data as $item) {
|
|
|
$distribution_channel_id = $item['distribution_channel_id'];
|
|
@@ -381,7 +382,7 @@ class Order extends Model
|
|
|
}
|
|
|
|
|
|
foreach ($data as &$dataItem) {
|
|
|
- $dataItem['date'] = $date;
|
|
|
+ $dataItem['date'] = $date;
|
|
|
$dataItem['created_at'] = date('Y-m-d H:i:s');
|
|
|
$dataItem['updated_at'] = date('Y-m-d H:i:s');
|
|
|
foreach ($chanenelRechargeAmount as $key => $chanenelRechargeAmountItem) {
|
|
@@ -405,11 +406,11 @@ class Order extends Model
|
|
|
$result = $search_obj->get();
|
|
|
|
|
|
$official_accounts_result = DB::table('official_accounts')->select('appid', 'nickname')->get();
|
|
|
- $temp_official_account = [];
|
|
|
+ $temp_official_account = [];
|
|
|
foreach ($official_accounts_result as $official_accounts_result_item) {
|
|
|
$temp_official_account[$official_accounts_result_item->appid] = $official_accounts_result_item->nickname;
|
|
|
}
|
|
|
- $temp_channel = [];
|
|
|
+ $temp_channel = [];
|
|
|
$temp_channel_charge_amount = [];
|
|
|
foreach ($result as $item) {
|
|
|
if (!isset($temp_channel[$item->distribution_channel_id])) {
|
|
@@ -424,9 +425,9 @@ class Order extends Model
|
|
|
if (!$force_subscribe_users_result) {
|
|
|
$force_subscribe_users_result = DB::table('force_subscribe_users')->where('uid', $item->uid)->where('is_subscribed', 0)->select('appid', 'distribution_channel_id')->first();
|
|
|
}
|
|
|
- if($force_subscribe_users_result){
|
|
|
+ if ($force_subscribe_users_result) {
|
|
|
$temp_channel[$item->distribution_channel_id][$force_subscribe_users_result->appid][] = $item->price;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$temp_channel[$item->distribution_channel_id]['unknown'][] = $item->price;
|
|
|
}
|
|
|
$temp_channel_charge_amount[$item->distribution_channel_id] += $item->price;
|
|
@@ -435,17 +436,28 @@ class Order extends Model
|
|
|
$finalArray = [];
|
|
|
foreach ($temp_channel as $key => $temp_channel_item) {
|
|
|
foreach ($temp_channel_item as $appid => $price) {
|
|
|
- $finalArray[] = ['date' => $date,
|
|
|
- 'nickname' => isset($temp_official_account[$appid])?$temp_official_account[$appid]:'unknown',
|
|
|
- 'appid' => $appid,
|
|
|
- 'distribution_channel_id' => $key,
|
|
|
- 'recharge_amount' => array_sum($price),
|
|
|
- 'channel_recharge_amount' => $temp_channel_charge_amount[$key],
|
|
|
- 'created_at' => date('Y-m-d H:i:s'),
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')];
|
|
|
+ $finalArray[] = ['date' => $date,
|
|
|
+ 'nickname' => isset($temp_official_account[$appid]) ? $temp_official_account[$appid] : 'unknown',
|
|
|
+ 'appid' => $appid,
|
|
|
+ 'distribution_channel_id' => $key,
|
|
|
+ 'recharge_amount' => array_sum($price),
|
|
|
+ 'channel_recharge_amount' => $temp_channel_charge_amount[$key],
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $finalArray;
|
|
|
}
|
|
|
+
|
|
|
+ public static function getOrdersByActivityId($channelId, $createdAt, $activityId)
|
|
|
+ {
|
|
|
+ $result = self::select('uid', 'status', 'price', 'activity_id', 'product_id')
|
|
|
+ ->where('distribution_channel_id', $channelId)
|
|
|
+ ->where('created_at', '>=', $createdAt)
|
|
|
+ ->where('activity_id', $activityId)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ return $result ? $result->toArray() : [];
|
|
|
+ }
|
|
|
}
|