|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
defined('InShopNC') or exit('Access Invalid!');
|
|
|
|
|
|
+require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
|
|
|
|
|
|
class minutesControl extends BaseCronControl
|
|
|
{
|
|
@@ -71,12 +72,12 @@ class minutesControl extends BaseCronControl
|
|
|
$mch_cache = rcache("storge_limit" , 'merchant-');
|
|
|
$caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
|
|
|
|
|
|
- $reader = function ($mchid,$time,$curtime)
|
|
|
+ $reader = function ($mchid,$time)
|
|
|
{
|
|
|
$cond['mchid'] = $mchid;
|
|
|
$cond['inner_status'] = 0;
|
|
|
$cond['order_state'] = ORDER_STATE_SUCCESS;
|
|
|
- $cond['refill_order.order_time'] = [['egt', $time],['lt', $curtime],'and'];
|
|
|
+ $cond['refill_order.order_time'] = ['egt', $time];
|
|
|
|
|
|
$items = Model('')->table('refill_order,vr_order')->join('inner')
|
|
|
->on('refill_order.order_id=vr_order.order_id')
|
|
@@ -87,29 +88,73 @@ class minutesControl extends BaseCronControl
|
|
|
return $items;
|
|
|
};
|
|
|
|
|
|
- $curtime = time();
|
|
|
- $new_caches = [];
|
|
|
- $card_type = [1 => 'petrochina' , 2 => 'sinopec'];
|
|
|
+
|
|
|
+ $merger = function ($limits,$reals,$mchid,$card_type)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ foreach ($limits as $amount => $limit)
|
|
|
+ {
|
|
|
+ $limit = intval($limit);
|
|
|
+
|
|
|
+ if($limit === -1) {
|
|
|
+ $allow = true;
|
|
|
+ }
|
|
|
+ elseif($limit === 0) {
|
|
|
+ $allow = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $finded = false;
|
|
|
+ foreach ($reals as $item)
|
|
|
+ {
|
|
|
+ $tmp = intval($item['refill_amount'] + 0.005);
|
|
|
+ if($item['card_type'] == $card_type && $tmp == $amount) {
|
|
|
+ $num = $item['num'];
|
|
|
+ $allow = $limit > $num;
|
|
|
+ $finded = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$finded) {
|
|
|
+ $allow = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $result["{$mchid}-{$card_type}-{$amount}"] = $allow;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ };
|
|
|
+
|
|
|
+ $type_map = ['petrochina' => 1,'sinopec' => 2];
|
|
|
+ $abilitys = [];
|
|
|
foreach ($caches as $cache)
|
|
|
{
|
|
|
$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-卡类型-额度
|
|
|
+ $petros = $cache['petrochina'];
|
|
|
+ $sinos = $cache['sinopec'];
|
|
|
+ $items = $reader($mchid,$start);
|
|
|
|
|
|
- $cache_num = $cache[$card_type[$item['card_type']]][$item['refill_amount']];
|
|
|
- $can_add = true;
|
|
|
- if ($cache_num < $item['num']) {
|
|
|
- $can_add = $cache_num == -1;
|
|
|
- }
|
|
|
- $new_caches["{$cache['mchid']}-{$item['card_type']}-{$item['refill_amount']}"] = $can_add;
|
|
|
+ $prets = $merger($petros,$items,$mchid,$type_map['petrochina']);
|
|
|
+ $srets = $merger($sinos,$items,$mchid,$type_map['sinopec']);
|
|
|
+ foreach ($prets as $key => $val) {
|
|
|
+ $abilitys[$key] = $val;
|
|
|
+ }
|
|
|
+ foreach ($srets as $key => $val) {
|
|
|
+ $abilitys[$key] = $val;
|
|
|
}
|
|
|
}
|
|
|
- if(!empty($new_caches)) {
|
|
|
- wcache("mch_can_order" , ['data' => serialize($new_caches)] , 'merchant-');
|
|
|
+
|
|
|
+ $old = rcache("refill_able",'merchant-');
|
|
|
+ $old = $old['data'];
|
|
|
+ $new = serialize($abilitys);
|
|
|
+ if($new != $old) {
|
|
|
+ wcache("refill_able" , ['data' => $new] , 'merchant-');
|
|
|
+ $publisher = new message\publisher();
|
|
|
+ $publisher->modify_refill_merchant();
|
|
|
}
|
|
|
}
|
|
|
|