Procházet zdrojové kódy

move merchant price to quality

stanley-king před 4 roky
rodič
revize
9133053ffc

+ 8 - 197
crontab/control/date.php

@@ -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;
-    }
 }

+ 1 - 0
data/model/merchant.model.php

@@ -26,6 +26,7 @@ class merchantModel extends Model
         return $result;
     }
 
+
     public function getPrices($mchid, $amount,$quality)
     {
         return $this->table('merchant_price')->where(['mchid' => $mchid, 'spec' => $amount , 'quality' => $quality])->select();

+ 1 - 0
docker/conf/crontab/root

@@ -6,6 +6,7 @@
 0	3	*	*	6	run-parts /etc/periodic/weekly
 0	5	1	*	*	run-parts /etc/periodic/monthly
 0   3   *   *   *   php /var/www/html/crontab/index.php date index
+0   4   *   *   *   php /var/www/html/crontab/index.php date forth_clock
 0   9   *   *   *   php /var/www/html/crontab/index.php date nine_clock
 0   10  *   *   *   php /var/www/html/crontab/index.php date ten_clock
 *    *   *   *   *   php /var/www/html/crontab/index.php minutes index

+ 2 - 1
helper/refill/LZRefillFactory.php

@@ -11,8 +11,9 @@ require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/quaility.php');
-require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/quality_ploy.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/merchant_price.php');
 
+require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/quality_ploy.php');
 
 use Log;
 use StatesHelper;

+ 2 - 0
helper/refill/XYZRefillFactory.php

@@ -13,6 +13,8 @@ require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/quaility.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/merchant_price.php');
+
 require_once(BASE_HELPER_PATH . '/refill/policy/xyz/quality_ploy.php');
 
 use Log;

+ 0 - 1
helper/refill/policy/mchctl.php

@@ -9,7 +9,6 @@ class mchctl
     public function __construct()
     {
         $this->load();
-
     }
 
     public function load()

+ 53 - 0
helper/refill/policy/merchant_price.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace refill;
+
+class merchant_price
+{
+    private $mPrices;
+
+    public function __construct()
+    {
+        $this->load();
+    }
+
+    public function load()
+    {
+        $i = 0;
+        while (true)
+        {
+            $start = $i * 1000;
+            $items = Model()->table('merchant_price')->field('*')->order('mprice_id asc')->limit("{$start},1000")->select();
+            if(empty($items)) {
+                return;
+            }
+            $i++;
+
+            foreach ($items as $item)
+            {
+                $card_types = $item['card_types'];
+                $price = ncPriceFormat($item['price']);
+                $mchid = intval($item['mchid']);
+                $spec = intval($item['spec']);
+                $quality = intval($item['quality']);
+
+                $types = explode(',',$card_types);
+                foreach ($types as $card_type) {
+                    $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
+                    $this->mPrices[$key] = $price;
+                }
+            }
+        }
+    }
+
+    public function price($mchid,$card_type,$spec,$quality)
+    {
+        $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
+        if(array_key_exists($key,$this->mPrices)) {
+            return $this->mPrices[$key];
+        }
+        else {
+            return false;
+        }
+    }
+}

+ 6 - 0
helper/refill/policy/xyz/policy.php

@@ -12,6 +12,7 @@ class policy extends ProviderManager implements IPolicy
     protected $mChannelControl;
     protected $mMchctl;
     protected $mQuality;
+    protected $mPrices;
 
     public function __construct()
     {
@@ -19,6 +20,7 @@ class policy extends ProviderManager implements IPolicy
         $this->mChannelControl = new chctl();
         $this->mMchctl = new mchctl();
         $this->mQuality = new quality_ploy();
+        $this->mPrices = new merchant_price();
     }
 
     public function load()
@@ -28,6 +30,7 @@ class policy extends ProviderManager implements IPolicy
         $this->mChannelControl->load();
         $this->mMchctl->load();
         $this->mQuality->load();
+        $this->mPrices->load();
     }
 
     public function find_providers(int $spec, int $card_type,int $quality): array
@@ -69,6 +72,9 @@ class policy extends ProviderManager implements IPolicy
 
         foreach ($qualities as $quality)
         {
+            $price = $this->mPrices->price($mchid,$card_type,$spec,$quality);
+            if($price === false) continue;
+
             [$names,$overload] = $this->find_providers($spec,$card_type,$quality);
             if($overload) {
                 Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);

+ 5 - 0
test/TestRefill.php

@@ -47,6 +47,11 @@ class TestRefill extends TestCase
         refill\RefillFactory::instance();
     }
 
+    public function testMerchantPrice()
+    {
+        $price = new refill\merchant_price();
+    }
+
     public function testCallBack()
     {