rabin 3 سال پیش
والد
کامیت
bdc74b47f0

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

@@ -965,6 +965,7 @@ $config = array
                 'end' => array('yes-fdate', '<='),
                 'area' => array('yes', 'like'),
                 'type' => 1,
+                'type_id' => array('yes', 'in'),
                 'status' => array('yes', 'in'),
                 'state' => 1,
                 'parent_type' => array('yes','in'),

+ 1 - 1
service/agent/database/member.php

@@ -1042,7 +1042,7 @@ return array
             # 匹配的正则或函数 选填项
             'option' => array
             (
-                'area' => array('yes','='),
+                'area' => 'yes',
                 'role' => 'yes',
                 'state' => 1,
             ),

+ 8 - 105
service/mail/database/area_entry.php

@@ -1,14 +1,5 @@
 <?php
-$shop = function()
-{
-    $array = array();
-    $data = Dever::db('shop/info-state');
-    if($data)
-    {
-        $array += $data;
-    }
-    return $array;
-};
+
 return array
 (
     # 表名
@@ -44,22 +35,10 @@ return array
             'match'     => 'is_numeric',
             'desc'      => '',
             'update'    => 'month',
-            'search'    => 'day',
+            'search'    => 'month',
             'list'      => 'date("Y-m", {month})',
         ),
 
-     //    'area'       => array
-	    // (
-	    //     'type'      => 'varchar-500',
-	    //     'name'      => '区域',
-	    //     'default'   => '',
-	    //     'desc'      => '区域',
-	    //     'match'     => 'option',
-	    //     'update'    => 'linkage',
-	    //     'list'      => 'Dever::load("area/api.string", "{area}")',
-     //        'option'    => Dever::url('api.get?level_total=4', 'area'),
-	    // ),
-
         'shop_id'      => array
         (
             'type'      => 'int-11',
@@ -67,7 +46,8 @@ return array
             'default'   => '',
             'desc'      => '店铺名称',
             'match'     => 'is_numeric',
-            'option'    => $shop,
+            'update'    => 'select',
+            'update_search' => 'shop/lib/manage.search_shop',
             'search'    => array
             (
                 'api' => 'shop/info-like',
@@ -79,30 +59,7 @@ return array
             'list_order' => 2,
         ),
 
-        'sid'      => array
-        (
-            'type'      => 'varchar-30',
-            'name'      => '店铺编号-一般为5位数字,不能重复',
-            'default'   => '',
-            'desc'      => '店铺编号',
-            'match'     => 'is_string',
-            'update'    => 'text',
-            # 绑定js脚本,更新时使用,第一个参数是执行的方式,第二个参数执行的方法,第三个参数是传值。
-            'bind'        => array('onblur', 'loading', array('url' => Dever::url("shop/lib/record.search"))),
-        ),
-
-        'num'      => array
-        (
-            'type'      => 'decimal-11',
-            'name'      => '店铺数量',
-            'default'   => '0',
-            'desc'      => '店铺数量',
-            'match'     => 'is_numeric',
-            // 'update'    => 'text',
-            // 'list'      => true,
-        ),
-
-        'cprice'      => array
+        'buy'      => array
         (
             'type'      => 'decimal-11,2',
             'name'      => '毛利',
@@ -114,18 +71,6 @@ return array
             'list_order' => 4,
         ),
 
-        'price'      => array
-        (
-            'type'      => 'decimal-11,2',
-            'name'      => '分润金额',
-            'default'   => '0',
-            'desc'      => '分润金额',
-            'match'     => 'is_numeric',
-            // 'update'    => 'text',
-            // 'list'      => true,
-            'list_order' => 5,
-        ),
-
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -154,61 +99,19 @@ return array
 
     'request' => array
     (
-        'getNewAll' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'start' => array('yes-month','>='),
-                'end' => array('yes-month','<='),
-                // 'area' => array('yes','like'),
-                'state' => 1,
-            ),
-            
-            'type' => 'all',
-            'col' => '*',
-        ),
-        'getAll' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'start' => array('yes-month','>='),
-                'end' => array('yes-month','<='),
-                // 'area' => array('yes','like'),
-                'state' => 1,
-            ),
-            
-            'type' => 'all',
-            'col' => 'id,area',
-        ),
-        'getNum' => array
-        (
-            # 匹配的正则或函数 选填项
-            'option' => array
-            (
-                'start' => array('yes-month','>='),
-                'end' => array('yes-month','<='),
-                'area' => array('yes','like'),
-                'state' => 1,
-            ),
-            
-            'type' => 'one',
-            'col' => 'sum(num) as num',
-        ),
-        'getPrice' => array
+        'getBuy' => array
         (
             # 匹配的正则或函数 选填项
             'option' => array
             (
                 'start' => array('yes-month','>='),
                 'end' => array('yes-month','<='),
-                'area' => array('yes','like'),
+                'shop_id' => array('yes','in'),
                 'state' => 1,
             ),
             
             'type' => 'one',
-            'col' => 'sum(cprice) as cprice',
+            'col' => 'sum(buy) as total',
         ),
     ),
 );

+ 67 - 79
service/mail/database/area_stat.php

@@ -1,4 +1,18 @@
 <?php
+
+$status = array
+(
+    1 => '已确认',
+    2 => '未确认',
+);
+
+$cash_status = array
+(
+    1 => '已发放',
+    2 => '未发放',
+);
+
+
 return array
 (
     # 表名
@@ -61,66 +75,31 @@ return array
             'match'     => 'is_numeric',
         ),
 
-        'mid'      => array
-        (
-            'type'      => 'int-11',
-            'name'      => '收益代理商姓名/电话',
-            'default'   => '-1',
-            'desc'      => '代理商',
-            'match'     => 'is_string',
-            // 'update'    => 'text',
-            'search'    => array
-            (
-                'api' => 'agent/member-getSearch',
-                'col' => 'col',
-                'result' => 'id',
-                'search' => 'mid',
-            ),
-            'list_name' => '收益代理商',
-            'list'      => 'Dever::load("mail/lib/manage.area_member", {id})',
-            'list_order' => 15,
-        ),
-
-        'mobile'      => array
-        (
-            'type'      => 'bigint-11',
-            'name'      => '代理商手机号',
-            'default'   => '',
-            'desc'      => '请输入手机号',
-            'match'     => Dever::rule('mobile'),
-            'update'    => 'text',
-            # 绑定js脚本,更新时使用,第一个参数是执行的方式,第二个参数执行的方法,第三个参数是传值。
-            'bind'        => array('onblur', 'loading', array('url' => Dever::url("lib/soft_cash.search", 'agent'))),
-            //'search'    => 'fulltext',
-            //'list'      => true,
-        ),
-
-        'num'      => array
+        't_cash'      => array
         (
-            'type'      => 'decimal-11',
-            'name'      => '店铺数量',
+            'type'      => 'decimal-11,2',
+            'name'      => '体验店分润金额',
             'default'   => '0',
-            'desc'      => '店铺数量',
+            'desc'      => '体验店分润金额',
             'match'     => 'is_numeric',
-            'update'    => 'text',
-            // 'list'      => true,
+            // 'update'    => 'text',
+            'list'      => true,
         ),
 
-        'c_price'      => array
+        'l_cash'      => array
         (
             'type'      => 'decimal-11,2',
-            'name'      => '采购金额',
+            'name'      => '零售店分润金额',
             'default'   => '0',
-            'desc'      => '采购金额',
+            'desc'      => '零售店分润金额',
             'match'     => 'is_numeric',
             // 'update'    => 'text',
-            // 'list'      => true,
-            // 'list_order' => 4,
+            'list'      => true,
         ),
 
         't_num'      => array
         (
-            'type'      => 'decimal-11',
+            'type'      => 'int-11',
             'name'      => '体验店数量',
             'default'   => '0',
             'desc'      => '体验店数量',
@@ -129,70 +108,79 @@ return array
             'list'      => true,
         ),
 
-        't_price'      => array
+        'l_num'      => array
         (
-            'type'      => 'decimal-11,2',
-            'name'      => '体验店采购金额',
+            'type'      => 'int-11',
+            'name'      => '零售店数量',
             'default'   => '0',
-            'desc'      => '体验店采购金额',
+            'desc'      => '零售店数量',
             'match'     => 'is_numeric',
             // 'update'    => 'text',
             'list'      => true,
         ),
-        't_fprice'      => array
+
+        't_buy'      => array
         (
             'type'      => 'decimal-11,2',
-            'name'      => '体验店分润金额',
+            'name'      => '体验店采购毛利',
             'default'   => '0',
-            'desc'      => '体验店分润金额',
+            'desc'      => '体验店采购毛利',
             'match'     => 'is_numeric',
             // 'update'    => 'text',
-            // 'list'      => true,
+            'list'      => true,
         ),
 
-        'price'      => array
+        'l_buy'      => array
         (
             'type'      => 'decimal-11,2',
-            'name'      => '分润金额',
+            'name'      => '零售店采购毛利',
             'default'   => '0',
-            'desc'      => '分润金额',
+            'desc'      => '零售店采购毛利',
             'match'     => 'is_numeric',
-            'update'    => 'text',
+            // 'update'    => 'text',
             'list'      => true,
-            'list_order' => 5,
         ),
 
-        'l_num'      => array
+        'mid'      => array
         (
-            'type'      => 'decimal-11',
-            'name'      => '零售店数量',
-            'default'   => '0',
-            'desc'      => '零售店数量',
-            'match'     => 'is_numeric',
+            'type'      => 'int-11',
+            'name'      => '收益代理商姓名/电话',
+            'default'   => '-1',
+            'desc'      => '代理商',
+            'match'     => 'is_string',
             // 'update'    => 'text',
-            'list'      => true,
+            'search'    => array
+            (
+                'api' => 'agent/member-getSearch',
+                'col' => 'col',
+                'result' => 'id',
+                'search' => 'mid',
+            ),
+            'list_name' => '收益代理商',
+            'list'      => 'Dever::load("mail/lib/manage.area_member", {id})',
+            'list_order' => 15,
         ),
 
-        'l_price'      => array
+        'status'        => array
         (
-            'type'      => 'decimal-11,2',
-            'name'      => '零售店采购金额',
-            'default'   => '0',
-            'desc'      => '零售店采购金额',
+            'type'      => 'int-11',
+            'name'      => '确认状态',
+            'default'   => '2',
+            'desc'      => '确认状态',
             'match'     => 'is_numeric',
-            // 'update'    => 'text',
+            'option'    => $status,
             'list'      => true,
         ),
 
-        'l_fprice'      => array
+        'cash_status'        => array
         (
-            'type'      => 'decimal-11,2',
-            'name'      => '零售店分润金额',
-            'default'   => '0',
-            'desc'      => '零售店分润金额',
+            'type'      => 'int-11',
+            'name'      => '发放状态',
+            'default'   => '2',
+            'desc'      => '发放状态',
             'match'     => 'is_numeric',
-            // 'update'    => 'text',
-            // 'list'      => true,
+            'option'    => $cash_status,
+            'list'      => true,
         ),
 
         'state'     => array

+ 183 - 49
service/mail/lib/Manage.php

@@ -681,68 +681,146 @@ class Manage
         return Dever::excelExport($body, $header, $file);
     }
 
-    #采购价-成本价
-    public function caigou($where){
-        $data = Dever::db('shop/buy_order')->getNewAll($where);
-        $res = array();
-        $money = 0;
-        $res['money'] = 0;
-        if($data && isset($data['price']) && $data['price']){
-            $res['price'] = $data['price'];
-        }else{
-            $res['price'] = 0;
-        }
+    # 体验店毛利:采购价-成本价
+    public function t_buy($where, $shop_id)
+    {
+        $where['type_id'] = $shop_id;
+        $where['status'] = '5,6';
+        $order = Dever::db('shop/buy_order')->getNewAll($where);
+        $total = 0;
         
-        foreach($data as $k => $v){
-            // $goods_id,$skuid
-            $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
-            $c_price = 0;
-            foreach($order_goods as $k1 => $v1){
-                $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
-                if($goods['c_price'] && $goods['c_price'] >= 0){
-                    $c_price += $goods['c_price'] * $v1['num'];
+        if ($order) {
+            foreach($order as $k => $v) {
+                $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+                $c_price = 0;
+                foreach($order_goods as $k1 => $v1){
+                    $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
+                    if($goods['c_price'] && $goods['c_price'] >= 0){
+                        $c_price += $goods['c_price'] * $v1['num'];
+                    }
                 }
+                $total += ($v['price'] - $c_price);
             }
-            $res['money'] += ($v['price'] - $c_price);
         }
-        return $res;
+        
+        return $total;
     }
-    #零售
-    public function ls($where,$type=false){
-        $shop = Dever::db('mail/area_entry')->getNewAll($where);
-        $data = array();
-        $data['price'] = 0;
-        foreach($shop as $k => $v){
-            if ($type == 1) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
-            } elseif ($type == 2) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
-            } elseif ($type == 3) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
-            }
-            
-        }
-        foreach($shop as $k => $v){
-            if(!$v['shop']){
-                unset($shop[$k]);
-            }
-        }
-        foreach($shop as $k=>$v){
-            $data['price'] +=$v['cprice'];
+    # 零售店毛利
+    public function l_buy($where, $shop_id)
+    {
+        $where['shop_id'] = $shop_id;
+        $data = Dever::db('mail/area_entry')->getBuy($where);
+        if ($data && $data['total']) {
+            return $data['total'];
         }
-        $data['num'] = count($shop);
-        return $data;
+        return 0;
     }
-    #区域分润
-    public function area_api(){
+
+    # 区域分润
+    public function area_api()
+    {
+        /*
         $month = Dever::input('month', date('Y-m'));
         $start_time = $month .'-01 00:00:00';
         $where = array();
         $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
         $where['start'] = Dever::maketime($start_time);
         $where['end'] = Dever::maketime($end_time);
-        $where['state'] = 1;
-        
+        */
+
+        # 设置利润计算规则:
+        $config = array
+        (
+            1 => 0.01,
+            2 => 0.03,
+            3 => 0.05,
+        );
+        # 传入day,获取月开始和月结束日期
+        list($where['start'], $where['end']) = Dever::month();
+
+        # 获取区域
+        $area = array();
+        $shop = Dever::db('shop/info')->select();
+        if ($shop) {
+            foreach ($shop as $k => $v) {
+                if ($v['type'] != 10) {
+                    if ($v['city'] > 0) {
+                        $key = $v['province'] . ',' . $v['city'];
+                        $area[$key]['shop_id'][$v['type']][] = $v['id'];
+                        $area[$key]['type'] = 1;
+                    }
+                    if ($v['county'] > 0) {
+                        $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'];
+                        $area[$key]['shop_id'][$v['type']][] = $v['id'];
+                        $area[$key]['type'] = 2;
+                    }
+                    if ($v['town'] > 0) {
+                        $key = $v['province'] . ',' . $v['city'] . ',' . $v['county'] . ',' . $v['town'];
+                        $area[$key]['shop_id'][$v['type']][] = $v['id'];
+                        $area[$key]['type'] = 3;
+                    }
+                }
+            }
+
+            foreach ($area as $k => $v) {
+                $update = array();
+                $update['month'] = $where['start'];
+                $update['name'] = $k;
+                $info = Dever::db('mail/area_stat')->find($update);
+
+                # 设置金额
+                $update['t_num'] = $update['l_num'] = $update['t_cash'] = $update['l_cash'] = $update['t_buy'] = $update['l_buy'] = 0;
+                foreach ($v['shop_id'] as $k1 => $v1) {
+                    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']];
+                        }
+                    } 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']];
+                        }
+                    }
+                }
+
+                if ($update['t_buy'] == 0 && $update['l_buy'] == 0) {
+                    continue;
+                }
+
+                # 设置上级id,用来做列表层级展示
+                if ($v['type'] == 1) {
+                    $update['parent_id'] = -1;
+                } elseif ($v['type'] == 2) {
+                    $update['parent_id'] = $city_id;
+                } elseif ($v['type'] == 3) {
+                    $update['parent_id'] = $county_id;
+                }
+
+                # 设置收益代理商
+                $member = Dever::db('agent/member')->getAreaAll(array('area' => $k));
+                if ($member) {
+                    $update['mid'] = $member['id'];
+                }
+
+                if (!$info) {
+                    $stat_id = Dever::db('mail/area_stat')->insert($update);
+                    if ($v['type'] == 1) {
+                        $city_id = $stat_id;
+                    } elseif ($v['type'] == 2) {
+                        $county_id = $stat_id;
+                    }
+                } else {
+                    $update['where_id'] = $info['id'];
+                    Dever::db('mail/area_stat')->update($w);
+                }
+            }
+        }
+        /*
         $data = array();
         $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
         foreach($data as $k => $v){
@@ -929,8 +1007,64 @@ class Manage
                 }
             }
         }
+        */
         return 'ok';
     }
+
+    /*
+    #采购价-成本价
+    public function caigou($where){
+        $data = Dever::db('shop/buy_order')->getNewAll($where);
+        $res = array();
+        $money = 0;
+        $res['money'] = 0;
+        if($data && isset($data['price']) && $data['price']){
+            $res['price'] = $data['price'];
+        }else{
+            $res['price'] = 0;
+        }
+        
+        foreach($data as $k => $v){
+            // $goods_id,$skuid
+            $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            $c_price = 0;
+            foreach($order_goods as $k1 => $v1){
+                $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
+                if($goods['c_price'] && $goods['c_price'] >= 0){
+                    $c_price += $goods['c_price'] * $v1['num'];
+                }
+            }
+            $res['money'] += ($v['price'] - $c_price);
+        }
+        return $res;
+    }
+    #零售
+    public function ls($where,$type=false){
+        $shop = Dever::db('mail/area_entry')->getNewAll($where);
+        $data = array();
+        $data['price'] = 0;
+        foreach($shop as $k => $v){
+            if ($type == 1) {
+                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
+            } elseif ($type == 2) {
+                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
+            } elseif ($type == 3) {
+                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
+            }
+            
+        }
+        foreach($shop as $k => $v){
+            if(!$v['shop']){
+                unset($shop[$k]);
+            }
+        }
+        foreach($shop as $k=>$v){
+            $data['price'] +=$v['cprice'];
+        }
+        $data['num'] = count($shop);
+        return $data;
+    }
+    */
     // public function area_api(){
     //     #零售店的采购金额*0.4
     //     $month = Dever::input('month', date('Y-m'));