RefillBase.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. <?php
  2. namespace refill;
  3. require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
  4. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  5. require_once(BASE_HELPER_PATH . '/refill/IRefill.php');
  6. require_once(BASE_HELPER_PATH . '/refill/IRefillOil.php');
  7. require_once(BASE_HELPER_PATH . '/refill/IRefillPhone.php');
  8. require_once(BASE_HELPER_PATH . '/refill/IRefillThird.php');
  9. require_once(BASE_HELPER_PATH . '/refill/IRefillCallBack.php');
  10. require_once(BASE_HELPER_PATH . '/refill/ProviderManager.php');
  11. require_once(BASE_HELPER_PATH . '/refill/CalcMerchantPrice.php');
  12. require_once(BASE_HELPER_PATH . '/refill/util.php');
  13. require_once(BASE_HELPER_PATH . '/refill/errcode.php');
  14. use Log;
  15. use scope_trace;
  16. use mtopcard;
  17. use QueueClient;
  18. use member_info;
  19. use Exception;
  20. use trans_wapper;
  21. use Swoole;
  22. class RefillBase
  23. {
  24. protected $mPolicy;
  25. protected function __construct($policy)
  26. {
  27. $this->mPolicy = $policy;
  28. }
  29. public function allow($mchid,$card_type,$amount,$quality)
  30. {
  31. return $this->mPolicy->allow($mchid,$card_type,$amount,$quality);
  32. }
  33. public function goods()
  34. {
  35. return $this->mPolicy->goods();
  36. }
  37. public function load()
  38. {
  39. $this->mPolicy->load();
  40. }
  41. public function find_quality(order $order,$skip = false)
  42. {
  43. return $this->mPolicy->find_quality($order,$skip);
  44. }
  45. private function third_can_retry(order $order) : array
  46. {
  47. return $this->mPolicy->third_retry($order);
  48. }
  49. public function notify($chname, $input)
  50. {
  51. $caller = $this->mPolicy->getCaller($chname);
  52. if($caller === false) {
  53. return false;
  54. }
  55. elseif ($caller->verify($input))
  56. {
  57. $values = $caller->notify($input);
  58. if(count($values) == 4) { //老的接口返回四个参数
  59. [$order_id, $success, $can_try, $need_handle] = $values;
  60. $official_sn = false;
  61. } else {
  62. [$order_id, $success, $can_try, $need_handle, $official_sn] = $values;
  63. }
  64. if (!$need_handle) {
  65. return true;
  66. }
  67. if ($order_id !== false) {
  68. return $this->proc_notify($order_id, $success, $can_try, $chname, $input, $official_sn);
  69. } else {
  70. Log::record("$chname callback 系统无此订单ID.", Log::WARING);
  71. }
  72. }
  73. else {
  74. $orgdata = json_encode($input);
  75. Log::record("$chname 签名失败:input=$orgdata",Log::WARING);
  76. }
  77. return true;
  78. }
  79. private function risksn_check($refill_info, $order_info, $org_official_sn)
  80. {
  81. $in_exclude = function ($store_id)
  82. {
  83. $store_id = intval($store_id);
  84. if($store_id <= 0) {
  85. return false;
  86. }
  87. global $config;
  88. $risk_official_sn = $config['risk_official_sn'] ?? [];
  89. $exclude_stores = $risk_official_sn['exclude_stores'] ?? [];
  90. return in_array($store_id,$exclude_stores);
  91. };
  92. $card_type = intval($refill_info['card_type']);
  93. $chk_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  94. $store_id = intval($order_info['store_id']);
  95. if($in_exclude($store_id)) {
  96. return false;
  97. }
  98. if(!in_array($card_type,$chk_types)) {
  99. return false;
  100. }
  101. if ($org_official_sn !== false)
  102. {
  103. $length = strlen($org_official_sn);
  104. if($length < 6 or $length > 48) {
  105. return true;
  106. }
  107. }
  108. $quality = intval($refill_info['quality']);
  109. $official_sn = $refill_info['official_sn'];
  110. if($quality === Quality::Normal && empty($official_sn)) {
  111. return true;
  112. }
  113. $start_with = function ($haystack, $needle) {
  114. $length = strlen($needle);
  115. return (substr($haystack, 0, $length) === $needle);
  116. };
  117. $headers = ['SP', 'J98', 'WX', '110110']; //, '11010336J' '0095','ZF2023'
  118. $spcheker = function () use ($start_with, $headers, $official_sn)
  119. {
  120. $official_sn = strtoupper($official_sn);
  121. foreach ($headers as $header)
  122. {
  123. if ($start_with($official_sn, $header)) {
  124. return true;
  125. }
  126. }
  127. return false;
  128. };
  129. return $spcheker();
  130. }
  131. private function proc_notify($order_id, $success, $can_try, $chname, $input = [], $official_sn = false)
  132. {
  133. $mod_order = Model('vr_order');
  134. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id]);
  135. $order_state = intval($order_info['order_state']);
  136. if ($order_state == ORDER_STATE_PAY)
  137. {
  138. if(!empty($input)) {
  139. Log::record(__METHOD__ . " recv notify when order_state=ORDER_STATE_PAY" ,Log::DEBUG);
  140. Swoole\Coroutine::sleep(5);
  141. util::push_notify($chname,$input);
  142. }
  143. return false;
  144. }
  145. if ($order_state != ORDER_STATE_SEND) {
  146. return false;
  147. }
  148. $logic_vr_order = Logic("vr_order");
  149. $mod_refill = Model('refill_order');
  150. try
  151. {
  152. $tran = new trans_wapper($mod_order,'notify change order state trans');
  153. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id], '*', true, true);
  154. $order_state = intval($order_info['order_state']);
  155. if ($order_state != ORDER_STATE_SEND) {
  156. $tran->commit();
  157. return false;
  158. }
  159. $refill_info = $mod_refill->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0]);
  160. if(empty($refill_info)) {
  161. $tran->commit();
  162. return false;
  163. }
  164. $quality = intval($refill_info['quality']);
  165. $card_type = intval($refill_info['card_type']);
  166. $spec = intval($refill_info['refill_amount']);
  167. $mchid = intval($refill_info['mchid']);
  168. $mch_order = $refill_info['mch_order'];
  169. $order_time = intval($refill_info['order_time']);
  170. if ($success)
  171. {
  172. $params = ['store_id' => $order_info['store_id'],
  173. 'channel_name' => $refill_info['channel_name'],
  174. 'order_sn' => $refill_info['order_sn'],
  175. 'order_id' => $refill_info['order_id'],
  176. 'official_sn' => $refill_info['official_sn']];
  177. if ($this->risksn_check($refill_info, $order_info, $official_sn)) {
  178. $tran->commit();
  179. QueueClient::async_push("OnRiskSN", $params, 1);
  180. return false;
  181. } else {
  182. QueueClient::async_push("OnRefillSuccess", $params, 1);
  183. }
  184. }
  185. $commit_time = intval($refill_info['commit_time']);
  186. $period = time() - $commit_time;
  187. util::monitor_notify($chname,$spec,$card_type,$refill_info['channel_amount'],$period,$success,$commit_time,$refill_info['mch_amount']);
  188. util::onEventNotify($refill_info,$order_info,$success);
  189. if ($success) {
  190. $logic_vr_order->changeOrderStateSuccess($order_id,true);
  191. $tran->commit();
  192. util::onOrderSuccess($refill_info,$order_info);
  193. }
  194. elseif ($can_try)
  195. {
  196. $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试", true, true);
  197. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['is_retrying' => 1,'notify_time' => time()]);
  198. $tran->commit();
  199. if ($card_type == mtopcard\ThirdRefillCard) {
  200. $thrid_refill = Model('thrid_refill');
  201. $third_info = $thrid_refill->getThird($order_id);
  202. $third_info = $thrid_refill->trans_order($third_info);
  203. } else {
  204. $third_info = [];
  205. }
  206. $order = order::from_db($refill_info, $order_info, $third_info);
  207. $ch_filter = $order->filter();
  208. $ch_filter->notify($refill_info['quality'], $chname);
  209. [$can_retry,$params] = $this->retry($order);
  210. if ($can_retry)
  211. {
  212. if($order->is_third())
  213. {
  214. if(util::push_addthird($params)) {
  215. return true;
  216. }
  217. }
  218. elseif(util::push_add($params)) {
  219. return true;
  220. }
  221. }
  222. else {
  223. $order->finish();
  224. }
  225. }
  226. else {
  227. $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.",true,true);
  228. $tran->commit();
  229. }
  230. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['notify_time' => time(), 'is_retrying' => 0,'notify_state' => 1]);
  231. util::monitor_callback($mchid, $spec, $card_type, $refill_info['mch_amount'], $refill_info['channel_amount'], $success, $order_time);
  232. util::onEventComplete($refill_info, $order_info, $success);
  233. util::pop_queue_order($mchid,$mch_order,$order_time);
  234. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
  235. return true;
  236. }
  237. catch (Exception $ex) {
  238. $tran->rollback();
  239. Log::record("Error:" . $ex->getMessage(), Log::ERR);
  240. Swoole\Coroutine::sleep(5);
  241. util::push_notify($chname,$input);
  242. return false;
  243. }
  244. }
  245. private function retry(order $order)
  246. {
  247. $trace = new scope_trace(__METHOD__);
  248. if($order->is_third())
  249. {
  250. [$can_retry,$next_pcode] = $this->third_can_retry($order);
  251. if($can_retry) {
  252. $params = $order->third_requeue_params($next_pcode);
  253. return [$can_retry,$params];
  254. }
  255. else {
  256. return [false,null];
  257. }
  258. }
  259. $params = $order->queue_params();
  260. return [true,$params];
  261. }
  262. public function success_order(order $order) : array
  263. {
  264. $last_orderid = $order->last_order_id();
  265. $mchid = $order->mchid();
  266. $order_time = $order->order_time();
  267. try
  268. {
  269. $minfo = new member_info($order->buyer_id());
  270. $org_quality = $order->org_quality();
  271. if(PolicyUtil::mixed_quality($org_quality)) {
  272. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$org_quality,$this->mPolicy,$order->thrid_params());
  273. }
  274. else {
  275. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$order->cur_quality(),$this->mPolicy,$order->thrid_params());
  276. }
  277. $mch_price = $calc->calc_vgoods_price([]);
  278. $mch_amount = $mch_price * $order->quantity();
  279. }
  280. catch (Exception $ex) {
  281. return [false,$last_orderid,'没有协商商品价格'];
  282. }
  283. $available = $minfo->available_predeposit();
  284. if ($mch_amount > $available) {
  285. return [false, $last_orderid,"余额不足支付订单"];
  286. }
  287. $goods_id = ZERO_GOODS_ID;
  288. $channel_name = 'cbproxy';
  289. $channel_amount = $mch_amount;
  290. $mod_refill = Model('refill_order');
  291. [$order_success, $order_id, $order_sn] = $this->create_order($order, $goods_id, $minfo, $calc, $channel_name, $channel_amount, $mch_amount);
  292. if(!$order_success) {
  293. return [false,$last_orderid,'订单创建失败'];
  294. }
  295. else {
  296. $logic_vr_order = Logic("vr_order");
  297. $logic_vr_order->changeOrderStateSuccess($order_id,true);
  298. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['commit_time' => time(),'notify_time' => time(), 'is_retrying' => 0,'notify_state' => 1]);
  299. util::monitor_callback($mchid, $order->spec(), $order->card_type(), $mch_amount, $channel_amount, true, $order->order_time());
  300. $refill_info = $mod_refill->partition(util::part_refill($order_time))->getOrderInfo(['order_id' => $order_id]);
  301. $mod_order = Model('vr_order');
  302. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id]);
  303. util::onEventComplete($refill_info, $order_info, true);
  304. return [true,$order_id,''];
  305. }
  306. }
  307. public function zero_order(order $order,$errmsg='')
  308. {
  309. $buyer_id = $order->buyer_id();
  310. $minfo = new member_info($buyer_id);
  311. $calc = new ZeroMerchantPrice($order->mchid(), $order->spec(), $order->card_type(),$order->cur_quality());
  312. $mch_amount = $calc->calc_vgoods_price([]);
  313. $input['goods_id'] = ZERO_GOODS_ID;
  314. $input['quantity'] = 1; //数量
  315. $input['buyer_phone'] = $minfo->mobile();
  316. $input['buyer_name'] = $minfo->truename();
  317. $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
  318. $input['order_from'] = 1;
  319. $input['pd_pay'] = true;
  320. $logic_buy_virtual = Logic('buy_virtual');
  321. $result = $logic_buy_virtual->buyStep3($input, $buyer_id, [$calc, 'calc_vorder_amount'], true, true);
  322. $mod_refill = Model('refill_order');
  323. if ($result['state'] === true)
  324. {
  325. $order_sn = $result['data']['order_sn'];
  326. $order_id = $result['data']['order_id'];
  327. $logic_vr_order = Logic("vr_order");
  328. $order_info = Model('vr_order')->partition(util::part_vr_create())->getOrderInfo(['order_id' => $order_id]);
  329. $logic_vr_order->changeOrderStateCancel($order_info, '', '无法下单创建0元订单',true,true);
  330. $mch_order = $order->mch_order();
  331. if (empty($mch_order)) {
  332. $order->set_mchorder($order_sn);
  333. }
  334. $thrid_refill = Model('thrid_refill');
  335. if($order->is_third()) {
  336. $product = $thrid_refill->getProduct(['system_code' => $order->pcode()]);
  337. $refill_amount = $product['refill_amount'];
  338. } else {
  339. $refill_amount = $order->spec();
  340. }
  341. //虚拟订单表信息扩展
  342. $orderext = $order->ZeroRefillParams($order_id,$order_sn,$refill_amount,$mch_amount,'',0,$errmsg);
  343. $order->commit_times_inc();
  344. $mod_refill->add_refill($orderext);
  345. if($order->is_third()) {
  346. $thrid_refill = Model('thrid_refill');
  347. $ext = $order->third_extparams($order_id,$order_sn);
  348. $thrid_refill->addExt($ext);
  349. }
  350. return $order_id;
  351. }
  352. else {
  353. return 0;
  354. }
  355. }
  356. public function mch_amount(order $order)
  357. {
  358. $mchid = $order->mchid();
  359. $org_quality = $order->org_quality();
  360. try
  361. {
  362. if (PolicyUtil::mixed_quality($org_quality)) {
  363. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(), $org_quality, $this->mPolicy, $order->thrid_params());
  364. } else {
  365. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(), $order->cur_quality(), $this->mPolicy, $order->thrid_params());
  366. }
  367. $mch_price = $calc->calc_vgoods_price([]);
  368. $mch_amount = $mch_price * $order->quantity();
  369. return $mch_amount;
  370. } catch (Exception $ex) {
  371. $spec = $order->spec();
  372. $card_type = $order->card_type();
  373. $cur_quality = $order->cur_quality();
  374. Log::record("onError mchid=$mchid org_quality=$org_quality cur_qua=$cur_quality spec=$spec card_type=$card_type :" . $ex->getMessage(), Log::ERR);
  375. return false;
  376. }
  377. }
  378. //返回值:[ 错误码,错误信息,订单ID,是否是网络错误]
  379. //说明:错误码为true 表示成功
  380. // 其它情况,则需要判断订单ID
  381. public function add(order $order)
  382. {
  383. $last_orderid = $order->last_order_id();
  384. $order_time = $order->order_time();
  385. $mchid = $order->mchid();
  386. $mch_order = $order->mch_order();
  387. [$providers, $overload] = $this->mPolicy->find_providers($order);
  388. $ch_times = $this->mPolicy->get_times();
  389. $chfilters = $order->filter();
  390. $cur_quality = $order->cur_quality();
  391. $providers = $chfilters->getProviders($cur_quality, $providers, $ch_times);
  392. if (empty($providers)) {
  393. Log::record("canot find any providers", Log::DEBUG);
  394. return [errcode::MERCHANT_REFILL_CHLIMIT, "匹配不到任何通道", $last_orderid, false, 0];
  395. }
  396. try
  397. {
  398. $minfo = new member_info($order->buyer_id());
  399. $org_quality = $order->org_quality();
  400. if(PolicyUtil::mixed_quality($org_quality)) {
  401. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$org_quality,$this->mPolicy,$order->thrid_params());
  402. }
  403. else {
  404. $calc = new CalcMerchantPrice($mchid, $order->spec(), $order->card_type(),$order->cur_quality(),$this->mPolicy,$order->thrid_params());
  405. }
  406. $mch_price = $calc->calc_vgoods_price([]);
  407. $mch_amount = $mch_price * $order->quantity();
  408. }
  409. catch (Exception $ex) {
  410. return [errcode::MERCHANT_PRICE_UNSETTING, "没有协商商品价格",$last_orderid,false,0];
  411. }
  412. $available = $minfo->available_predeposit();
  413. if ($mch_amount > $available) {
  414. $errmsg = "余额不足=$available";
  415. Log::record($errmsg, Log::DEBUG);
  416. return [errcode::MERCHANT_SHORT_MONEY, $errmsg, $last_orderid, false, 0];
  417. }
  418. foreach ($providers as $provider)
  419. {
  420. $channel_name = $provider->name();
  421. $can_commit = util::onEventBeforeCommit($order, $channel_name);
  422. if ($can_commit === false) {
  423. continue;
  424. }
  425. if($this->mPolicy->is_over_chspeed($channel_name)) {
  426. Log::record("chspeed is over:$channel_name",Log::DEBUG);
  427. continue;
  428. }
  429. [$goods_id, $ch_price] = $provider->goods($order->cur_quality(), $order->spec(), $order->card_type(), $order->region_no(), $order->thrid_params());
  430. if ($goods_id <= 0) continue;
  431. if($ch_price > $mch_price)
  432. {
  433. //非组合通道,以原始质量算价格. //通道价格大于客户价格,换通道.
  434. if($order->is_third())
  435. {
  436. $third_mixed = $this->mPolicy->third_mixed($order->mchid(),$order->pcode());
  437. if(!$third_mixed) {
  438. continue;
  439. }
  440. }
  441. elseif(PolicyUtil::mixed_quality($org_quality))
  442. {
  443. if (!$order->can_over_price()) {
  444. Log::record("can_over_price is false", Log::DEBUG);
  445. continue;
  446. } else {
  447. Log::record("can_over_price is true", Log::DEBUG);
  448. }
  449. }
  450. else {
  451. continue;
  452. }
  453. }
  454. $mod_refill = Model('refill_order');
  455. $channel_amount = $ch_price * $order->quantity();
  456. [$order_success, $order_id, $order_sn] = $this->create_order($order, $goods_id, $minfo, $calc, $channel_name, $channel_amount, $mch_amount);
  457. $last_orderid = $order_id;
  458. if(!$order_success) {
  459. return [errcode::MERCHANT_REFILL_DBERROR, "充值失败", $last_orderid, false, 0];
  460. }
  461. $start = microtime(true);
  462. $net_errno = "";
  463. $params = $order->channel_params($order_id, $order_sn, $goods_id, $ch_price);
  464. $card_no = $order->card_no();
  465. $card_type = $order->card_type();
  466. $spec = $order->spec();
  467. $quality = $order->cur_quality();
  468. [$state, $errmsg, $neterr] = $provider->add($card_no, $card_type, $spec, $params, $net_errno);
  469. Log::record(sprintf(" %s add request time=%.6f: state=$state neterr=$neterr,net_errno=$net_errno", $channel_name,microtime(true) - $start), Log::DEBUG);
  470. if ($state)
  471. {
  472. $commit_time = time();
  473. $chfilters->add($cur_quality,$channel_name,true);
  474. util::monitor_commit($channel_name, $spec, $card_type, $channel_amount, $commit_time);
  475. util::onEventCommit($order,$channel_name);
  476. $trade_no = $errmsg;
  477. $refill_type = $provider->refill_type();
  478. $vr_part = util::part_vr_order_time($order_time);
  479. //api回调模式
  480. if ($refill_type == 'api') {
  481. $logic_vr_order = Logic("vr_order");
  482. $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
  483. }
  484. //抢单子模式
  485. elseif($refill_type == 'fetch') {
  486. $logic_vr_order = Logic("vr_order");
  487. $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
  488. $order_info = Model('vr_order')->partition($vr_part)->getOrderInfo(['order_id' => $order_id]);
  489. $mod_fetch_order = Model('fetch_order');
  490. $fetch_datas = ['order_id' => $order_id, 'order_sn' => $order_sn, 'store_id' => $order_info['store_id'],'channel_name' => $channel_name,
  491. 'fetch_status' => 1, 'card_no' => $card_no, 'card_type' => $card_type, 'refill_amount' => $spec,
  492. 'add_time' => time()];
  493. $mod_fetch_order->add($fetch_datas);
  494. }
  495. else {
  496. Log::record("Err refill_type = $refill_type",Log::ERR);
  497. }
  498. $data = ['commit_time' => $commit_time, 'ch_trade_no' => $trade_no];
  499. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, $data);
  500. //主动查询模式。如果对方没有回调能力,则启动主动查询.
  501. if($provider->callback() === false) {
  502. QueueClient::async_push("QueryAutoRefillState",['order_id' => $order_id,'query_times' => 0],3);
  503. }
  504. return [true, '', $last_orderid, false, 0];
  505. }
  506. else
  507. {
  508. $chfilters->add($cur_quality, $channel_name, false);
  509. if(!empty($neterr) && util::need_check($net_errno)) {
  510. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['commit_time' => time(),'neterr' => 1,'err_msg' => "neterr=$net_errno"]);
  511. util::monitor_netchk($channel_name,false);
  512. util::onEventNeterror($order,$channel_name);
  513. return [errcode::MERCHANT_REFILL_NETERROR, "充值失败", $last_orderid, $neterr, $net_errno];
  514. }
  515. //可以再提单
  516. Log::record("channel:$channel_name err:$errmsg");
  517. $logic_vr_order = Logic("vr_order");
  518. $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
  519. $logic_vr_order->changeOrderStateCancel($order_info, '', "调用{$channel_name}接口失败",true,true);
  520. if(!is_string($errmsg)) {
  521. $errmsg = "$errmsg";
  522. }
  523. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['commit_time' => time(), 'err_msg' => $errmsg]);
  524. }
  525. }
  526. return [errcode::MERCHANT_REFILL_CHLIMIT, "无可用通道", $last_orderid, false, 0];
  527. }
  528. private function create_order(order $order, $goods_id, $minfo, $calc, $ch_name, $ch_amount, $mch_amount)
  529. {
  530. $refill_creater = function (order $order,$last_orderid,$order_id,$order_sn,$mod_refill) use($ch_name, $ch_amount,$mch_amount)
  531. {
  532. try
  533. {
  534. if($last_orderid > 0) {
  535. $order_time = $order->order_time();
  536. $mod_refill->partition(util::part_refill($order_time))->edit($last_orderid, ['inner_status' => 1]);
  537. }
  538. $order->set_last_orderid($order_id);
  539. $thrid_refill = Model('thrid_refill');
  540. if($order->is_third()) {
  541. $product = $thrid_refill->getProduct(['system_code' => $order->pcode(),'opened' => 1]);
  542. $refill_amount = $product['refill_amount'];
  543. } else {
  544. $refill_amount = $order->spec();
  545. }
  546. if(empty($order->mch_order())) {
  547. $order->set_mchorder($order_sn);
  548. }
  549. $order->commit_times_inc();
  550. $orderext = $order->refill_params($order_id, $order_sn, $refill_amount, $ch_name, $ch_amount, $mch_amount);
  551. $fInsert = $mod_refill->add_refill($orderext);
  552. if($order->is_third()) {
  553. $ext = $order->third_extparams($order_id,$order_sn);
  554. $thrid_refill->addExt($ext);
  555. }
  556. if(!$fInsert) {
  557. return false;
  558. } else {
  559. return true;
  560. }
  561. }
  562. catch (Exception $ex)
  563. {
  564. Log::record($ex->getMessage(),Log::ERR);
  565. return false;
  566. }
  567. };
  568. $order_canceler = function ($order_id,$err_msg) {
  569. $logic_vr_order = Logic("vr_order");
  570. $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
  571. $logic_vr_order->changeOrderStateCancel($order_info, '', $err_msg, true, true);
  572. };
  573. try
  574. {
  575. $logic_buy_virtual = Logic('buy_virtual');
  576. $mod_refill = Model('refill_order');
  577. $input['goods_id'] = $goods_id;
  578. $input['quantity'] = $order->quantity();
  579. $input['buyer_phone'] = $minfo->mobile();
  580. $input['buyer_name'] = $minfo->truename();
  581. $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
  582. $input['order_from'] = 1;
  583. $input['pd_pay'] = true;
  584. $start = microtime(true);
  585. $result = $logic_buy_virtual->buyStep3($input, $order->buyer_id(), [$calc, 'calc_vorder_amount'], true, true);
  586. if ($result['state'] === true)
  587. {
  588. $order_sn = $result['data']['order_sn'];
  589. $order_id = $result['data']['order_id'];
  590. $last_orderid = $order->last_order_id();
  591. $fSuccess = $refill_creater($order, $last_orderid, $order_id, $order_sn, $mod_refill);
  592. if(!$fSuccess) {
  593. Log::record("refill_creater fail: order_sn=$order_sn", Log::ERR);
  594. $order_canceler($order_id,'refill_order 记录创建失败');
  595. return [false, $order_id, $order_sn];
  596. }
  597. if (!$this->pay_completed($order_sn)) {
  598. $order_canceler($order_id,'预存款不足以支付该订单');
  599. return [false, $order_id, $order_sn];
  600. }
  601. Log::record(sprintf(__METHOD__ . " request time=%.6f", microtime(true) - $start), Log::DEBUG);
  602. return [true, $order_id, $order_sn];
  603. }
  604. else
  605. {
  606. Log::record(__METHOD__ . " fail:buyStep3 err msg={$result['msg']}", Log::ERR);
  607. return [false, 0, ''];
  608. }
  609. }
  610. catch (Exception $ex)
  611. {
  612. Log::record($ex->getMessage(), Log::ERR);
  613. return [false, 0, ''];
  614. }
  615. }
  616. private function pay_completed($order_sn)
  617. {
  618. $logic_payment = Logic('payment');
  619. $order = $logic_payment->getVrOrderInfo($order_sn,'',true);
  620. $api_pay_amount = $order['data']['api_pay_amount'];
  621. return ($api_pay_amount == ncPriceFormat(0.0000));
  622. }
  623. public function notify_merchant($order_id,$manual)
  624. {
  625. if ($order_id <= 0) {
  626. return [false, "订单ID小于0"];
  627. }
  628. $mod_order = Model('vr_order');
  629. $mod_refill = Model('refill_order');
  630. if ($manual) {
  631. $part = '';
  632. } else {
  633. $part = util::part_notify();
  634. }
  635. $order_info = $mod_order->partition($part)->getOrderInfo(['order_id' => $order_id]);
  636. $refill_info = $mod_refill->partition($part)->getOrderInfo(['order_id' => $order_id,'inner_status' => 0,'is_retrying' => 0]);
  637. if (empty($order_info) || empty($refill_info)) {
  638. return [false, "无此订单"];
  639. }
  640. if($refill_info['mch_notify_times'] == 0) {
  641. $card_no = $refill_info['card_no'];
  642. $spec = $refill_info['refill_amount'];
  643. util::loop_order_dec($card_no,$spec);
  644. }
  645. //手动通知,之所以不做尝试,是担心客户方状态处理不当
  646. if (!$manual && $refill_info['mch_notify_state'] != 0) {
  647. return [false, "已经通知客户方"];
  648. }
  649. $notify_url = $refill_info['notify_url'];
  650. $order_time = intval($refill_info['order_time']);
  651. $part = util::part_refill($order_time);
  652. if (empty($notify_url)) {
  653. $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 1, 'mch_notify_times' => 0]);
  654. return [false, "回调地址为空"];
  655. }
  656. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  657. $order_state = intval($order_info['order_state']);
  658. if ($order_state !== ORDER_STATE_CANCEL && $order_state !== ORDER_STATE_SUCCESS) {
  659. return [false, "错误的订单状态,不能通知."];
  660. }
  661. $resp = $this->mPolicy->notify($order_info,$refill_info);
  662. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  663. if ($resp) {
  664. $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 1, 'mch_notify_times' => ['exp', 'mch_notify_times+1']]);
  665. return [true, ""];
  666. }
  667. else
  668. {
  669. $mod_refill->partition($part)->edit($order_id, ['mch_notify_times' => ['exp', 'mch_notify_times+1']]);
  670. $times = $refill_info['mch_notify_times'] + 1;
  671. if ($times > 100) {
  672. $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 2]);
  673. } else {
  674. $period = 5;
  675. QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false], $period);
  676. }
  677. return [false, "通知{$times}次,失败."];
  678. }
  679. }
  680. //发预回调通知消息
  681. public function notify_merchant_success($mchid, $mch_order)
  682. {
  683. $part = util::part_notify();
  684. $mod_refill = Model('refill_order');
  685. $refill_info = $mod_refill->partition($part)->getOrderInfo(['mch_order' => $mch_order,'mchid' => $mchid,'inner_status' => 0]);
  686. if(empty($refill_info)) {
  687. return [false, "refill_order table cannot find order when mchid=$mchid mch_order=$mch_order"];
  688. }
  689. $order_sn = $refill_info['order_sn'];
  690. $order_id = $refill_info['order_id'];
  691. $vr_order = Model('vr_order');
  692. $order_info = $vr_order->partition($part)->getOrderInfo(['order_sn' => $order_sn]);
  693. if (empty($order_info)) {
  694. return [false, "refill_order table cannot find order when order_sn=$order_sn."];
  695. }
  696. $resp = $this->mPolicy->notify_success($order_info,$refill_info);
  697. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  698. if ($resp) {
  699. $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 1, 'mch_notify_times' => ['exp', 'mch_notify_times+1']]);
  700. return [true, ""];
  701. }
  702. else
  703. {
  704. $mod_refill->partition($part)->edit($order_id, ['mch_notify_times' => ['exp', 'mch_notify_times+1']]);
  705. $times = $refill_info['mch_notify_times'] + 1;
  706. if ($times > 100) {
  707. $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 2]);
  708. } else {
  709. $period = 5;
  710. QueueClient::async_push("NotifyMerchantSuccess", ['mchid' => $mchid, 'mch_order' => $mch_order], $period);
  711. }
  712. return [false, "通知{$times}次,失败."];
  713. }
  714. }
  715. public function query($order_id)
  716. {
  717. $mod_order = Model('vr_order');
  718. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  719. if(empty($order_info)) return false;
  720. $mod_refill = Model('refill_order');
  721. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
  722. $chname = $refill_info['channel_name'];
  723. if ($refill_info['notify_state'] == 1 && in_array($order_info['order_state'], [ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL])) {
  724. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
  725. return true;
  726. }
  727. if($order_info['order_state'] == ORDER_STATE_SEND) {
  728. $query_able = true;
  729. }
  730. else {
  731. $query_able = false;
  732. }
  733. if($query_able)
  734. {
  735. if(empty($chname)) {
  736. Log::record("chname={$chname}", Log::DEBUG);
  737. return false;
  738. }
  739. $provider = $this->mPolicy->provider($chname);
  740. if(empty($provider)) return false;
  741. $values = $provider->query($refill_info);
  742. if (count($values) == 2) {
  743. [$state, $order_state] = $values;
  744. $official_sn = false;
  745. } else {
  746. [$state, $order_state, $official_sn] = $values;
  747. }
  748. if (!$state) {
  749. return false;
  750. } elseif ($order_state == ORDER_STATE_SUCCESS) {
  751. $this->proc_notify($order_id, true, false, $chname, $official_sn);
  752. } elseif ($order_state == ORDER_STATE_CANCEL) {
  753. $this->proc_notify($order_id, false, true, $chname, $official_sn);
  754. } else {
  755. Log::record("RefillBase::query order_state={$order_state}", Log::DEBUG);
  756. }
  757. }
  758. return true;
  759. }
  760. public function query_net($order_id)
  761. {
  762. $query_handler = function ($order_id, $order_info, $state, $order_state, $chname,$order_time)
  763. {
  764. $mod_refill = Model('refill_order');
  765. if ($order_info['order_state'] == ORDER_STATE_PAY) {
  766. $query_able = true;
  767. } else {
  768. $query_able = false;
  769. }
  770. $vr_part = util::part_vr_order(intval($order_info['add_time']));
  771. $can_try = false;
  772. if($query_able)
  773. {
  774. if(!$state) {
  775. QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],30);
  776. $neterr = true;
  777. }
  778. elseif($order_state == ORDER_STATE_SUCCESS || $order_state == ORDER_STATE_CANCEL)
  779. {
  780. $neterr = false;
  781. $logic_vr_order = Logic("vr_order");
  782. $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
  783. $data = ['commit_time' => time()];
  784. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, $data);
  785. QueueClient::async_push("QueryRefillState", ['order_id' => $order_id], 1);
  786. }
  787. elseif ($order_state == ORDER_STATE_NOEXIST) {
  788. $neterr = false;
  789. $logic_vr_order = Logic("vr_order");
  790. $logic_vr_order->changeOrderStateSend($order_id, true, $vr_part);
  791. $can_try = true;
  792. }
  793. else {
  794. $neterr = true;
  795. QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],30);
  796. }
  797. util::monitor_netchk($chname,$neterr);
  798. }
  799. return [true,$can_try];
  800. };
  801. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  802. $mod_order = Model('vr_order');
  803. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id]);
  804. if (empty($order_info) || $order_info['order_state'] != ORDER_STATE_PAY) return false;
  805. $mod_refill = Model('refill_order');
  806. $refill_info = $mod_refill->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
  807. $chname = $refill_info['channel_name'];
  808. $provider = $this->mPolicy->provider($chname);
  809. if(empty($provider)) return false;
  810. $values = $provider->query($refill_info);
  811. if (count($values) == 2) {
  812. [$state, $order_state] = $values;
  813. $official_sn = false;
  814. } else {
  815. [$state, $order_state, $official_sn] = $values;
  816. }
  817. try {
  818. $can_try = false;
  819. $tran = new trans_wapper($mod_order, 'query_net change order state trans');
  820. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id], '*', true, true);
  821. $order_time = intval($refill_info['order_time']);
  822. [$ret, $can_try] = $query_handler($order_id, $order_info, $state, $order_state, $chname,$order_time);
  823. $tran->commit();
  824. $trans_succ = true;
  825. }
  826. catch (Exception $ex) {
  827. Log::record("Error:" . $ex->getMessage(), Log::ERR);
  828. $trans_succ = false;
  829. $tran->rollback();
  830. $ret = false;
  831. }
  832. if($can_try)
  833. {
  834. if($trans_succ) {
  835. $this->proc_notify($order_id, false, true, $chname, $official_sn);
  836. } else {
  837. QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],30);
  838. }
  839. }
  840. return $ret;
  841. }
  842. public function query_timeout($mchid, $mch_order)
  843. {
  844. $has_tmout = transfer_timeout::instance()->has_tmout($mchid, $mch_order);
  845. if($has_tmout)
  846. {
  847. //标记为超时,并且预回调成功。
  848. util::push_queue_order($mchid, $mch_order, ORDER_STATE_TIMEOUT);
  849. $part = util::part_notify();
  850. $mod_refill = Model('refill_order');
  851. $refill_info = $mod_refill->partition($part)->getOrderInfo(['mch_order' => $mch_order,'mchid' => $mchid,'inner_status' => 0]);
  852. if(empty($refill_info)) {
  853. return false;
  854. }
  855. $order_id = $refill_info['order_id'];
  856. $mod_refill->partition($part)->edit($order_id, ['notify_time' => time()]);
  857. QueueClient::push("NotifyMerchantSuccess", ['mchid' => $mchid, 'mch_order' => $mch_order]);
  858. }
  859. return true;
  860. }
  861. public function query_auto($order_id,$query_times)
  862. {
  863. $perioder = function ($times)
  864. {
  865. if($times > 10) {
  866. return 300;
  867. }
  868. elseif($times > 5) {
  869. return 120;
  870. }
  871. else {
  872. return 5;
  873. }
  874. };
  875. $query_handler = function ($order_id, $order_info, $state, $order_state, $chname,$order_time,$query_times) use ($perioder)
  876. {
  877. $query_times += 1;
  878. $mod_refill = Model('refill_order');
  879. $vr_part = util::part_vr_order(intval($order_info['add_time']));
  880. $peroid = $perioder($query_times);
  881. $can_try = false;
  882. if (!$state) {
  883. QueueClient::async_push("QueryAutoRefillState", ['order_id' => $order_id, 'query_times' => $query_times], $peroid);
  884. $neterr = true;
  885. } elseif ($order_state == ORDER_STATE_SUCCESS || $order_state == ORDER_STATE_CANCEL) {
  886. $neterr = false;
  887. QueueClient::async_push("QueryRefillState", ['order_id' => $order_id], 1);
  888. } elseif ($order_state == ORDER_STATE_NOEXIST) {
  889. $neterr = false;
  890. QueueClient::async_push("QueryRefillState", ['order_id' => $order_id], 1);
  891. $can_try = true;
  892. } else {
  893. $neterr = true;
  894. QueueClient::async_push("QueryAutoRefillState", ['order_id' => $order_id, 'query_times' => $query_times], $peroid);
  895. }
  896. util::monitor_netchk($chname, $neterr);
  897. return [true, $can_try];
  898. };
  899. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  900. $mod_order = Model('vr_order');
  901. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id]);
  902. if (empty($order_info)) return false;
  903. $mod_refill = Model('refill_order');
  904. $refill_info = $mod_refill->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
  905. $chname = $refill_info['channel_name'];
  906. $provider = $this->mPolicy->provider($chname);
  907. if(empty($provider)) return false;
  908. $values = $provider->query($refill_info);
  909. if (count($values) == 2) {
  910. [$state, $order_state] = $values;
  911. $official_sn = false;
  912. } else {
  913. [$state, $order_state, $official_sn] = $values;
  914. }
  915. try {
  916. $can_try = false;
  917. $tran = new trans_wapper($mod_order, 'query_net change order state trans');
  918. $order_info = $mod_order->partition(util::part_notify())->getOrderInfo(['order_id' => $order_id], '*', true, true);
  919. $order_time = intval($refill_info['order_time']);
  920. [$ret, $can_try] = $query_handler($order_id, $order_info, $state, $order_state, $chname,$order_time,$query_times);
  921. $tran->commit();
  922. $trans_succ = true;
  923. }
  924. catch (Exception $ex) {
  925. Log::record("Error:" . $ex->getMessage(), Log::ERR);
  926. $trans_succ = false;
  927. $tran->rollback();
  928. $ret = false;
  929. }
  930. if($can_try)
  931. {
  932. if($trans_succ) {
  933. $this->proc_notify($order_id, false, true, $chname, $official_sn);
  934. } else {
  935. QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],30);
  936. }
  937. }
  938. return $ret;
  939. }
  940. public function manual_success($order_id)
  941. {
  942. $order_id = intval($order_id);
  943. if($order_id <= 0) return false;
  944. try
  945. {
  946. $mod_order = Model('vr_order');
  947. $tran = new trans_wapper($mod_order,'manual_success state trans');
  948. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id],'*',true,true);
  949. if(!empty($order_info) && in_array($order_info['order_state'],[ORDER_STATE_PAY,ORDER_STATE_SEND]))
  950. {
  951. $tran->commit();
  952. $logic_vr_order = Logic("vr_order");
  953. $logic_vr_order->changeOrderStateSuccess($order_id,true);
  954. $mod_refill = Model('refill_order');
  955. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  956. $order_time = intval($refill_info['order_time']);
  957. util::onOrderSuccess($refill_info,$order_info);
  958. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
  959. mtopcard\cards_helper::assign($order_id);
  960. util::pop_queue_order($refill_info['mchid'], $refill_info['mch_order'], $order_time);
  961. }
  962. else {
  963. $tran->commit();
  964. }
  965. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true]);
  966. return true;
  967. }
  968. catch (Exception $ex) {
  969. $tran->rollback();
  970. Log::record("manual_success exception:{$ex->getMessage()}",Log::ERR);
  971. return false;
  972. }
  973. }
  974. public function manual_cancel($order_id)
  975. {
  976. $order_id = intval($order_id);
  977. if($order_id <= 0) return false;
  978. try {
  979. $mod_order = Model('vr_order');
  980. $tran = new trans_wapper($mod_order,'manual_cancel state trans');
  981. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id],'*',true,true);
  982. if(!empty($order_info) && in_array($order_info['order_state'],[ORDER_STATE_PAY,ORDER_STATE_SEND]))
  983. {
  984. $tran->commit();
  985. $logic_vr_order = Logic("vr_order");
  986. $logic_vr_order->changeOrderStateCancel($order_info, '', "后台手动回调通知失败",true,true);
  987. $mod_refill = Model('refill_order');
  988. $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
  989. $order_time = intval($refill_info['order_time']);
  990. $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
  991. mtopcard\cards_helper::reuse($order_id);
  992. util::pop_queue_order($refill_info['mchid'], $refill_info['mch_order'], $order_time);
  993. }
  994. else {
  995. $tran->commit();
  996. }
  997. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => true]);
  998. return true;
  999. }
  1000. catch (Exception $ex) {
  1001. $tran->rollback();
  1002. Log::record("manual_cancel exception:{$ex->getMessage()}",Log::ERR);
  1003. return false;
  1004. }
  1005. }
  1006. public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no)
  1007. {
  1008. return $this->mPolicy->need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no);
  1009. }
  1010. public function region_intercept($quality,$card_type,$region_no)
  1011. {
  1012. return $this->mPolicy->region_intercept($quality,$card_type,$region_no);
  1013. }
  1014. public function UpdateMchRatios($gross,$detail,$types)
  1015. {
  1016. $this->mPolicy->update_mchratios($gross, $detail, $types);
  1017. }
  1018. public function UpdateChctl($params)
  1019. {
  1020. $this->mPolicy->update_chctl($params);
  1021. }
  1022. public function UpdateChspeed($params)
  1023. {
  1024. $this->mPolicy->update_chspeeds($params);
  1025. }
  1026. public function UpdateMaxSpeed($params)
  1027. {
  1028. $this->mPolicy->update_maxspeeds($params);
  1029. }
  1030. public function isOverChspeed($chname)
  1031. {
  1032. return $this->mPolicy->is_over_chspeed($chname);
  1033. }
  1034. }