Parcourir la source

add merchant_refill and update merchantweb

ayHaru il y a 4 ans
Parent
commit
f548fe8080
2 fichiers modifiés avec 119 ajouts et 0 suppressions
  1. 114 0
      mobile/control/merchant_refill.php
  2. 5 0
      mobile/control/merchantweb.php

+ 114 - 0
mobile/control/merchant_refill.php

@@ -0,0 +1,114 @@
+<?php
+
+require_once(BASE_ROOT_PATH . '/mobile/control/merchantweb.php');
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+
+class merchant_refillControl extends mbMerchantControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function goodsOp(){
+        $goods = refill\RefillFactory::instance()->goods();
+        $oil_amount = $phone_amount = [];
+        foreach ($goods as $key => $value){
+            if($key == 'sinopec' || $key == 'petrochina'){
+                foreach ($value as $amount){
+                    if(!in_array($amount,$oil_amount)){
+                        $oil_amount[] = $amount;
+                    }
+                }
+            }
+            if($key == 'chinamobile' || $key == 'chinaunicom' || $key == 'chinatelecom'){
+                foreach ($value as $amount){
+                    if(!in_array($amount,$phone_amount)){
+                        $phone_amount[] = $amount;
+                    }
+                }
+            }
+        }
+        $result['oil_amount'] = $oil_amount;
+        $result['phone_amount'] = $phone_amount;
+        return self::outsuccess($result);
+    }
+
+    private function check_params($params)
+    {
+        if(empty($params['cardno'])) {
+            return [false,'参数没有包含cardno'];
+        }
+        if(empty($params['amount'])) {
+            return [false,'参数没有包含充值金额:amount'];
+        }
+
+        $card_no = $params['cardno'];
+        $card_type = mtopcard\card_type($card_no);
+
+        if($card_type == mtopcard\UnknownCard) {
+            return [false,"充值卡不是电话和中石油中石化类型."];
+        }
+
+        if($card_type === mtopcard\PetroChinaCard)
+        {
+            if(empty($params['idcard'])) {
+                return [false,'中石油需要参数没有包含身份证号码:idcard'];
+            }
+            if(empty($params['card_name'])) {
+                return [false,'参数没有包含身份证姓名:card_name'];
+            }
+        }
+
+        $card_type = mtopcard\card_type($card_no);
+        if($card_type === mtopcard\UnknownCard) {
+            return [false,'卡类型无法识别'];
+        }
+
+        return [true,""];
+    }
+
+    public function addOp(){
+        $params = $_GET;
+
+        $amount = intval($_GET['amount']);
+        $card_no = trim($_GET['cardno']);
+        $card_no = explode(',' , $card_no);
+        if(empty($card_no)){
+            return self::outerr(errcode::ErrParamter, "卡号格式错误或未上传");
+        }
+        //成功个数、失败个数
+        $success_no = $error_no = 0;
+        $data = [];
+        $all_no = count($card_no);
+        foreach ($card_no as $no){
+            $params['cardno'] = $no;
+            [$success,$error] = $this->check_params($params);
+
+            if($success === false) {
+                $error_no++;
+                $arr['state'] = 201;
+                $arr['err'] = $error;
+            }else{
+                [$state,$err] = refill\RefillFactory::instance()->add($this->mchid(),$this->adminid(),$amount,$no,'','');
+                $arr['state'] = $state;
+                $arr['err'] = $err;
+                if($state === true) {
+                    $success_no++;
+                }
+                else {
+                    $error_no++;
+                }
+            }
+            $arr['card_no'] = $no;
+            $arr['amount'] = $amount;
+            $data[] = $arr;
+        }
+        $result['success_no'] = $success_no;
+        $result['error_no'] = $error_no;
+        $result['all_no'] = $all_no;
+        $result['data'] = $data;
+        return self::outsuccess($result);
+    }
+}

+ 5 - 0
mobile/control/merchantweb.php

@@ -156,4 +156,9 @@ class mbMerchantControl extends merchantwebControl
     {
         return intval($_SESSION['mchid']);
     }
+
+    public function adminid()
+    {
+        return intval($_SESSION['member_id']);
+    }
 }