rabin 3 vuotta sitten
vanhempi
commit
b163cd09c1

+ 54 - 22
service/agent/src/My.php

@@ -95,7 +95,12 @@ class My extends Core
             }
         }
         #获取区域分润
-        // $this->data['fenrun'] = Dever::db('mail/area_stat')->getMoney(array('mid'=>$this->uid));
+        $area = Dever::db('mail/area_stat')->find(array('mid' => $this->uid));
+        if ($area) {
+            $this->data['area'] = 1;
+        } else {
+            $this->data['area'] = 2;
+        }
         
         return $this->data;
     }
@@ -1138,31 +1143,58 @@ class My extends Core
         return Dever::load('agent/address')->del($this->uid, $id, 2);
     }
     #获取体验店和零售店区域分润
-    public function getAreastat(){
-        $data = Dever::db('mail/area_stat')->getTy(array('mid'=>$this->uid));
+    public function getAreaList()
+    {
+        $data = Dever::db('mail/area_stat')->getData(array('mid' => $this->uid));
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $data[$k] = $this->getAreaOne($v);
+            }
+        }
         return $data;
     }
+
+    private function getAreaOne($v)
+    {
+        $date = date('Y年m月', $v['month']);
+        $v['name'] = Dever::load("area/api.string", $v['name'], '') . '区域分润' . $date . '对账单';
+
+        list($year, $month, $end) = explode('-', date('Y-m-t', $v['month']));
+
+        $v['start'] = $year . '/' . $month . '/01';
+        $v['end'] = $year . '/' . $month . '/' . $end;
+
+        $v['total'] = round($v['l_cash'] + $v['t_cash'], 2);
+
+        $v['status_name'] = '已发放';
+
+        return $v;
+    }
     #获取体验店和零售店区域分润列表
-    public function getAreadesc(){
-        $type = Dever::input('type');#1=体验店,2=零售店
-        $data = array();
-        if (!$type) {
-            $type = 1;
-        }
-        $res = Dever::db('mail/area_stat')->getTy(array('mid'=>$this->uid));
-        $data['list'] = Dever::db('mail/area_stat')->getTiyan(array('mid'=>$this->uid));
-        if ($type == 1) {
-            $price = 't_fprice';
-        } else {
-            $price = 'l_fprice';
-        }
-        $data['total']= $res[$price];
-        if ($data['list']) {
-            foreach ($data['list'] as $k => $v) {
-                $data['list'][$k]['month'] = date('Y年m月',$v['month']);
-                $data['list'][$k]['price'] = $v[$price];
+    public function getAreaView()
+    {
+        $id = Dever::input('id');
+        $info = Dever::db('mail/area_stat')->find(array('mid' => $this->uid, 'id' => $id));
+        if ($info) {
+            $info = $this->getAreaOne($info);
+
+            if ($info['data']) {
+                $data = Dever::json_decode($info['data']);
+                $info['data'] = array();
+                if ($data) {
+                    foreach ($data as $k => $v) {
+                        $shop = Dever::db('shop/info')->find($k);
+                        if ($shop) {
+                            $info['data'][] = array
+                            (
+                                'name' => $shop['name'],
+                                'cash' => $v,
+                            );
+                        }
+                    }
+                }
             }
         }
-        return $data;
+        return $info;
     }
 }

+ 2 - 2
service/mail/database/area_entry.php

@@ -111,8 +111,8 @@ return array
                 'state' => 1,
             ),
             
-            'type' => 'one',
-            'col' => 'sum(buy) as total',
+            'type' => 'all',
+            'col' => '*',
         ),
     ),
 );

+ 16 - 18
service/mail/database/area_stat.php

@@ -182,6 +182,15 @@ return array
             'list'      => true,
         ),
 
+        'data'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '明细数据',
+            'default'   => '',
+            'desc'      => '明细数据',
+            'match'     => 'is_string',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -240,7 +249,7 @@ return array
             # 允许自定义以上配置
             'config' => true,
         ),
-        'getMoney' => array
+        'getOne' => array
         (
             # 匹配的正则或函数 选填项
             'option' => array
@@ -248,22 +257,11 @@ return array
                 'mid' => 'yes',
                 'state' => 1,
             ),
-            'type' => 'one',
-            'col' => 'sum(price) as  price',
-        ),
-        'getTy' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'mid' => 'yes',
-                'state' => 1,
-            ),
-            'type' => 'one',
-            'group' => 'mid',
-            'col' => 'sum(t_fprice) as t_fprice,sum(l_fprice) as l_fprice',
+            'type' => 'count',
+            'col' => '*',
         ),
-        'getTiyan' => array
+
+        'getData' => array
         (
             # 匹配的正则或函数 选填项
             'option' => array
@@ -272,9 +270,9 @@ return array
                 'state' => 1,
             ),
             'type' => 'all',
-            'order' => array('month'=>'desc'),
+            'order' => array('month' => 'desc', 'id' => 'desc'),
             'page' => array(20, 'list'),
-            'col' => 't_fprice,l_fprice,month',
+            'col' => '*',
         ),
     ),
 );

+ 28 - 13
service/mail/lib/Manage.php

@@ -682,15 +682,20 @@ class Manage
     }
 
     # 体验店毛利:采购价-成本价
-    public function t_buy($where, $shop_id)
+    public function t_buy($where, $shop_id, $per)
     {
         $where['type_id'] = $shop_id;
         $where['status'] = '5,6';
         $order = Dever::db('shop/buy_order')->getNewAll($where);
         $total = 0;
+        $shop = array();
         
         if ($order) {
             foreach($order as $k => $v) {
+                if (!isset($shop[$v['shop_id']])) {
+                    $shop[$v['shop_id']] = 0;
+                }
+                
                 $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
                 $c_price = 0;
                 foreach($order_goods as $k1 => $v1){
@@ -699,21 +704,29 @@ class Manage
                         $c_price += $goods['c_price'] * $v1['num'];
                     }
                 }
-                $total += ($v['price'] - $c_price);
+                $price = ($v['price'] - $c_price);
+                $total += $price;
+                $shop[$v['shop_id']] += round($price * $per, 2);
             }
         }
         
-        return $total;
+        return array(round($total, 2), round($total*$per, 2), $shop);
     }
     # 零售店毛利
-    public function l_buy($where, $shop_id)
+    public function l_buy($where, $shop_id, $per)
     {
         $where['shop_id'] = $shop_id;
         $data = Dever::db('mail/area_entry')->getBuy($where);
-        if ($data && $data['total']) {
-            return $data['total'];
+        $total = 0;
+        $shop = array();
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $price = $v['buy'];
+                $total += $price;
+                $shop[$v['shop_id']] += round($price * $per, 2);
+            }
         }
-        return 0;
+        return array(round($total, 2), round($total*$per, 2), $shop);
     }
 
     # 区域分润
@@ -764,6 +777,7 @@ class Manage
             }
 
             $area_id = array();
+            $shop_data = array();
             foreach ($area as $k => $v) {
                 $update = array();
                 $update['month'] = $month;
@@ -776,16 +790,16 @@ class Manage
                     if ($k1 == 1) {
                         # 体验店
                         $update['t_num'] = count($v1);
-                        $update['t_buy'] = $this->t_buy($where, $v1);
-                        if ($update['t_buy'] > 0) {
-                            $update['t_cash'] = $update['t_buy'] * $config[$v['type']];
+                        list($update['t_buy'], $update['t_cash'], $shop_data) = $this->t_buy($where, $v1, $config[$v['type']]);
+                        if ($shop_data) {
+                            $update['data'] += $shop_data;
                         }
                     } elseif ($k1 == 2) {
                         # 零售店
                         $update['l_num'] = count($v1);
-                        $update['l_buy'] = $this->l_buy($where, $v1);
-                        if ($update['l_buy'] > 0) {
-                            $update['l_cash'] = $update['l_buy'] * $config[$v['type']];
+                        list($update['l_buy'], $update['l_cash'], $shop_data) = $this->l_buy($where, $v1, $config[$v['type']]);
+                        if ($shop_data) {
+                            $update['data'] += $shop_data;
                         }
                     }
                 }
@@ -813,6 +827,7 @@ class Manage
                     $update['mid'] = $member['id'];
                 }
 
+                $update['data'] = Dever::json_encode($update['data']);
                 if (!$info) {
                     $stat_id = Dever::db('mail/area_stat')->insert($update);
                 } else {