stanley-king il y a 2 ans
Parent
commit
72a98d1c34

+ 1 - 0
docker/compose/workcuda/acc/docker-compose.yml

@@ -10,6 +10,7 @@ services:
       - ../conf/etc/localtime:/etc/localtime:ro
       - ../conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
       - /mnt/upload:/var/www/html/data/upload
+      - /mnt/merchant:/var/www/html/merchant
     container_name: "panda-nginx"
     command: [nginx,'-g','daemon off;']
     extra_hosts:

+ 1 - 1
docker/compose/workcuda/conf/php/php.ini

@@ -1947,6 +1947,6 @@ xdebug.remote_enable=1
 xdebug.remote_handler=dbgp
 xdebug.remote_host=192.168.3.220
 xdebug.remote_port=9300
-xdebug.remote_mode=jit
+xdebug.remote_mode=req
 xdebug.remote_autostart=1
 xdebug.idekey=PHPSTORM

+ 15 - 0
helper/queue/iqueue.php

@@ -148,6 +148,21 @@ class IClient
     }
 }
 
+class IJsonClient
+{
+    private $mQueuedb;
+
+    public function __construct($queueDb)
+    {
+        $this->mQueuedb = $queueDb;
+    }
+
+    public function push($key, $value)
+    {
+        return $this->mQueuedb->lpush(json_encode(['method' => $key, 'params' => $value]));
+    }
+}
+
 class IServer
 {
     private $_queuedb;

+ 67 - 0
helper/queue/monitor.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace queue;
+
+use queue\DispatcherClient;
+use queue\DispatcherDB;
+use queue\IClient;
+
+class MonitorDB extends IQueueDB
+{
+    public function __construct()
+    {
+        parent::__construct('REFILL_MONITOR_QUEUE');
+    }
+}
+
+class MonitorClient extends IJsonClient
+{
+    private static $stInstance = null;
+
+    public static function instance()
+    {
+        if (self::$stInstance == null) {
+            self::$stInstance = new MonitorClient();
+        }
+
+        return self::$stInstance;
+    }
+
+    public function __construct()
+    {
+        $db = new MonitorDB();
+        parent::__construct($db);
+    }
+
+    public function onSubmit($mchid,$time,$mch_amount)
+    {
+        $params = ['mchid' => $mchid,'time' => $time,'mch_amount' => $mch_amount];
+        $this->push('refill_submit',$params);
+    }
+
+    public function onCallback($mchid,$time,$mch_amount,$channel_amount,$succ)
+    {
+        $params = ['mchid' => $mchid,'time' => $time,'mch_amount' => $mch_amount,'channel_amount' => $channel_amount];
+        if($succ) {
+            $this->push('refill_succ',$params);
+        } else {
+            $this->push('refill_fail',$params);
+        }
+    }
+
+    public function onNetError($chname,$time)
+    {
+        $params = ['channel_name' => $chname,'time' => $time];
+        $this->push('channel_neterr',$params);
+    }
+
+    public function onNotify($chname,$time,$spec,$card_type,$period,$succ)
+    {
+        $params = ['channel_name' => $chname,'time' => $time,'spec' => $spec,'card_type' => $card_type,'period' => $period];
+        if ($succ) {
+            $this->push('notify_succ', $params);
+        } else {
+            $this->push('notify_fail', $params);
+        }
+    }
+}

+ 26 - 0
helper/refill/RefillBase.php

@@ -15,6 +15,7 @@ require_once(BASE_HELPER_PATH . '/refill/util.php');
 require_once(BASE_HELPER_PATH . '/refill/errcode.php');
 
 use Log;
+use refill\afd\config;
 use scope_trace;
 use mtopcard;
 use QueueClient;
@@ -126,6 +127,9 @@ class RefillBase
             $mchid = intval($refill_info['mchid']);
             $mch_order = $refill_info['mch_order'];
 
+            $period = time() - intval($refill_info['commit_time']);
+            util::monitor_notify($chname,$spec,$card_type,$period,$success);
+
             if ($success) {
                 $logic_vr_order->changeOrderStateSuccess($order_id,true);
                 $tran->commit();
@@ -133,6 +137,7 @@ class RefillBase
                 util::incr_notify($chname, $card_type, $spec, $quality, true);
                 util::incr_user_success($mchid,$card_type, $spec,$quality);
                 util::onOrderSuccess($refill_info,$order_info);
+                util::monitor_callback($mchid, $refill_info['mch_amount'], $refill_info['channel_amount'], true);
             }
             elseif ($can_try)
             {
@@ -151,6 +156,7 @@ class RefillBase
                     }
                 }
                 util::incr_user_fail($mchid,$card_type, $spec,$quality);
+                util::monitor_callback($mchid, $refill_info['mch_amount'], 0, false);
             }
             else {
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.",true,true);
@@ -159,6 +165,7 @@ class RefillBase
                 util::incr_notify($chname, $card_type, $spec, $quality, false);
                 util::incr_amount_lock($mchid,$card_type,$spec);
                 util::incr_user_fail($mchid,$card_type, $spec,$quality);
+                util::monitor_callback($mchid, $refill_info['mch_amount'], 0, false);
             }
 
             $mod_refill->edit($order_id, ['notify_time' => time(), 'is_retrying' => 0,'notify_state' => 1]);
@@ -300,6 +307,23 @@ class RefillBase
         }
     }
 
+    public function mch_amount(order $order)
+    {
+        $mchid = $order->mchid();
+        $org_quality = $order->org_quality();
+
+        if(PolicyUtil::mixed_quality($org_quality)) {
+            $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$org_quality,$this->mPolicy,$order->thrid_params());
+        }
+        else {
+            $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$order->cur_quality(),$this->mPolicy,$order->thrid_params());
+        }
+        $mch_price = $calc->calc_vgoods_price([]);
+        $mch_amount = $mch_price * $order->quantity();
+
+        return $mch_amount;
+    }
+
     //返回值:[ 错误码,错误信息,订单ID,是否是网络错误]
     //说明:错误码为true 表示成功
     //     其它情况,则需要判断订单ID
@@ -419,6 +443,8 @@ class RefillBase
                 $chfilters->add_channel($channel_name,false);
                 if(!empty($neterr) && util::need_check($net_errno)) {
                     $mod_refill->edit($order_id, ['commit_time' => time(),'neterr' => 1,'err_msg' => "neterr={$net_errno}"]);
+                    util::monitor_neterr($channel_name);
+
                     break;
                 } else {
                     $neterr = false;

+ 21 - 0
helper/refill/util.php

@@ -4,6 +4,7 @@ namespace refill;
 
 require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
+require_once(BASE_HELPER_PATH . '/queue/monitor.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
 
 use queue;
@@ -513,6 +514,26 @@ class util
             refill\rlock::decr_mch_storage($mchid,$card_type,$spec,1);
         }
     }
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public static function monitor_submit($mchid,$mch_amount)
+    {
+        queue\MonitorClient::instance()->onSubmit($mchid,time(),$mch_amount);
+    }
+
+    public static function monitor_callback($mchid,$mch_amount,$channel_amount,$succ)
+    {
+        queue\MonitorClient::instance()->onCallback($mchid,time(),floatval($mch_amount),floatval($channel_amount),$succ);
+    }
+
+    public static function monitor_neterr($chname)
+    {
+        queue\MonitorClient::instance()->onNetError($chname, time());
+    }
+
+    public static function monitor_notify($chname,$spec,$card_type,$period,$succ)
+    {
+        queue\MonitorClient::instance()->onNotify($chname, time(),$spec,$card_type,$period,$succ);
+    }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function set_order_channels($mchid,$mchorder,$datas)

+ 3 - 3
plot/ProfitCenter.py

@@ -14,7 +14,7 @@ from io import BytesIO
 import logging
 
 class ProfitCenter(object):
-    queue_name = 'nc_profit_monitor';
+    queue_name = 'REFILL_MONITOR_QUEUE';
     latest_delta = 10
     pos_map = {
         'commit': 0, 'success': 1, 'fail': 2
@@ -60,8 +60,8 @@ class ProfitCenter(object):
                 self._parse(val)
 
     def _parse(self,val):
-        print(val)
-
+        method = val['method']
+        params = val['params']
 
 
     def parase(self, hfive, text, val, prefix):

+ 2 - 2
plot/thdf5.py

@@ -163,7 +163,7 @@ class DataTest(unittest.TestCase):
         speedDataCenter.channl_speed()
 
     def test_profitPrepare(self):
-        profitCenter.set_redis('docker.hostip','6379')
+        profitCenter.set_redis('192.168.3.46','6379')
         profitCenter.prepare_data()
 
 
@@ -180,7 +180,7 @@ class DataTest(unittest.TestCase):
             print(ex)
         finally:
             pass
-
+        
     def test_setcache(self):
         import json
         r = None

+ 4 - 0
rdispatcher/proxy.php

@@ -146,6 +146,8 @@ class proxy
                 return $this->onEerror($order, '卡类型和产品类型不符.');
             } else {
                 refill\util::incr_user_commit($mchid, $order->card_type(), $order->spec(), $org_quality);
+                $mch_amount = refill\RefillFactory::instance()->mch_amount($order);
+                refill\util::monitor_submit($order->mchid(),$mch_amount);
             }
         }
         elseif($this->need_transfer($order) && $this->transfer($order)) {
@@ -306,6 +308,8 @@ class proxy
         refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
         $refill_order->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_SEND]);
         refill\util::incr_user_commit($mchid,$card_type,$spec,$org_quality);
+        $mch_amount = refill\RefillFactory::instance()->mch_amount($order);
+        refill\util::monitor_submit($mchid,$mch_amount);
 
         [$errcode, $errmsg, $order_id, $neterr,$net_errno] = refill\RefillFactory::instance()->add($order);
         if($errcode !== true)

+ 28 - 0
test/TestRefillMonitor.php

@@ -0,0 +1,28 @@
+<?php
+
+
+use PHPUnit\Framework\TestCase;
+define('APP_ID', 'refill_stat');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+require_once(BASE_HELPER_PATH . '/queue/iqueue.php');
+require_once(BASE_HELPER_PATH . '/queue/monitor.php');
+
+
+class TestRefillMonitor extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function testPushMessage()
+    {
+        queue\MonitorClient::instance()->onSubmit(1,time(),98.5);
+    }
+
+}