Pārlūkot izejas kodu

member card stats

ayHaru 4 gadi atpakaļ
vecāks
revīzija
ee708b6cac
2 mainītis faili ar 65 papildinājumiem un 10 dzēšanām
  1. 5 0
      helper/vrorder_helper.php
  2. 60 10
      test/TestMemberCard.php

+ 5 - 0
helper/vrorder_helper.php

@@ -66,4 +66,9 @@ class vrorder_helper
             }
         }
     }
+
+    public static function get_order($condition){
+        $vr_order = Model('vr_order');
+        return $vr_order->getOrderList($condition);
+    }
 }

+ 60 - 10
test/TestMemberCard.php

@@ -182,6 +182,7 @@ class TestMemberCard extends TestCase
 
     public function testAddMemberYearCard()
     {
+        global $config;
         $finder = function () {
             $mid_amounts = [];
             $path = BASE_DATA_PATH . "/cards/memcard.txt";
@@ -193,9 +194,10 @@ class TestMemberCard extends TestCase
 
             while(!feof($file)) {
                 $line = fgets($file);
+                $line = str_replace("\r\n", '',$line);
                 $kv = preg_split('/,/',$line);
-                if(count($kv) != 2) continue;
-                $mid_amounts[] = ['mid' => intval($kv[0]),'amount' => intval($kv[1])];
+                if(count($kv) != 3) continue;
+                $mid_amounts[] = ['mid' => intval($kv[0]),'start_time' => strtotime($kv[1]),'end_time' => strtotime($kv[2])];
             }
             fclose($file);
 
@@ -203,20 +205,68 @@ class TestMemberCard extends TestCase
         };
 
         $mids = $finder();
+        $spec_card = $config['vgoods_spec_card'];
         foreach ($mids as $val)
         {
-            $usercards = new mcard\user_mcards($val['mid']);
-            $params = mcard\getConfig('year',$val['amount']);
-            $ret = $usercards->addCard($params);
-            if($ret) {
-                Log::record("{$val['mid']} : {$val['amount']} success.",Log::DEBUG);
-            } else {
-                Log::record("{$val['mid']} : {$val['amount']} fail.",Log::ERR);
+            $condition['buyer_id'] = $val['mid'];
+            $condition['add_time'] = ['between',[$val['start_time'],$val['end_time']]];
+            $vrorder_helper = new \vrorder_helper();
+            $orders = $vrorder_helper->get_order($condition);
+            if(empty($orders)){
+                $result[$val['mid']] = [];
             }
+            foreach ($orders as $item){
+                $goods_id  = intval($item['goods_id']);
+                $amount = $spec_card[$goods_id];
+                $extra_info = json_decode($item['extra_info'],true);
+
+                $card_no   = $extra_info['input']['card_no'];
+                $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
+                if($card_type == 1 || $card_type == 2){
+                    $data[$card_type]['type'] = $card_type;
+                    $data[$card_type]['amount'] += $amount * $item['goods_num'];
+                }elseif($card_type == 3){
+                    $PhoneLocation = $this->GetPhoneLocation($card_no);
+                    $data[$card_type]['type'] = $card_type;
+                    $data[$card_type]['amount'] += $amount * $item['goods_num'];
+//                    $phoneData['catName'] = $PhoneLocation['catName'];
+//                    $phoneData['card_no'] = $card_no;
+//                    $phoneData['amount']  = $amount * $item['goods_num'];
+                    $phoneData[$card_no]['catName'] = $PhoneLocation['catName'];
+                    $phoneData[$card_no]['card_no'] = $card_no;
+                    $phoneData[$card_no]['amount']  += $amount * $item['goods_num'];
+                    $data[$card_type]['phoneData'] = $phoneData;
+                }
+            }
+            $result[$val['mid']] = $data;
+            return $result;
+//            if($ret) {
+//                Log::record("{$val['mid']} : {$val['amount']} success.",Log::DEBUG);
+//            } else {
+//                Log::record("{$val['mid']} : {$val['amount']} fail.",Log::ERR);
+//            }
         }
     }
 
-    public function testAddMemberCard4Hg()
+    /**
+     * 根据手机号获取收运营商信息
+     * @param $phone
+     * @return array|bool
+     */
+    private function GetPhoneLocation($phone)
+    {
+        if (empty($phone)) return false;  //手机号不能为空
+        $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel={$phone}";
+        $response = file_get_contents($url);  //获取API返回的数据
+        $list = mb_convert_encoding($response, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'); //解决中文乱码
+        //解决返回数据格式问题
+        $res = trim(explode('=', $list)[1]);
+        preg_match_all("/(\w+):'([^']+)/", $res, $m);
+        $res = array_combine($m[1], $m[2]);
+        return $res;
+    }
+
+        public function testAddMemberCard4Hg()
     {
         $mids = [62704,52836];
         foreach ($mids as $mid) {