|
@@ -15,6 +15,8 @@ require_once(BASE_ROOT_PATH . '/helper/notify_helper.php');
|
|
|
require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
|
|
|
require_once(BASE_ROOT_PATH . '/helper/bonus_helper.php');
|
|
|
require_once(BASE_DATA_PATH . '/mobile/omsid.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/stat_helper.php');
|
|
|
+
|
|
|
|
|
|
class dateControl extends BaseCronControl
|
|
|
{
|
|
@@ -101,6 +103,12 @@ class dateControl extends BaseCronControl
|
|
|
stat_helper::onDaiyBehavior(time() - 86400);
|
|
|
}
|
|
|
|
|
|
+ public function forth_clockOp()
|
|
|
+ {
|
|
|
+ $refill = new statistics\stat_refill();
|
|
|
+ $refill->run();
|
|
|
+ }
|
|
|
+
|
|
|
public function nine_clockOp()
|
|
|
{
|
|
|
//订单自动完成
|
|
@@ -1151,201 +1159,4 @@ class dateControl extends BaseCronControl
|
|
|
}
|
|
|
return $datas;
|
|
|
}
|
|
|
-
|
|
|
- //订单系统,通道,商户订单统计.
|
|
|
- public function _order_stats()
|
|
|
- {
|
|
|
- $this->system_order_stats();
|
|
|
- $this->provider_order_stats();
|
|
|
- $this->merchant_order_stats();
|
|
|
- }
|
|
|
-
|
|
|
- private function day_order_stats($type , $condition , $start_time)
|
|
|
- {
|
|
|
- if($start_time == 0) {
|
|
|
- $start_time = strtotime(date("Y-m-d" , strtotime("-1 day")));
|
|
|
- }
|
|
|
- $stats = Model('')->table('refill_stats')->where($condition)->find();
|
|
|
-
|
|
|
- $end_time = $start_time + 3600*24;
|
|
|
- $condition['refill_order.order_time'] = [ ['egt', $start_time] , ['lt', $end_time] , 'and'];
|
|
|
- $condition['inner_status'] = 0;
|
|
|
-
|
|
|
- $counts = Model('')->table('refill_order,vr_order')->join('inner')
|
|
|
- ->on('refill_order.order_id=vr_order.order_id')
|
|
|
- ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts, order_state')
|
|
|
- ->where($condition)
|
|
|
- ->group('order_state')
|
|
|
- ->select();
|
|
|
-
|
|
|
- $cancel_count = $success_count = $order_count = 0;
|
|
|
- $success_refill_amounts = $success_channel_amounts = $success_mch_amounts = $profit_amounts = 0;
|
|
|
- foreach ($counts as $count)
|
|
|
- {
|
|
|
- if ($count['order_state'] == ORDER_STATE_SUCCESS) {
|
|
|
- $success_refill_amounts = $count['refill_amounts'];
|
|
|
- $success_channel_amounts = $count['channel_amounts'];
|
|
|
- $success_mch_amounts = $count['mch_amounts'];
|
|
|
- $success_count = $count['order_count'];
|
|
|
- $profit_amounts = ncPriceFormat($success_mch_amounts - $success_channel_amounts);
|
|
|
- } elseif ($count['order_state'] == ORDER_STATE_CANCEL) {
|
|
|
- $cancel_count = $count['order_count'];
|
|
|
- }
|
|
|
-
|
|
|
- $order_count += $count['order_count'];
|
|
|
- }
|
|
|
-
|
|
|
- $params['time_text'] = date("Y-m-d" , $start_time);
|
|
|
- $params['time_stamp'] = $start_time;
|
|
|
- $params['success_count'] = $success_count;
|
|
|
- $params['success_refill_amounts'] = $success_refill_amounts;
|
|
|
- $params['success_channel_amounts'] = $success_channel_amounts;
|
|
|
- $params['success_mch_amounts'] = $success_mch_amounts;
|
|
|
- $params['profit_amounts'] = $profit_amounts;
|
|
|
- $params['order_count'] = $order_count;
|
|
|
- $params['cancel_count'] = $cancel_count;
|
|
|
- if($order_count == 0) {
|
|
|
- $params['success_ratio'] = '0%';
|
|
|
- }else{
|
|
|
- $params['success_ratio'] = ncPriceFormat($success_count / $order_count) * 100 . '%';
|
|
|
- }
|
|
|
-
|
|
|
- return $params;
|
|
|
- }
|
|
|
-
|
|
|
- private function system_order_stats()
|
|
|
- {
|
|
|
- $type = 'system';
|
|
|
- $start_time = strtotime(date("Y-m-d" , strtotime("-1 day")));
|
|
|
-
|
|
|
- $system_stats = function($params , $type){
|
|
|
- $params['type'] = $type;
|
|
|
- $params['cid'] = 0;
|
|
|
- $params['cname'] = $type;
|
|
|
- $success_refill_amounts = $params['success_refill_amounts'];
|
|
|
- if($success_refill_amounts > 0 && $success_refill_amounts <= 15000000) {
|
|
|
- $params['service_amounts'] = ncPriceFormat($params['success_refill_amounts'] * 0.001);
|
|
|
- }elseif ($success_refill_amounts > 15000000 && $success_refill_amounts <= 30000000) {
|
|
|
- $params['service_amounts'] = 15000;
|
|
|
- }else{
|
|
|
- $params['service_amounts'] = ncPriceFormat($params['success_refill_amounts'] * 0.0005);
|
|
|
- }
|
|
|
- Model('')->table('refill_stats')->insert($params);
|
|
|
- };
|
|
|
-
|
|
|
- $need_init = $this->check_stats($type);
|
|
|
-
|
|
|
- if($need_init == false){
|
|
|
- $stats = Model('')->table('refill_stats')->where(['type' => $type , 'time_stamp' => $start_time])->find();
|
|
|
- if(empty($stats)) {
|
|
|
- $params = $this->day_order_stats($type , [] , $start_time);
|
|
|
- $system_stats($params,$type);
|
|
|
- }
|
|
|
- }else{
|
|
|
- Model('')->table('refill_stats')->where(['type' => $type])->delete();
|
|
|
- foreach ($need_init as $date) {
|
|
|
- $params = $this->day_order_stats($type , [] , strtotime($date));
|
|
|
- $system_stats($params,$type);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function provider_order_stats()
|
|
|
- {
|
|
|
- $type = 'provider';
|
|
|
-
|
|
|
- $provider_list = Model('')->table('refill_provider,store')->field('refill_provider.store_id,store.store_name')->join('inner')
|
|
|
- ->on('store.store_id=refill_provider.store_id')->limit(100)->select();
|
|
|
- if(empty($provider_list)) {
|
|
|
- return ;
|
|
|
- }
|
|
|
- $start_time = strtotime(date("Y-m-d" , strtotime("-1 day")));
|
|
|
-
|
|
|
- $provider_stats = function($params , $type , $provider){
|
|
|
- $params['type'] = $type;
|
|
|
- $params['cid'] = $provider['store_id'];
|
|
|
- $params['cname'] = $provider['store_name'];
|
|
|
- $params['service_amounts'] = 0;
|
|
|
- return $params;
|
|
|
- };
|
|
|
- $insert = [];
|
|
|
- $need_init = $this->check_stats($type);
|
|
|
-
|
|
|
- foreach ($provider_list as $provider) {
|
|
|
- $store_id = $provider['store_id'];
|
|
|
- $condition['store_id'] = $store_id;
|
|
|
- if($need_init == false){
|
|
|
- $stats = Model('')->table('refill_stats')->where(['type' => $type , 'time_stamp' => $start_time , 'cid' => $store_id])->find();
|
|
|
- if(empty($stats)) {
|
|
|
- $params = $this->day_order_stats($type , $condition , $start_time);
|
|
|
- $insert[] = $provider_stats($params , $type , $provider);
|
|
|
- }
|
|
|
- }else {
|
|
|
- Model('')->table('refill_stats')->where(['type' => $type])->delete();
|
|
|
- foreach ($need_init as $date) {
|
|
|
- $params = $this->day_order_stats($type , $condition , strtotime($date));
|
|
|
- $insert[] = $provider_stats($params, $type , $provider);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Model('')->table('refill_stats')->insertAll($insert);
|
|
|
- }
|
|
|
-
|
|
|
- private function merchant_order_stats()
|
|
|
- {
|
|
|
- $type = 'merchant';
|
|
|
- $merchant_list = Model('')->table('merchant')->limit(100)->select();
|
|
|
- if(empty($merchant_list)) {
|
|
|
- return ;
|
|
|
- }
|
|
|
- $start_time = strtotime(date("Y-m-d" , strtotime("-1 day")));
|
|
|
-
|
|
|
- $merchant_stats = function($params , $type , $merchant){
|
|
|
- $params['type'] = $type;
|
|
|
- $params['cid'] = $merchant['mchid'];
|
|
|
- $params['cname'] = $merchant['company_name'] == '' ? $merchant['name'] : $merchant['company_name'];
|
|
|
- $params['service_amounts'] = 0;
|
|
|
- return $params;
|
|
|
- };
|
|
|
- $insert = [];
|
|
|
- $need_init = $this->check_stats($type);
|
|
|
-
|
|
|
- foreach ($merchant_list as $merchant) {
|
|
|
- $mchid = $merchant['mchid'];
|
|
|
- $condition['mchid'] = $mchid;
|
|
|
- if($need_init == false){
|
|
|
- $stats = Model('')->table('refill_stats')->where(['type' => $type , 'time_stamp' => $start_time , 'cid' => $mchid])->find();
|
|
|
- if(empty($stats)) {
|
|
|
- $params = $this->day_order_stats($type , $condition , $start_time);
|
|
|
- $insert[] = $merchant_stats($params , $type , $merchant);
|
|
|
- }
|
|
|
- }else{
|
|
|
- Model('')->table('refill_stats')->where(['type' => $type])->delete();
|
|
|
- foreach ($need_init as $date) {
|
|
|
- $params = $this->day_order_stats($type , $condition , strtotime($date));
|
|
|
- $insert[] = $merchant_stats($params , $type , $merchant);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Model('')->table('refill_stats')->insertAll($insert);
|
|
|
- }
|
|
|
-
|
|
|
- //检测前天是否有统计
|
|
|
- public function check_stats($type)
|
|
|
- {
|
|
|
- $date = strtotime(date("Y-m-d" , strtotime("-2 day")));
|
|
|
- $condition['type'] = $type;
|
|
|
- $condition['time_stamp'] = $date;
|
|
|
- $stats = Model('')->table('refill_stats')->where($condition)->find();
|
|
|
- if(empty($stats)) {
|
|
|
- $first_order = Model('')->table('refill_order')->order('order_time asc')->find();
|
|
|
- $days = (strtotime(date("Y-m-d")) - strtotime(date("Y-m-d" , $first_order['order_time']))) / (3600 * 24);
|
|
|
- for ($i = $days; $i > 0; $i--) {
|
|
|
- $dates[] = date("Y-m-d" , strtotime("-{$i}day"));
|
|
|
- }
|
|
|
- return $dates;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|