goods(); $sorter = function (array $items) { $ret = []; foreach ($items as $key => $val) { sort($val); $ret[$key] = $val; } return $ret; }; $result = $sorter($result); return self::outsuccess($result); } private function check_params($params) { if(empty($params['mob'])) { return -9; } if(empty($params['amt'])) { return -9; } $card_no = $params['mob']; if(empty($card_no)) { return -11; } if(empty($params['notifyurl'])) { return -9; } if(empty($params['ord'])) { return -9; } if(empty($params['tim'])) { return -9; } $tim = strtotime($params['tim']); if($tim === false) { return -9; } $cur = time(); $start = strtotime(date('Y-m-d',$cur - 1800)); if($tim < $start || $tim > $cur + 1800) { return -9; } return true; } public function add_mobOp() { $code = $this->check_params($_GET); if($code !== true) { return self::outerr($code,$this->merchant_available); } $amount = intval($_GET['amt']); $card_no = $_GET['mob']; $notify_url = $_GET['notifyurl']; $mch_order = $_GET['ord']; //对方的order编号 $quality = $_GET['quality'] ?? 0; //此处判断是对的 if($amount > $this->member_available) { return self::outerr(4,$this->merchant_available); } if(!$this->check_mchorder($this->mchid(),$mch_order)) { return self::outerr(11,$this->merchant_available); } // if(!$this->can_refill($card_no)) { // return self::outerr(10,$this->merchant_available); // } $params = [ 'mchid' => $this->mchid(), 'buyer_id' => $this->adminid(), 'amount' => $amount, 'card_no' => $card_no, 'mch_order' => $mch_order, 'notify_url' => $notify_url, 'org_quality' => $quality ]; refill\util::push_queue($this->mchid(),$mch_order,time()); $ret = refill\util::push_add($params); if($ret) { return self::outsuccess($this->merchant_available); } else { return self::outerr(-6,$this->merchant_available); } } private function check_third($params) { if(empty($params['product_code'])) { Log::record("check_third product_code",Log::ERR); return -9; } $pcode = $params['product_code']; if($this->check_pcode($pcode) == false) { Log::record("check_third check_pcode",Log::ERR); return -10; } if(empty($params['quantity']) || intval($params['quantity']) < 1) { Log::record("check_third quantity",Log::ERR); return -9; } $card_no = $params['mob']; if(empty($card_no)) { Log::record("check_third mob",Log::ERR); return -9; } $third_card_type = $params['card_type']; if(empty($third_card_type)) { Log::record("check_third card_type",Log::ERR); return -9; } if(empty($params['notifyurl'])) { Log::record("check_third notifyurl",Log::ERR); return -9; } if(empty($params['ord'])) { Log::record("check_third ord",Log::ERR); return -9; } if(empty($params['tim'])) { Log::record("check_third tim",Log::ERR); return -9; } $tim = strtotime($params['tim']); if($tim === false) { Log::record("check_third strtotime tim",Log::ERR); return -9; } $cur = time(); $start = strtotime(date('Y-m-d',$cur - 1800)); if($tim < $start || $tim > $cur + 1800) { Log::record("check_third check tim",Log::ERR); return -9; } return true; } private function check_pcode($pcode) { $mod_third = Model('thrid_refill'); $product = $mod_third->getProduct(['system_code' => $pcode]); return !empty($product); } public function add_thirdOp() { $code = $this->check_third($_GET); if($code !== true) { return self::outerr($code,$this->merchant_available); } $amount = refill\util::ThirdRefillAmount; $mch_order = $_GET['ord']; $notify_url = $_GET['notifyurl']; //三方充值没有质量 $quality = 1; $card_type = mtopcard\ThirdRefillCard; $product_code = $_GET['product_code']; $card_no = $_GET['mob']; $quantity = $_GET['quantity']; $third_card_type = $_GET['card_type']; //此处判断是对的 if($this->member_available <= 0) { return self::outerr(4,$this->merchant_available); } if(!$this->check_mchorder($this->mchid(),$mch_order)) { return self::outerr(11,$this->merchant_available); } $params = [ 'mchid' => $this->mchid(), 'buyer_id' => $this->adminid(), 'amount' => $amount, 'mch_order' => $mch_order, 'notify_url' => $notify_url, 'org_quality' => $quality, 'card_type' => $card_type, 'card_no' => $card_no, 'product_code' => $product_code, 'quantity' => $quantity, 'third_card_type' => $third_card_type ]; $ret = refill\util::push_addthird($params); if($ret) { return self::outsuccess($this->merchant_available); } else { return self::outerr(-6,$this->merchant_available); } } private function can_refill($cardno) { $card_info = refill\util::read_card($cardno); if(empty($card_info)) return false; return intval($card_info['black_card']) === 0; } private function check_mchorder($mchid,$mch_order) { if(empty($mch_order)) { return false; } else { $refill_order = Model('refill_order'); $ret = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]); return empty($ret); } } public function balanceOp() { $uid = $this->adminid(); $minfo = new member_info($uid); $available = $minfo->available_predeposit(); $content = "0|".ncPriceFormat($available)."|0.00"; echo $content; return true; } public function queryOp() { $mchid = $this->mchid(); $order_sn = $_GET['ord']; //用户方的订单号,对应数据库中的mch_order if(empty($order_sn)) { return self::outerr(-9,$this->merchant_available); } $mod_refill = Model('refill_order'); $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]); if(empty($refill_info)) { $state = 3; $msg = "{$order_sn}-无此订单"; $remark = ""; $content = "|{$state}|{$msg}|{$remark}"; echo $content; return true; } if(empty($refill_info)) { $ret = refill\util::query_queue($mchid,$order_sn); if ($ret > 0) { $state = 0; $msg = "{$order_sn}-充值中"; $remark = ""; $content = "|{$state}|{$msg}|{$remark}"; echo $content; return true; } else { $state = 3; $msg = "{$order_sn}-无此订单"; $remark = ""; $content = "|{$state}|{$msg}|{$remark}"; echo $content; return true; } } $vr_order = Model('vr_order'); $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]); if($refill_info['is_retrying']) { QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]); $state = 0; $msg = "{$order_sn}-充值中"; $remark = ""; } else { $order_state = $order_info['order_state']; if($order_state == ORDER_STATE_SEND || $order_state == ORDER_STATE_PAY || $order_state == ORDER_STATE_NEW) { QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]); $state = 0; $msg = "{$order_sn}-充值中"; $remark = ""; } elseif($order_state == ORDER_STATE_CANCEL) { $state = 2; $msg = "{$order_sn}-充值失败"; $remark = ""; } else { $state = 1; $msg = "{$order_sn}-充值成功"; $remark = "{$refill_info['official_sn']}"; } } if($refill_info['card_type'] == mtopcard\ThirdRefillCard) { $remark = $this->third_remark($refill_info); } $content = "|{$state}|{$msg}|{$remark}"; echo $content; return true; } private function third_remark($refill_info) { $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $this->mchid()]); $mod_third = Model('thrid_refill'); $thrid_info = $mod_third->getThird($refill_info['order_id']); $secure_key = $mchinfo['secure_key']; $remark = ''; if (!empty($thrid_info)) { $card_info = $thrid_info['card_info']; if (!empty($card_info)) { $encrypt = openssl_encrypt($card_info,'AES-128-CBC',$secure_key); if($encrypt != false) { $remark = $encrypt; } } } return $remark; } }