dever 3 vuotta sitten
vanhempi
commit
b9cc789043

+ 1 - 1
app/shop/database/buy_order.php

@@ -284,7 +284,7 @@ $struct = array
     (
         'type'      => 'int-11',
         'name'      => '退款数量',
-        'default'   => '',
+        'default'   => '0',
         'desc'      => '退款数量',
         'match'     => 'is_numeric',
     ),

+ 2 - 2
app/shop/database/sell_order.php

@@ -354,7 +354,7 @@ return array
         (
             'type'      => 'int-11',
             'name'      => '退款数量',
-            'default'   => '',
+            'default'   => '0',
             'desc'      => '退款数量',
             'match'     => 'is_numeric',
         ),
@@ -830,7 +830,7 @@ return array
                 'state' => 1,
             ),
             'type' => 'all',
-            'col' => 'id,order_num,mobile,shop_id,cdate,sum(price-refund_cash) as total,sum(num-refund_num) as num',
+            'col' => 'id,order_num,mobile,shop_id,cdate,price-refund_cash as total,num-refund_num as num',
         ),
 
         # 获取订单数量

+ 5 - 4
app/shop/database/user_rank_stat.php

@@ -37,7 +37,7 @@ $config = array
                     'week' => '按周',
                     'month' => '按月',
                 ),
-                'group' => 'day',
+                'group' => 'day,mobile',
             ),
             'order'     => 'desc',
             'list'      => 'Dever::showDay("{day}")',
@@ -117,7 +117,7 @@ $config = array
             'desc'      => '环比增长',
             'match'     => 'option',
             'update'    => 'text',
-            'list'      => 'Dever::load("shop/lib/manage.getUserRankHb", "{num}", "{time}")',
+            'list'      => 'Dever::load("shop/lib/manage.getUserRankHb", "{num}", "{mobile}", "{time}")',
         ),
 
         'state'     => array
@@ -169,7 +169,7 @@ $config = array
             'type' => 'all',
             'order' => array('time' => 'desc', 'cdate' => 'desc'),
             'page' => array(20, 'list'),
-            'group' => 'day',
+            'group' => 'day,mobile',
             'col' => '*,min(day) as time, sum(cash) as cash, sum(num) as num',
         ),
 
@@ -179,6 +179,7 @@ $config = array
             'option' => array
             (
                 'day' => array('yes-day', '<'),
+                'mobile' => 'yes',
                 //'start_day' => array('yes-day', '>='),
                 //'end_day' => array('yes-day', '<='),
                 'state' => 1,
@@ -186,7 +187,7 @@ $config = array
             'order' => array('time' => 'desc', 'id' => 'desc'),
             'type' => 'one',
             'col' => '*,min(day) as time, sum(cash) as cash, sum(num) as num',
-            'group' => 'day',
+            'group' => 'day,mobile',
             # 允许自定义以上配置
             'config' => true,
         ),

+ 34 - 48
app/shop/lib/Cron.php

@@ -489,63 +489,49 @@ class Cron
         $w['end'] = $end;
         $w['status'] = '2,3,4,5,6';
         $data = Dever::db('shop/sell_order')->getAllByDate($w);
-        print_r($data);die;
 
         if ($data) {
             $where = array();
+            $result = array();
             foreach ($data as $k => $v) {
                 $day = Dever::maketime(date('Y-m-d 00:00:00', $v['cdate']));
-                $where['shop_id'] = $v['shop_id'];
-                $where['day'] = $day;
-                $where['clear'] = true;
-                $info = Dever::db('shop/shop_stat')->find($where);
 
-                if (!$info) {
-                    $up = $where;
-                    $up['num'] = $v['num'];
-                    $up['cash'] = $v['total'];
-                    Dever::db('shop/shop_stat')->insert($up);
-                } else {
-                    
+                $key = $v['shop_id'] . '_' . $day . '_' . $v['mobile'];
+                if (!isset($result[$key])) {
+                    $result[$key] = array();
+                    $result[$key]['num'] = 0;
+                    $result[$key]['cash'] = 0;
                 }
-            }
-        }
-
-        $shop = Dever::db('shop/info')->select();
-
-        foreach ($shop as $k => $v) {
-            $where = array();
-            $where['status'] = '2,3,4,5,6';
-            $where['shop_id'] = $v['id'];
-            for($i=0; $i<=$day; $i++) {
-                $where['start'] = $start + 86400*$i;
-                $where['end'] = $start + 86400*$i + 86399;
-                $data = array();
-                $data['shop_id'] = $v['id'];
-                $data['day'] = $where['start'];
-                $info = Dever::db('shop/shop_stat')->find($data);
-                $cash = Dever::db('shop/sell_order')->getCashNum($where);
-                $data['sell_cash'] = round($cash['total'], 2);
-                $data['sell_num'] = Dever::db('shop/sell_order')->getOrderNum($where);
-                
-                $where['type'] = 1;
-                $where['type_id'] = $v['id'];
-                $cash = Dever::db('shop/buy_order')->getCashNum($where);
-                $data['buy_cash'] = round($cash['total'], 2);
-                $data['buy_num'] = Dever::db('shop/buy_order')->getOrderNum($where);
 
-                $data['sl_num'] = 0;
+                $result[$key]['num'] += $v['num'];
+                $result[$key]['cash'] = $v['total'];
+            }
 
-                $data['area'] = $v['area'];
-                $data['province'] = $v['province'];
-                $data['city'] = $v['city'];
-                $data['county'] = $v['county'];
-                $data['town'] = $v['town'];
-                if (!$info) {
-                    Dever::db('shop/shop_stat')->insert($data);
-                } else {
-                    $data['where_id'] = $info['id'];
-                    Dever::db('shop/shop_stat')->update($data);
+            if ($result) {
+                foreach ($result as $k => $v) {
+                    $temp = explode('_', $k);
+
+                    $where['shop_id'] = $temp[0];
+                    $where['day'] = $temp[1];
+                    $where['mobile'] = $temp[2];
+                    $where['clear'] = true;
+                    $info = Dever::db('shop/user_rank_stat')->find($where);
+
+                    $up = array();
+                    if (!$info) {
+                        $up = $where;
+                        $shop = Dever::db('shop/info')->one($where['shop_id']);
+                        $up['area'] = $shop['area'];
+                        $up['num'] = $v['num'];
+                        $up['cash'] = $v['cash'];
+                        Dever::db('shop/user_rank_stat')->insert($up);
+                    } else {
+                        $up = array();
+                        $up['where_id'] = $info['id'];;
+                        $up['num'] = $v['num'];
+                        $up['cash'] = $v['cash'];
+                        Dever::db('shop/user_rank_stat')->update($up);
+                    }
                 }
             }
         }

+ 2 - 2
app/shop/lib/Manage.php

@@ -573,9 +573,9 @@ class Manage
     }
 
     # 获取环比增长
-    public function getUserRankHb($num, $day)
+    public function getUserRankHb($num, $mobile, $day)
     {
-        $where = array('day' => $day);
+        $where = array('day' => $day, 'mobile' => $mobile);
         $search = Dever::search_button();
         if ($search) {
             $where['config']['group'] = $search[0];