123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <?php
- class lzrefillControl extends lzbaseControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function goodsOp()
- {
- $result = refill\RefillFactory::instance()->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_order($this->mchid(), $mch_order, ORDER_STATE_QUEUE);
- Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
- $ret = refill\util::push_add($params);
- if ($ret) {
- return self::outsuccess($this->merchant_available);
- } else {
- refill\util::del_queue_order($this->mchid(),$mch_order);
- Model('refill_order')->del_detail($this->mchid(),$mch_order);
- 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
- ];
-
- refill\util::push_queue_order($this->mchid(), $mch_order, ORDER_STATE_QUEUE);
- Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
- $ret = refill\util::push_addthird($params);
- if($ret) {
- return self::outsuccess($this->merchant_available);
- }
- else {
- refill\util::del_queue_order($this->mchid(),$mch_order);
- Model('refill_order')->del_detail($this->mchid(),$mch_order);
- 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->exist($mchid, $mch_order);
- return ($ret == false);
- }
- }
- 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);
- }
- $order_state = refill\util::query_queue_order($mchid,$order_sn);
- if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
- Log::record("query_state in queue mchid={$mchid} mch_order={$order_sn} order_state={$order_state}" ,Log::DEBUG);
- $state = 0;
- $msg = "{$order_sn}-充值中";
- $remark = "";
- $content = "|{$state}|{$msg}|{$remark}";
- echo $content;
- $this->query_request($mchid,$order_sn);
- return true;
- }
- else
- {
- $mod_refill = Model('refill_order');
- $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
- if(empty($refill_info))
- {
- Log::record("query_state in db no order mchid={$mchid} mch_order={$order_sn}" ,Log::DEBUG);
- $state = 3;
- $msg = "{$order_sn}-无此订单";
- $remark = "";
- $content = "|{$state}|{$msg}|{$remark}";
- echo $content;
- return true;
- }
- else
- {
- $vr_order = Model('vr_order');
- $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
- $order_state = $order_info['order_state'];
- Log::record("query_state in db mchid={$mchid} mch_order={$order_sn} order_state={$order_state}" ,Log::DEBUG);
- if ($order_state == ORDER_STATE_CANCEL) {
- $state = 2;
- $msg = "{$order_sn}-充值失败";
- $remark = "";
- }
- elseif($order_state == ORDER_STATE_SUCCESS) {
- $state = 1;
- $msg = "{$order_sn}-充值成功";
- $remark = "{$refill_info['official_sn']}";
- }
- else {
- $state = 0;
- $msg = "{$order_sn}-充值中";
- $remark = "";
- }
- if($refill_info['card_type'] == mtopcard\ThirdRefillCard) {
- $remark = $this->third_remark($refill_info);
- }
- $content = "|{$state}|{$msg}|{$remark}";
- echo $content;
- return true;
- }
- }
- }
- private function query_request($mchid,$order_sn)
- {
- $mod_refill = Model('refill_order');
- $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
- if(!empty($refill_info))
- {
- $vr_order = Model('vr_order');
- $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
- if(!empty($order_info) && $order_info['order_state'] == ORDER_STATE_SEND) {
- QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
- }
- }
- }
- 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;
- }
- }
|