rabin 3 years ago
parent
commit
4662f4e2cf
1 changed files with 16 additions and 11 deletions
  1. 16 11
      service/agent/lib/Tool.php

+ 16 - 11
service/agent/lib/Tool.php

@@ -769,21 +769,26 @@ class Tool
     # 根据身份证号获取购买次数
     public function buy_api()
     {
-        $data = Dever::db('agent/order')->fetchAll('select mobile, role, name, idcard, price from churen_agent_order where status = 4 and state = 1 and idcard is not null order by idcard desc');
+        $data = Dever::db('agent/order')->fetchAll('select idcard, count(*) as num from churen_agent_order where status = 4 and state = 1 and idcard is not null group by idcard order by num desc');
 
         $head = array('姓名', '手机号', '身份证号', '角色', '金额');
-        $body = array();
+        $result = array();
         if ($data) {
             foreach ($data as $k => $v) {
-                $role = Dever::db('setting/role')->find($v['role']);
-                $body[] = array
-                (
-                    $v['name'],
-                    $v['mobile'],
-                    $v['idcard'],
-                    $role['name'],
-                    $v['price'],
-                );
+                if ($v['num'] > 1) {
+                    $order = Dever::db('agent/order')->select(array('idcard' => $v['idcard']));
+                    foreach ($order as $k1 => $v1) {
+                        $role = Dever::db('setting/role')->find($v1['role']);
+                        $body[] = array
+                        (
+                            $v1['name'],
+                            $v1['mobile'],
+                            $v1['idcard'],
+                            $role['name'],
+                            $v1['price'],
+                        );
+                    }
+                }
             }
         }