|
@@ -9,16 +9,59 @@ use StatesHelper;
|
|
|
|
|
|
class policy extends ProviderManager implements IPolicy
|
|
|
{
|
|
|
- const normal_times = 15;
|
|
|
+ const normal_times = 30;
|
|
|
const normle_time_out = 900;
|
|
|
|
|
|
const high_times = 5;
|
|
|
const high_time_out = 60;
|
|
|
|
|
|
+ protected $mChannelControl;
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ $this->mChannelControl = new chctl();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function load()
|
|
|
+ {
|
|
|
+ parent::load();
|
|
|
+ $this->mChannelControl->load();
|
|
|
+ }
|
|
|
+
|
|
|
public function find_providers(int $spec, int $card_type,int $quality): array
|
|
|
{
|
|
|
$providers = parent::find_providers($spec,$card_type,$quality);
|
|
|
|
|
|
+ if(empty($providers)) {
|
|
|
+ return [$providers,false];
|
|
|
+ }
|
|
|
+
|
|
|
+ $names = [];
|
|
|
+ foreach ($providers as $provider) {
|
|
|
+ $names[] = $provider->name();
|
|
|
+ }
|
|
|
+
|
|
|
+ [$names,$overload] = $this->mChannelControl->match($names,$spec,$card_type,$quality);
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ foreach ($names as $name)
|
|
|
+ {
|
|
|
+ foreach ($providers as $provider)
|
|
|
+ {
|
|
|
+ if($name == $provider->name()) {
|
|
|
+ $result[] = $provider;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$result,$overload];
|
|
|
+// $this->sort_price($providers,$spec,$card_type,$quality);
|
|
|
+// return [$providers,false];
|
|
|
+ }
|
|
|
+
|
|
|
+ //按价格从低到高排序
|
|
|
+ private function sort_price($providers,int $spec, int $card_type,int $quality)
|
|
|
+ {
|
|
|
$ascending = function ($l, $r) use ($quality,$spec,$card_type) {
|
|
|
[$glid, $lprice] = $l->goods($quality,$spec,$card_type);
|
|
|
[$rgid, $rprice] = $r->goods($quality,$spec,$card_type);
|
|
@@ -35,7 +78,7 @@ class policy extends ProviderManager implements IPolicy
|
|
|
};
|
|
|
usort($providers, $ascending);
|
|
|
|
|
|
- return [$providers,false];
|
|
|
+ return $providers;
|
|
|
}
|
|
|
|
|
|
public function can_retry(array $refill_info, array $order_info) : bool
|
|
@@ -49,12 +92,12 @@ class policy extends ProviderManager implements IPolicy
|
|
|
}
|
|
|
|
|
|
$times = intval($refill['commit_times']);
|
|
|
- if ($times > 15) {
|
|
|
+ if ($times > policy::normal_times) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$period = time() - $refill['order_time'];
|
|
|
- if ($period >= 15 * 60) {
|
|
|
+ if ($period >= policy::normle_time_out) {
|
|
|
Log::record("retry false:time > 15m", Log::DEBUG);
|
|
|
return false;
|
|
|
}
|