rabin před 3 roky
rodič
revize
8415b9d289
2 změnil soubory, kde provedl 23 přidání a 34 odebrání
  1. 2 1
      app/shop/database/sell_order_goods.php
  2. 21 33
      app/shop/lib/Cron.php

+ 2 - 1
app/shop/database/sell_order_goods.php

@@ -303,7 +303,8 @@ return array
                 ),
                 ),
             ),
             ),
             'type' => 'one',
             'type' => 'one',
-            'col' => 'id,sum(t_1.price*t_1.num) as cash,sum(t_1.num) as num',
+            'group' => 't_2.shop_id, t_1.goods_id',
+            'col' => 'id,t_2.shop_id, t_1.goods_id,sum(t_1.price*t_1.num) as cash,sum(t_1.num) as num',
         ),
         ),
     ),
     ),
 );
 );

+ 21 - 33
app/shop/lib/Cron.php

@@ -420,40 +420,28 @@ class Cron
         $end = Dever::maketime($end . ' 23:59:59');
         $end = Dever::maketime($end . ' 23:59:59');
         $day = intval(($end - $start)/86400);
         $day = intval(($end - $start)/86400);
 
 
-        $shop = Dever::db('shop/info')->select();
+        for($i=0; $i<=$day; $i++) {
+            $where['start'] = $start + 86400*$i;
+            $where['end'] = $start + 86400*$i + 86399;
+            $num = Dever::db('shop/sell_order_goods')->getNum($where);
+            $data['cash'] = $data['num'] = 0;
+            if ($num) {
+                $data = array();
+                $data['shop_id'] = $num['shop_id'];
+                $data['goods_id'] = $num['goods_id'];
+                $data['day'] = $where['start'];
+                $info = Dever::db('shop/goods_stat')->find($data);
 
 
-        foreach ($shop as $k => $v) {
-            $where['shop_id'] = $v['id'];
-            $goods = Dever::db('shop/goods')->select(array('shop_id' => $v['id']));
-            if ($goods) {
-                foreach ($goods as $k1 => $v1) {
-                    $where['goods_id'] = $v1['goods_id'];
-                    $goods_info = Dever::db('goods/info')->one($v1['goods_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['goods_id'] = $v1['goods_id'];
-                        $data['day'] = $where['start'];
-                        $info = Dever::db('shop/goods_stat')->find($data);
-                        $num = Dever::db('shop/sell_order_goods')->getNum($where);
-                        $data['cash'] = $data['num'] = 0;
-                        if ($num) {
-                            $data['cash'] = round($num['cash'], 2);
-                            $data['num'] = round($num['num'], 2);
-                        }
-                        if ($data['num'] > 0) {
-                            $data['area'] = $v['area'];
-                            $data['category'] = $goods_info['category'];
-                            if (!$info) {
-                                Dever::db('shop/goods_stat')->insert($data);
-                            } else {
-                                $data['where_id'] = $info['id'];
-                                Dever::db('shop/goods_stat')->update($data);
-                            }
-                        }
-                    }
+                $data['area'] = $v['area'];
+                $data['category'] = $goods_info['category'];
+                $data['cash'] = round($num['cash'], 2);
+                $data['num'] = round($num['num'], 2);
+
+                if (!$info) {
+                    Dever::db('shop/goods_stat')->insert($data);
+                } else {
+                    $data['where_id'] = $info['id'];
+                    Dever::db('shop/goods_stat')->update($data);
                 }
                 }
             }
             }
         }
         }