Browse Source

add to local

stanley-king 4 năm trước cách đây
mục cha
commit
3949d490c5

+ 9 - 6
admin/control/merchant.php

@@ -151,27 +151,29 @@ class merchantControl extends SystemControl
 
     public function orderDayLimitOp()
     {
-        if (chksubmit()) {
+        if (chksubmit())
+        {
             $mchids = $_POST['mchid'];
             $petrochinas = $_POST['petrochina'];
             $sinopecs = $_POST['sinopec'];
-            foreach ($mchids as $key => $mchid) {
+            foreach ($mchids as $pos => $mchid) {
                 $data['mchid'] = $mchid;
-                $data['petrochina'] = ['100' => $petrochinas[100][$key] , '200' => $petrochinas[200][$key] , '500' => $petrochinas[500][$key] , '1000' => $petrochinas[1000][$key]];
-                $data['sinopec'] = ['100' => $sinopecs[100][$key] , '200' => $sinopecs[200][$key] , '500' => $sinopecs[500][$key] , '1000' => $sinopecs[1000][$key]];
+                $data['petrochina'] = ['100' => $petrochinas[100][$pos] , '200' => $petrochinas[200][$pos] , '500' => $petrochinas[500][$pos] , '1000' => $petrochinas[1000][$pos]];
+                $data['sinopec'] = ['100' => $sinopecs[100][$pos] , '200' => $sinopecs[200][$pos] , '500' => $sinopecs[500][$pos] , '1000' => $sinopecs[1000][$pos]];
                 $data['time'] = time();
                 $result[$mchid] = $data;
             }
-            wcache('order_limit' , ['data' => serialize($result)] , 'merchant-');
+            wcache('storge_limit' , ['data' => serialize($result)] , 'merchant-');
             showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
         }
-        $order_limit = rcache('order_limit' , 'merchant-');
+        $order_limit = rcache('storge_limit' , 'merchant-');
 
         if(empty($order_limit)){
             $order_limit = [];
         }else{
             $order_limit = unserialize($order_limit['data']);
         }
+
         $default = function ($merchant) {
             $amount = [
                 '100' => -1,
@@ -183,6 +185,7 @@ class merchantControl extends SystemControl
             $data['petrochina'] = $data['sinopec'] = $amount;
             return $data;
         };
+
         $model_merchant = model('merchant');
         $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc' , 'mchid,company_name');
         foreach ($merchant_list as $merchant)

+ 11 - 5
crontab/control/minutes.php

@@ -66,17 +66,17 @@ class minutesControl extends BaseCronControl
         wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
     }
 
-    private function _check_refill_order_limit()
+    public function check_refill_order_limit()
     {
-        $mch_cache = rcache("order_limit" , 'merchant-');
+        $mch_cache = rcache("storge_limit" , 'merchant-');
         $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
 
-        $reader = function ($mchid,$time)
+        $reader = function ($mchid,$time,$curtime)
         {
             $cond['mchid'] = $mchid;
             $cond['inner_status'] = 0;
             $cond['order_state'] = ORDER_STATE_SUCCESS;
-            $cond['refill_order.order_time'] = ['ge', $time];
+            $cond['refill_order.order_time'] = [['egt', $time],['lt', $curtime],'and'];
 
             $items = Model('')->table('refill_order,vr_order')->join('inner')
                 ->on('refill_order.order_id=vr_order.order_id')
@@ -87,13 +87,19 @@ class minutesControl extends BaseCronControl
             return $items;
         };
 
+        $curtime = time();
         $new_caches = [];
         $card_type = [1 => 'petrochina' , 2 => 'sinopec'];
         foreach ($caches as $cache)
         {
-            $items = $reader($cache['mchid'],$cache['time']);
+            $mchid = intval($cache['mchid']);
+            $start = $cache['time'];
+            $end = $curtime;
+
+            $items = $reader($mchid,$start,$end);
             foreach ($items as $item) {
                 //指定card_type,refill_amount的单数比缓存中设置单数大,设置对应缓存能否下单为false,key为商户ID-卡类型-额度
+
                 $cache_num = $cache[$card_type[$item['card_type']]][$item['refill_amount']];
                 $can_add = true;
                 if ($cache_num < $item['num']) {

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

@@ -21,7 +21,8 @@ class merchantModel extends Model
 
     public function getMerchantList($condition, $page = null, $order = '', $field = '*', $limit = '')
     {
-        $result = $this->table('merchant,member')->join('inner')->on('member.member_id=merchant.admin_id')->field($field)->where($condition)->order($order)->limit($limit)->page($page)->select();
+        $result = $this->table('merchant,member')->join('inner')->on('member.member_id=merchant.admin_id')
+            ->field($field)->where($condition)->order($order)->limit($limit)->page($page)->select();
         return $result;
     }
 

+ 37 - 0
test/TestCrontab.php

@@ -0,0 +1,37 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+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');
+
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+
+require_once(BASE_CRONTAB_PATH . '/control/control.php');
+require_once(BASE_CRONTAB_PATH . '/control/minutes.php');
+
+class TestCrontab extends TestCase
+{
+    private $min_controller;
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function __construct(?string $name = null, array $data = [], $dataName = '')
+    {
+        parent::__construct($name, $data, $dataName);
+        $this->min_controller = new minutesControl();
+    }
+    public function testLimit()
+    {
+        $this->min_controller->check_refill_order_limit();
+    }
+
+}