stanley-king 4 年之前
父节点
当前提交
068090292c
共有 4 个文件被更改,包括 138 次插入62 次删除
  1. 4 0
      data/config/prod/refill.ini.php
  2. 67 62
      mobile/control/merchant_info.php
  3. 57 0
      test/TestLXOrder.php
  4. 10 0
      test/TestTime.php

+ 4 - 0
data/config/prod/refill.ini.php

@@ -1,5 +1,6 @@
 <?php
 <?php
 
 
+//速汇充京东加油通道
 $suhc_oil = ['name' => 'suhc', 'store_id' => 7, 'card_type' => ['sinopec'],
 $suhc_oil = ['name' => 'suhc', 'store_id' => 7, 'card_type' => ['sinopec'],
     'amount' => [100 => ['goods_id' => 6290, 'price' => 96.8],
     'amount' => [100 => ['goods_id' => 6290, 'price' => 96.8],
         200 => ['goods_id' => 6291, 'price' => 193.6],
         200 => ['goods_id' => 6291, 'price' => 193.6],
@@ -7,6 +8,7 @@ $suhc_oil = ['name' => 'suhc', 'store_id' => 7, 'card_type' => ['sinopec'],
         1000 => ['goods_id' => 6293, 'price' => 968]],
         1000 => ['goods_id' => 6293, 'price' => 968]],
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
 
 
+//速汇充天猫加油通道
 $suhctm_oil = ['name' => 'suhctm', 'store_id' => 7, 'card_type' => ['sinopec'],
 $suhctm_oil = ['name' => 'suhctm', 'store_id' => 7, 'card_type' => ['sinopec'],
     'amount' => [100 => ['goods_id' => 6290, 'price' => 96.8],
     'amount' => [100 => ['goods_id' => 6290, 'price' => 96.8],
         200 => ['goods_id' => 6291, 'price' => 193.6],
         200 => ['goods_id' => 6291, 'price' => 193.6],
@@ -14,12 +16,14 @@ $suhctm_oil = ['name' => 'suhctm', 'store_id' => 7, 'card_type' => ['sinopec'],
         1000 => ['goods_id' => 6293, 'price' => 968]],
         1000 => ['goods_id' => 6293, 'price' => 968]],
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
 
 
+//赵梓暄提供的加油通道
 $zzx_oil = ['name' => 'zzx', 'store_id' => 13, 'card_type' => ['petrochina','sinopec'],
 $zzx_oil = ['name' => 'zzx', 'store_id' => 13, 'card_type' => ['petrochina','sinopec'],
     'amount' => [100 => ['goods_id' => 6307, 'price' => 97.8],
     'amount' => [100 => ['goods_id' => 6307, 'price' => 97.8],
         200 => ['goods_id' => 6308, 'price' => 195.6],
         200 => ['goods_id' => 6308, 'price' => 195.6],
         500 => ['goods_id' => 6309, 'price' => 489],
         500 => ['goods_id' => 6309, 'price' => 489],
         1000 => ['goods_id' => 6310, 'price' => 978]], 'refill_type' => 'api'];
         1000 => ['goods_id' => 6310, 'price' => 978]], 'refill_type' => 'api'];
 
 
+//赵梓暄提供的加油通道
 $lx_oil = ['name' => 'lx', 'store_id' => 14, 'card_type' => ['sinopec'],
 $lx_oil = ['name' => 'lx', 'store_id' => 14, 'card_type' => ['sinopec'],
     'amount' => [1000 => ['goods_id' => 6311, 'price' => 958] //,
     'amount' => [1000 => ['goods_id' => 6311, 'price' => 958] //,
 //        2000 => ['goods_id' => 6322, 'price' => 1916]
 //        2000 => ['goods_id' => 6322, 'price' => 1916]

+ 67 - 62
mobile/control/merchant_info.php

@@ -15,7 +15,7 @@ class merchant_infoControl extends mbMerchantControl
         $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name,alarm_amount,ip_white_list,use_key');
         $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name,alarm_amount,ip_white_list,use_key');
         $model_member = Model('member');
         $model_member = Model('member');
         $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
         $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
-        if(empty($member_info)){
+        if (empty($member_info)) {
             $member_info['available_predeposit'] = 0;
             $member_info['available_predeposit'] = 0;
         }
         }
         $merchant_info['member'] = $member_info;
         $merchant_info['member'] = $member_info;
@@ -35,28 +35,79 @@ class merchant_infoControl extends mbMerchantControl
         $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name');
         $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid], 'mchid,admin_id,name');
         $model_member = Model('member');
         $model_member = Model('member');
         $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
         $member_info = $model_member->getMemberInfo(['member_id' => $merchant_info['admin_id']], 'available_predeposit');
-        if(empty($member_info)){
+        if (empty($member_info)) {
             $merchant_info['available_predeposit'] = 0;
             $merchant_info['available_predeposit'] = 0;
-        }else{
+        } else {
             $merchant_info['available_predeposit'] = $member_info['available_predeposit'];
             $merchant_info['available_predeposit'] = $member_info['available_predeposit'];
         }
         }
 
 
-        $cond['mchid'] = $mchid;
-        $cond['inner_status'] = 0;
-        $beginToday = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
-        $endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
-        $cond['refill_order.order_time'] = ['between', [$beginToday, $endToday]];
-        $todayStatistics = $this->MerchantOrderStatistics($cond);
-        $beginThisWeek = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('y'));
-        $endThisWeek = time();
-        $cond['refill_order.order_time'] = ['between', [$beginThisWeek, $endThisWeek]];
-        $weeksStatistics = $this->WeeksMerchantOrderStatistics($cond);
+        $statistics = $this->statistics();
+
         $result['merchant_info'] = $merchant_info;
         $result['merchant_info'] = $merchant_info;
-        $result['todayStatistics'] = $todayStatistics;
-        $result['weeksStatistics'] = $weeksStatistics;
+        $result['todayStatistics'] = $statistics[0];
+        $result['weeksStatistics'] = $statistics;
         return self::outsuccess($result);
         return self::outsuccess($result);
     }
     }
 
 
+    private function statistics()
+    {
+        $cond['mchid'] = $this->mchid();
+        $cond['inner_status'] = 0;
+        $begin_time = $this->date_time();
+        $cond['order_time'] = ['egt', $begin_time];
+
+        $result = [];
+        for ($ftime = $begin_time, $i = 0; $ftime < time(); $ftime += 86400, $i += 1) {
+            $result[$i] = ['count' => 0, 'successCount' => 0, 'errorCount' => 0, 'otherCount' => 0, 'amountCount' => 0];
+        }
+
+
+        $model_refill_order = Model('refill_order');
+
+        $i = 0;
+        while (true)
+        {
+            $start = $i * 1000;
+            $orders = $model_refill_order->getMerchantOrderList($cond,'','*', 'refill_order.order_id desc',"{$start},1000");
+
+            if (empty($orders)) {
+                break;
+            }
+
+            $days_calc = function ($order_time) use ($begin_time) {
+                $period = $order_time - $begin_time;
+                $days = intval($period / 86400) + ($period % 86400 > 0 ? 1 : 0);
+                return $days;
+            };
+
+            foreach ($orders as $order)
+            {
+                $order_day = $days_calc($order['order_time']);
+
+                $result[$order_day]['count'] += 1;
+                if ($order['order_state'] == ORDER_STATE_CANCEL) {
+                    $result[$order_day]['errorCount'] += 1;
+                } elseif ($order['order_state'] == ORDER_STATE_SUCCESS) {
+                    $result[$order_day]['successCount'] += 1;
+                    $result[$order_day]['amountCount'] += $order['mch_amount'];;
+                } else {
+                    $result[$order_day]['otherCount'] += 1;
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    private function date_time($days = 6)
+    {
+        $date = date('Y-m-d', time());
+        $day_start = strtotime("{$date}");
+        $begin = $day_start - $days * 86400;
+        return $begin;
+    }
+
+
     public function addipOp()
     public function addipOp()
     {
     {
         $mchid = $this->mchid();
         $mchid = $this->mchid();
@@ -160,7 +211,7 @@ class merchant_infoControl extends mbMerchantControl
             return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
             return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
         }
         }
         $model_pd = Model('merchant');
         $model_pd = Model('merchant');
-        if(empty($merchant_info['admin_id'])){
+        if (empty($merchant_info['admin_id'])) {
             $result['data'] = [];
             $result['data'] = [];
             $result['total'] = 0;
             $result['total'] = 0;
             return self::outsuccess($result);
             return self::outsuccess($result);
@@ -216,50 +267,4 @@ class merchant_infoControl extends mbMerchantControl
         }
         }
         return $data;
         return $data;
     }
     }
-
-    private function WeeksMerchantOrderStatistics($cond)
-    {
-        $data = [];
-        $begin = mktime(0, 0, 0, date('m'), date('d') - 7, date('Y'));
-        $end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
-        $cond['refill_order.order_time'] = ['between', [$begin, $end]];
-        $WeeksOrderStatistics = $this->MerchantOrderStatistics($cond);
-
-        for ($i = 0; $i < 7; $i++) {
-            $begin = mktime(0, 0, 0, date('m'), date('d') - $i, date('Y'));
-            $end = mktime(0, 0, 0, date('m'), date('d') - $i + 1, date('Y')) - 1;
-            $cond['refill_order.order_time'] = ['between', [$begin, $end]];
-            $OrderStatistics = $this->MerchantOrderStatistics($cond);
-            $data[] = $OrderStatistics;
-        }
-        return $data;
-    }
-
-    private function MerchantOrderStatistics($cond)
-    {
-        $model_refill_order = Model('refill_order');
-        $orders = $model_refill_order->getMerchantOrderList($cond);
-        if (empty($orders)) {
-            $data['count'] = $data['successCount'] = $data['errorCount'] = $data['otherCount'] = $data['amountCount'] = 0;
-            return $data;
-        }
-        $count = count($orders);
-        $successCount = $errorCount = $otherCount = $amountCount = 0;
-        foreach ($orders as $order) {
-            if ($order['order_state'] == ORDER_STATE_CANCEL) {
-                $errorCount++;
-            } elseif ($order['order_state'] == ORDER_STATE_SUCCESS) {
-                $successCount++;
-                $amountCount += $order['mch_amount'];
-            } else {
-                $otherCount++;
-            }
-        }
-        $data['count'] = $count;
-        $data['successCount'] = $successCount;
-        $data['errorCount'] = $errorCount;
-        $data['otherCount'] = $otherCount;
-        $data['amountCount'] = $amountCount;
-        return $data;
-    }
 }
 }

+ 57 - 0
test/TestLXOrder.php

@@ -0,0 +1,57 @@
+<?php
+
+declare(strict_types=0);
+
+define('APP_ID', 'test');
+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');
+
+use PHPUnit\Framework\TestCase;
+
+class TestLXOrder extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    private $mStoreID;
+
+    public function __construct(?string $name = null, array $data = [], $dataName = '')
+    {
+        parent::__construct($name, $data, $dataName);
+        $this->mStoreID = 10;
+    }
+
+    public function testDown()
+    {
+        $vr_order = Model('vr_order');
+        $orders = $vr_order->getOrderList(['store_id' => $this->mStoreID,'order_state' => ORDER_STATE_PAY]);
+        if(empty($orders)) {
+            Log::record("没有新订单",Log::DEBUG);
+            return;
+        }
+
+        $order_ids = [];
+        foreach ($orders as $order) {
+            $order_ids[] = $order['order_id'];
+        }
+
+        $refill_order = Model('refill_order');
+//        $refills = $refill_order->get
+
+    }
+
+    public function testUpSuccess()
+    {
+
+    }
+
+    public function testUpFail()
+    {
+
+    }
+
+}

+ 10 - 0
test/TestTime.php

@@ -115,4 +115,14 @@ class TestTime extends TestCase
             $day_end = strtotime("{$date}   {$period['end']}");
             $day_end = strtotime("{$date}   {$period['end']}");
         }
         }
     }
     }
+
+    public function testDate()
+    {
+        $date = date('Y-m-d',time());
+        $day_start = strtotime("{$date}");
+        $begin = $day_start - 6 * 86400;
+
+
+    }
+
 }
 }