Your Name 2 years ago
parent
commit
9a62a24a49

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

@@ -913,6 +913,23 @@ $config = array
             'order' => array('cdate' => 'desc'),
             'col' => '*',
         ),
+         # 区域查询
+        'getSerachMoney' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'area' => array('yes', 'like'),
+                'type' => 1,
+                'type_id' => array('yes','in'),
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(price) as total',
+        ),
     ),
 );
 

+ 42 - 0
app/shop/database/info.php

@@ -824,5 +824,47 @@ return array
             'order' => array('reorder' => 'desc', 'id' => 'desc'),
             'col' => 'id,id as value, name',
         ),
+        'getAreaAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'city' => 'yes',
+                'county' => 'yes',
+                'town' => 'yes',
+                'type' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => 'id,province,city,county,town',
+        ),
+        'getSerachNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'city' => 'yes',
+                'county' => 'yes',
+                'town' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
+        'getSerachTNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'city' => 'yes',
+                'county' => 'yes',
+                'town' => 'yes',
+                'type' => 1,
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
     ),
 );

+ 182 - 0
service/mail/database/area_stat.php

@@ -0,0 +1,182 @@
+<?php
+return array
+(
+    # 表名
+    'name' => 'area_stat',
+    # 显示给用户看的名称
+    'lang' => '区域分润管理统计',
+    'order' => 79,
+    'menu' => 'agent',
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'month'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '月份',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            '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}")',
+	    ),
+
+        'mid'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '收益代理商',
+            'default'   => '-1',
+            'desc'      => '代理商',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => array
+            (
+                'api' => 'agent/member-find',
+                'col' => 'mobile',
+                'result' => 'id',
+                'search' => 'mid',
+            ),
+            'list_name' => '收益代理商',
+            'list'      => 'Dever::load("mail/lib/manage.area_member", {id})',
+            'list_order' => 10,
+        ),
+
+        'num'      => array
+        (
+            'type'      => 'decimal-11',
+            'name'      => '店铺数量',
+            'default'   => '0',
+            'desc'      => '店铺数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'c_price'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '采购金额',
+            'default'   => '0',
+            'desc'      => '采购金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+            'list_order' => 4,
+        ),
+
+        't_num'      => array
+        (
+            'type'      => 'decimal-11',
+            'name'      => '体验店数量',
+            'default'   => '0',
+            'desc'      => '体验店数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        't_price'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '体验店采购金额',
+            'default'   => '0',
+            'desc'      => '体验店采购金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        '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',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '统计时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'delete' => false,
+        'edit' => false,
+        'excel' => true,
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'mid' => 'yes',
+                'state' => 1,
+            ),
+            'order' => array('id' => 'desc'),
+            'page' => array(10, 'list'),
+            'type' => 'all',
+            'col' => '*',
+        ),
+
+        'prev' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'month' => array('yes-month', '<'),
+                'mid' => 'yes',
+                'state' => 1,
+            ),
+            'order' => array('time' => 'desc', 'id' => 'desc'),
+            'type' => 'one',
+            'col' => '*,min(month) as time, sum(num) as num',
+            # 允许自定义以上配置
+            'config' => true,
+        ),
+    ),
+);

+ 126 - 0
service/mail/lib/Manage.php

@@ -573,4 +573,130 @@ class Manage
         $data['total_price'] = $data['a_price'] + $data['a_noprice'];
         return Dever::render('soft_cash', $data);
     }
+    #区域分润
+    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;
+        
+        $data = array();
+        $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
+        foreach($shop as $k=>$v){
+            $data[$v['city']]=$v;
+        }
+        $data = array_values($data);
+        foreach($data as $k => $v){
+            $w['month'] = $where['start'];
+            #街道
+            if($v['town']>0){
+                $where['area'] = $v['town'];
+                $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
+                $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
+                $mid = Dever::db('agent/member')->getAreaAll($where);
+                $data[$k]['towns']['mid'] = $mid['id'];
+                $whe['town'] = $v['town'];
+                $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
+                #体验店
+                $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
+                $data[$k]['towns']['type'] = array_column($t_shop,'id');
+                $where['type_id'] = implode(',',$data[$k]['towns']['type']);
+                $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['towns']['t_num'] = Dever::db('shop/info')->getSerachTNum($where);
+                $w['mid'] = $data[$k]['towns']['mid'];
+                $w['area'] = $data[$k]['towns']['area'];
+                $w['price'] = $data[$k]['towns']['price'];
+                $w['num'] = $data[$k]['towns']['num'];
+                $w['c_price'] = $data[$k]['towns']['money']['total'];
+                $w['t_num'] = $data[$k]['towns']['t_num'];
+                $w['t_price'] = $data[$k]['towns']['t_price']['total'];
+                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
+                if(!$shop){
+                    Dever::db('mail/area_stat')->insert($w);
+                }else{
+                    $w['where_id'] = $shop['id'];
+                    Dever::db('mail/area_stat')->update($w);
+                }
+            }
+            #区县
+            if($v['county']>0){
+                $where['area'] = $v['county'];
+                $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
+                $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
+                $mid = Dever::db('agent/member')->getAreaAll($where);
+                $data[$k]['countys']['mid'] = $mid['id'];
+                $wh['county'] = $v['county'];
+                $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
+                // #体验店
+                $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
+                $data[$k]['countys']['type'] = array_column($t_shop,'id');
+                $where['type_id'] = implode(',',$data[$k]['countys']['type']);
+                $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['countys']['t_num'] = Dever::db('shop/info')->getSerachTNum($where);
+
+                $w['mid'] = $data[$k]['countys']['mid'];
+                $w['area'] = $data[$k]['countys']['area'];
+                $w['price'] = $data[$k]['countys']['price'];
+                $w['num'] = $data[$k]['countys']['num'];
+                $w['c_price'] = $data[$k]['countys']['money']['total'];
+                $w['t_num'] = $data[$k]['countys']['t_num'];
+                $w['t_price'] = $data[$k]['countys']['t_price']['total'];
+                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
+                if(!$shop){
+                    Dever::db('mail/area_stat')->insert($w);
+                }else{
+                    $w['where_id'] = $shop['id'];
+                    Dever::db('mail/area_stat')->update($w);
+                }
+            }
+            #城市
+            if($v['city']>0){
+                $where['area'] = $v['city'];
+                $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
+                $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
+                $mid = Dever::db('agent/member')->getAreaAll($where);
+                $w['citys']['area'] = $v['city'];
+                $data[$k]['citys']['mid'] = $mid['id'];
+                $where['city'] = $v['city'];
+                $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
+                #体验店
+                $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
+                $data[$k]['citys']['type'] = array_column($t_shop,'id');
+                $where['type_id'] = implode(',',$data[$k]['citys']['type']);
+                $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                $data[$k]['citys']['t_num'] = Dever::db('shop/info')->getSerachTNum($where);
+                $w['mid'] = $data[$k]['citys']['mid'];
+                $w['area'] = $data[$k]['citys']['area'];
+                $w['price'] = $data[$k]['citys']['price'];
+                $w['c_price'] = $data[$k]['citys']['money']['total'];
+                $w['num'] = $data[$k]['citys']['num'];
+                $w['t_num'] = $data[$k]['citys']['t_num'];
+                $w['t_price'] = $data[$k]['citys']['t_price']['total'];
+                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
+                if(!$shop){
+                    Dever::db('mail/area_stat')->insert($w);
+                }else{
+                    $w['where_id'] = $shop['id'];
+                    Dever::db('mail/area_stat')->update($w);
+                }
+            } 
+        }
+        return 'ok';
+    }
+    public function area_member($id){
+        $info = Dever::db('mail/area_stat')->find($id);
+        if($info['mid']){
+            $member = Dever::db('agent/member')->find($info['mid']);
+            $res = $member['name'].'<br/>'.$member['mobile'];
+        }else{
+            $res = '-';
+        }
+        return $res;
+    }
 }