Your Name 2 years ago
parent
commit
37b7405516

+ 43 - 42
app/shop/database/record.php

@@ -44,12 +44,12 @@ $manage_status = array
     2 => '已审核',
     3 => '已作废',
 );
-$fafang_status = array
-(
-    //1 => '待审核',
-    2 => '已发放',
-    3 => '已作废',
-);
+// $fafang_status = array
+// (
+//     //1 => '待审核',
+//     2 => '已发放',
+//     3 => '已作废',
+// );
 $col = Dever::input('col');
 $list_button = array();
 $list_button['list'] = array('查看明细', '"record&project=shop&id={id}&page_type=1"');
@@ -236,31 +236,31 @@ $config = array
             'list_order'  => 20,
             'show'      => 'audit=3',
         ),
-        'fafang'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '审核状态',
-            'default'   => '2',
-            'desc'      => '审核状态',
-            'match'     => 'is_numeric',
-            'update'    => $col ? 'radio' : false,
-            'option'    => $fafang_status,
-            'mul'       => true,
-            'control'   => 'fafang',
-        ),
+        // 'fafang'        => array
+        // (
+        //     'type'      => 'int-11',
+        //     'name'      => '审核状态',
+        //     'default'   => '2',
+        //     'desc'      => '审核状态',
+        //     'match'     => 'is_numeric',
+        //     'update'    => $col ? 'radio' : false,
+        //     'option'    => $fafang_status,
+        //     'mul'       => true,
+        //     'control'   => 'fafang',
+        // ),
 
-        'fafang_desc'      => array
-        (
-            'type'      => 'varchar-600',
-            'name'      => '备注',
-            'default'   => '',
-            'desc'      => '审核说明',
-            'match'     => 'is_string',
-            'update'    => $col ? 'textarea' : false,
-            // 'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
-            // 'list_order'  => 20,
-            'show'      => 'fafang=3',
-        ),
+        // 'fafang_desc'      => array
+        // (
+        //     'type'      => 'varchar-600',
+        //     'name'      => '备注',
+        //     'default'   => '',
+        //     'desc'      => '审核说明',
+        //     'match'     => 'is_string',
+        //     'update'    => $col ? 'textarea' : false,
+        //     // 'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
+        //     // 'list_order'  => 20,
+        //     'show'      => 'fafang=3',
+        // ),
         'operdate'     => array
         (
             'type'      => 'int-11',
@@ -284,18 +284,18 @@ $config = array
             // 'place'     => '759*562',
         ),
 
-        'fpic'       => array
-        (
-            'type'      => 'text-255',
-            'name'      => '发放凭证',
-            'default'   => '',
-            'desc'      => '多张图片',
-            'match'     => 'is_string',
-            'update'    => $col ? 'images' : false,
-            'key'       => '1',
-            // 'place'     => '759*562',
-            'show'      => 'fafang=2',
-        ),
+        // 'fpic'       => array
+        // (
+        //     'type'      => 'text-255',
+        //     'name'      => '发放凭证',
+        //     'default'   => '',
+        //     'desc'      => '多张图片',
+        //     'match'     => 'is_string',
+        //     'update'    => $col ? 'images' : false,
+        //     'key'       => '1',
+        //     // 'place'     => '759*562',
+        //     'show'      => 'fafang=2',
+        // ),
 
         'state'     => array
         (
@@ -345,6 +345,7 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('cdate'=>'desc'),
+            'page' => array(10,'list'),
             'col' => 'id,shop_id,price,yue,type,status,cdate',
         ),
         'getSearch' => array

+ 62 - 14
app/shop/lib/Record.php

@@ -40,7 +40,7 @@ class Record
     	$ids = Dever::db('shop/record')->insert($where);
 
         $update['where_id'] = $shop_id;
-        $update['set_price'] = $cash;
+        $update['set_price'] = $yue;
         Dever::db('shop/info')->upCash($update);
     	return $ids;
     }
@@ -59,6 +59,8 @@ class Record
             	}
             	$where['price'] = 0;
             	$insert['yue'] = $shop['price'];
+
+            	$insert['type_id'] = Dever::load('bill/lib/tixian')->up($shop['id'], $info['price'], $info['price'], $info['pic'], 2,$id);
             }
             Dever::db('shop/info')->upCash($where);
             $ids = Dever::db('shop/info')->find(array('sid'=>$info['sid'],'s'=>1));
@@ -110,6 +112,10 @@ class Record
                     	
                 		$yue = $shop['price'] + $where['price'];
                 		Dever::db('shop/record')->update(array('where_id' => $id, 'yue'=>$yue,'status' => 2, 'operdate' => time()));
+                		$tixian = Dever::db('bill/tixian')->find($info['type_id']);
+                		if($tixian){
+                			Dever::db('bill/tixian')->update(array('where_id'=>$tixian['id'],'status'=>1));
+                		}
                     }else{
                     	$where['price'] = $info['price'];
                     	Dever::db('shop/record')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
@@ -212,8 +218,8 @@ class Record
             		array('审核时间', $operdate),
 	                array('审核状态', $audit_name),
 	                array('备注', $info['audit_desc']),
-	                array('发放状态', $f_name),
-	                array('备注', $info['fafang_desc']),
+	                // array('发放状态', $f_name),
+	                // array('备注', $info['fafang_desc']),
             	),
             	array
             	(
@@ -223,7 +229,7 @@ class Record
         );
         }
         $button = array();
-        if($info['type'] == 2){
+        if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
         	$purl = Dever::url('project/database/update?project=shop&table=record&where_id='.$info['id'].'&status=1&col=id,audit,audit_desc', 'manage');
         	if($info['audit'] == 1){
         		$button[] = array
@@ -232,17 +238,59 @@ class Record
 	                'link' => $purl,
 	                'name' => '审核',
 	            );
-        	}
-        	if($info['audit'] == 2 && $info['fafang'] == 1){
-        		$purl = Dever::url('project/database/update?project=shop&table=record&where_id='.$info['id'].'&status=1&col=id,fafang,fafang_desc,fpic', 'manage');
-        		$button[] = array
-	            (
-	                'type' => 'edit',
-	                'link' => $purl,
-	                'name' => '发放',
-	            );
-        	} 
+            }
+        }
+        if ($info['type'] == 2) {
+        	$tixian = Dever::db('bill/tixian')->find($info['type_id']);
+        	// print_R($tixian);die;
+            if ($tixian) {
+                $config = Dever::db('bill/tixian')->config['set'];
+                $status = $config['status'][$tixian['status']];
+
+                if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit1', '发放')) {
+                    if ($info['status'] == 2 && $tixian['status'] == 1) {
+                        $button[] = array
+                        (
+                            'type' => 'edit',
+                            'link' => Dever::url('project/database/update?project=bill&table=tixian&where_id='.$tixian['id'].'&col=audit,audit_desc,pic&oper_save_jump=tixian&oper_table=tixian&oper_parent=tixian', 'manage'),
+                            'name' => '发放',
+                        );
+                    }
+                }
+                if ($tixian['status']) {
+                    if ($tixian['operdate']) {
+                        $opertime = date('Y-m-d H:i', $tixian['operdate']);
+                    } else {
+                        $opertime = '';
+                    }
+                    $pic = '';
+                    if ($tixian['pic']) {
+                        $temp = explode(',', $tixian['pic']);
+                        foreach ($temp as $k => $v) {
+                            $pic .= '<a href="'.Dever::pic($v).'" target="_blank"><img src="'.Dever::pic($v).'" width="150" /></a>';
+                        }
+                    }
+                    $result['发放信息'] = array
+                    (
+                        'type' => 'info',
+                        'content' => array
+                        (
+                            array
+                            (
+                                array('发放时间', $opertime),
+                                array('发放状态', $status),
+                                array('备注', $tixian['audit_desc']),
+                            ),
+                            array
+                            (
+                                array('凭证', $pic),
+                            ),
+                        )
+                    );
+                }
+            }
         }
+       
         $head = array
         (
             'name' => '基本资料',

+ 42 - 1
app/shop/lib/Refund.php

@@ -212,6 +212,10 @@ class Refund
                     # 已发货不退配送费
                     $cash -= $data['ps_cash'];
                 }
+                #新加
+                if(isset($data['record_cash']) && $data['record_cash']>0){
+                    $re_cash = $data['record_cash'];
+                }
             }
 
             $cash = round($cash, 2);
@@ -506,6 +510,43 @@ class Refund
                     $rorder['status'] = $update['status'];
                 }
                 Dever::load('cash/lib/order')->up($rorder, 2, 2, $rinfo, 3);
+            }elseif (isset($order['record_cash']) && $order['record_cash'] && $order['record_cash'] > 0) {
+                # 还原资金账户
+                if ($re_cash > 0) {
+                    $record_cash = $re_cash;
+                } else {
+                    $record_cash = $order['record_cash'];
+                }
+                
+                if ($re_cash > 0) {
+                    $record_cash = $order['record_cash'] - $re_cash;
+                    $order['record_cash'] = $re_cash;
+
+                    Dever::db($this->order_table)->update(array('where_id' => $order['id'], 'record_cash' => $record_cash, 'clear' => true));
+                }
+                $record = Dever::db('shop/record')->find(array('type_id'=>$info['order_id'],'shop_id'=>$order['type_id']));
+                $shop = Dever::db('shop/info')->find(array('id'=>$order['type_id']));
+                if($shop && $record){
+                    if(!$shop['price']){
+                        $shop['price'] = 0;
+                    }
+                    $price = $shop['price'] + $info['re_cash'];
+                    $explan = '订单退货返还';
+                    Dever::load('shop/lib/record')->pingtai($shop['id'],$shop['sid'],3,$info['order_id'],$info['re_cash'],$price,$explan);
+                }
+                $rorder = $order;
+                $rinfo = $info;
+                $rorder['type'] = 1;
+                $rorder['type_id'] = $rorder['type_id'];
+                $rorder['source_type'] = 4;
+                $rorder['source_id'] = -1;
+                $rorder['num'] = $info['num'];
+                $rinfo['cash'] = $rorder['price'] = $record_cash;
+                $rinfo['p_cash'] = $rorder['p_price'] = $order['record_cash'];
+                if (isset($update['status'])) {
+                    $rorder['status'] = $update['status'];
+                }
+                Dever::load('cash/lib/order')->up($rorder, 2, 2, $rinfo, 3);
             }
 
             if ($cash && isset($order['source_id']) && $order['source_id'] && $order['source_id'] > 0) {
@@ -613,7 +654,7 @@ class Refund
             if (!$result) {
                 # 退款失败,抛出错误
                 //throw new \Exception('退款失败');
-                Dever::alert('退款失败,请联系管理员');
+                // Dever::alert('退款失败,请联系管理员');
             }
         }
         

+ 1 - 1
service/bill/lib/Manage.php

@@ -251,7 +251,7 @@ class Manage
                 $cash = Dever::db('bill/cash')->find($v['cash_id']);
             } elseif ($v['type'] == 2) {
                 $cash = Dever::db('shop/record')->find($v['cash_id']);
-            } elseif ($v['type'] == 3 {
+            } elseif ($v['type'] == 3) {
                 $cash = Dever::db('shop/user_money')->find($v['cash_id']);
             }
             

+ 214 - 0
service/mail/database/area_entry.php

@@ -0,0 +1,214 @@
+<?php
+$shop = function()
+{
+    $array = array();
+    $data = Dever::db('shop/info-state');
+    if($data)
+    {
+        $array += $data;
+    }
+    return $array;
+};
+return array
+(
+    # 表名
+    'name' => 'area_entry',
+    # 显示给用户看的名称
+    'lang' => '区域分润录入',
+    'order' => 79,
+    'menu' => 'agent',
+    'end' => array
+    (
+        'insert' => 'mail/lib/manage.updateArea_entry', 
+    ),
+    # 数据结构
+    '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'      => '',
+            'update'    => 'month',
+            'search'    => 'day',
+            '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',
+            'name'      => '店铺名称/店铺编号',
+            'default'   => '',
+            'desc'      => '店铺名称',
+            'match'     => 'is_numeric',
+            'option'    => $shop,
+            'search'    => array
+            (
+                'api' => 'shop/info-like',
+                'col' => '*',
+                'result' => 'id',
+            ) ,
+            'list_name' => '门店信息',
+            'list'      => 'Dever::load("mail/lib/manage.entry_member", {id})',
+            '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
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '毛利',
+            'default'   => '0',
+            'desc'      => '采购金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+            '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',
+            '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
+    (
+        '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
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-month','>='),
+                'end' => array('yes-month','<='),
+                'area' => array('yes','like'),
+                'state' => 1,
+            ),
+            
+            'type' => 'one',
+            'col' => 'sum(cprice) as cprice',
+        ),
+    ),
+);

+ 55 - 12
service/mail/database/area_stat.php

@@ -7,6 +7,10 @@ return array
     'lang' => '区域分润管理统计',
     'order' => 79,
     'menu' => 'agent',
+    // 'end' => array
+    // (
+    //     'insert' => 'mail/lib/manage.updateArea_stat', 
+    // ),
     # 数据结构
     'struct' => array
     (
@@ -29,7 +33,8 @@ return array
             'default'   => '',
             'match'     => 'is_numeric',
             'desc'      => '',
-            'search'    => 'month',
+            'update'    => 'month',
+            'search'    => 'day',
             'list'      => 'date("Y-m", {month})',
         ),
 
@@ -41,27 +46,43 @@ return array
 	        'desc'      => '区域',
 	        'match'     => 'option',
 	        'update'    => 'linkage',
+            'search'    => 'linkage',
 	        'list'      => 'Dever::load("area/api.string", "{area}")',
+            'option'    => Dever::url('api.get?level_total=4', 'area'),
 	    ),
 
         'mid'      => array
         (
             'type'      => 'int-11',
-            'name'      => '收益代理商',
+            'name'      => '收益代理商姓名/电话',
             'default'   => '-1',
             'desc'      => '代理商',
             'match'     => 'is_string',
-            'update'    => 'text',
+            // 'update'    => 'text',
             'search'    => array
             (
-                'api' => 'agent/member-find',
-                'col' => 'mobile',
+                'api' => 'agent/member-getSearch',
+                'col' => 'col',
                 'result' => 'id',
                 'search' => 'mid',
             ),
             'list_name' => '收益代理商',
             'list'      => 'Dever::load("mail/lib/manage.area_member", {id})',
-            'list_order' => 10,
+            '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
@@ -72,7 +93,7 @@ return array
             'desc'      => '店铺数量',
             'match'     => 'is_numeric',
             'update'    => 'text',
-            'list'      => true,
+            // 'list'      => true,
         ),
 
         'c_price'      => array
@@ -82,9 +103,9 @@ return array
             'default'   => '0',
             'desc'      => '采购金额',
             'match'     => 'is_numeric',
-            'update'    => 'text',
-            'list'      => true,
-            'list_order' => 4,
+            // 'update'    => 'text',
+            // 'list'      => true,
+            // 'list_order' => 4,
         ),
 
         't_num'      => array
@@ -94,7 +115,7 @@ return array
             'default'   => '0',
             'desc'      => '体验店数量',
             'match'     => 'is_numeric',
-            'update'    => 'text',
+            // 'update'    => 'text',
             'list'      => true,
         ),
 
@@ -105,7 +126,7 @@ return array
             'default'   => '0',
             'desc'      => '体验店采购金额',
             'match'     => 'is_numeric',
-            'update'    => 'text',
+            // 'update'    => 'text',
             'list'      => true,
         ),
 
@@ -121,6 +142,28 @@ return array
             'list_order' => 5,
         ),
 
+        'l_num'      => array
+        (
+            'type'      => 'decimal-11',
+            'name'      => '零售店数量',
+            'default'   => '0',
+            'desc'      => '零售店数量',
+            'match'     => 'is_numeric',
+            // 'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'l_price'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '零售店采购金额',
+            'default'   => '0',
+            'desc'      => '零售店采购金额',
+            'match'     => 'is_numeric',
+            // 'update'    => 'text',
+            'list'      => true,
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 447 - 11
service/mail/lib/Manage.php

@@ -575,8 +575,50 @@ class Manage
         $data['total_price'] = $data['a_price'] + $data['a_noprice'];
         return Dever::render('soft_cash', $data);
     }
+    #采购价-成本价
+    public function caigou($where){
+        $data = Dever::db('shop/buy_order')->getNewAll($where);
+        $res = array();
+        foreach($data as $k => $v){
+            // $goods_id,$skuid
+            $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
+            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){
+                    $data[$k]['money'] = $v['price'] - $goods['c_price'];
+                }else{
+                    $data[$k]['money'] = $v['price'];
+                }
+            }
+        }
+        $money = 0;
+        foreach($data as $k1 => $v1){
+            $money +=$v1['money'];
+        }
+        return $money;
+    }
+    public function ls($where){
+        // print_R($where);die;
+        $shop = Dever::db('mail/area_entry')->getNewAll($where);
+        $data = array();
+        $data['price'] = 0;
+        foreach($shop as $k => $v){
+            $shop[$k]['shop'] = Dever::db('shop/info')->find(array('area'=>$where['area'],'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'));
         $start_time = $month .'-01 00:00:00';
         $where = array();
@@ -590,19 +632,67 @@ class Manage
         foreach($shop as $k=>$v){
             $data[$v['city']]=$v;
         }
-        $data = array_values($data);
+        // $shop_area = $this->ls($where);
+        // // Dever::db('mail/area_entry')->getAll($where);
+        // $res = array();
+        // if($shop_area){
+        //     foreach($shop_area as $k => $v){
+        //         if($v['area']){
+        //            $area = explode(',',$v['area']);
+        //            if($area && isset($area[0])){
+        //                 $res[$k]['province'] = $area[0];
+        //            }
+        //            if ($area && isset($area[1])){
+        //                 $res[$k]['city'] = $area[1];
+        //            }else{
+        //                 $res[$k]['city'] = 0;
+        //            }
+        //            if($area && isset($area[2])){
+        //                 $res[$k]['county'] = $area[2];
+        //            }else{
+        //                 $res[$k]['county'] = 0;
+        //            }
+        //            if($area && isset($area[3])){
+        //                  $res[$k]['town'] = $area[3];
+        //            }else{
+        //                 $res[$k]['town'] = 0;
+        //            }
+        //         }
+        //     }
+        // }
+        
+        // $data = array_values($data);
+        // $data = array_merge($data,$res);
+        // // print_R($data);die;
+        // $result=array_unique($data, SORT_REGULAR);
+        // $rest=array();
+        // foreach($data as $k=>$v){
+        //     $rest[$v['county']]=$v;
+        // }
+        // $data=array_values($rest);
+        // foreach ($data as $k => $v) {
+        //   $edition[] = $v['province'];
+        // }
+        // array_multisort($edition, SORT_ASC, $data);
         foreach($data as $k => $v){
             $w['month'] = $where['start'];
             #城市
             if($v['city']>0){
                 $where['area'] = $v['city'];
                 $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
+                $jia = $this->caigou($where);
                 $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;
+                $data[$k]['citys']['price']= $jia * 0.01;
+                // $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'];
+               
+                if($mid && $mid['id']){
+                    $data[$k]['citys']['mid'] = $mid['id'];
+                }else{
+                     $data[$k]['citys']['mid'] = '';
+                }
+                
                 $where['city'] = $v['city'];
                 $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
                 #体验店
@@ -611,11 +701,32 @@ class Manage
                 $where['type_id'] = implode(',',$data[$k]['citys']['type']);
                 $data[$k]['citys']['t_num'] = count($t_shop);
                 if($data[$k]['citys']['t_num']>0){
-                    $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachMoney($where);
+                    $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
                     
                 }else{
                     $data[$k]['citys']['t_price'] = 0;
                 }
+                #零售店
+                $shop_area = $this->ls($where);
+                $data[$k]['citys']['l_price'] =$shop_area['price'] * 0.01;
+                $data[$k]['citys']['l_num'] = $shop_area['num'];
+                $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
+                // $entry = Dever::db('mail/area_entry')->getNewAll($where);
+                // print_R($entry);die;
+                // $entry = Dever::db('mail/area_entry')->getNum($where);
+                // if ($entry && $entry['num']){
+                //     $data[$k]['citys']['l_num'] = $entry['num'];
+                //     $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
+                // }else{
+                //     $data[$k]['citys']['l_num'] = 0;
+                // }
+                // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+                // if ($entry_price && $entry_price['cprice'] ){
+                //     $data[$k]['citys']['l_price'] =  $entry_price['cprice'] * 0.4;
+                //     $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
+                // }else{
+                //     $data[$k]['citys']['l_price'] = 0;
+                // }
 
                 $w['mid'] = $data[$k]['citys']['mid'];
                 $w['area'] = $data[$k]['citys']['area'];
@@ -624,6 +735,9 @@ class Manage
                 $w['num'] = $data[$k]['citys']['num'];
                 $w['t_num'] = $data[$k]['citys']['t_num'];
                 $w['t_price'] = $data[$k]['citys']['t_price']['total'];
+                $w['l_num'] = $data[$k]['citys']['l_num'];
+                $w['l_price'] = $data[$k]['citys']['l_price'];
+
                 $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);
@@ -638,12 +752,14 @@ class Manage
                 $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;
+                $jia = $this->caigou($where);
+                $data[$k]['countys']['price']= $jia *0.03;
+                // $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'] = '';
                 if($mid && $mid['id']){
                     $data[$k]['countys']['mid'] = $mid['id'];
+                }else{
+                    $data[$k]['countys']['mid'] = '';
                 }
                 $wh['county'] = $v['county'];
                 $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
@@ -658,6 +774,26 @@ class Manage
                     $data[$k]['countys']['t_price'] = 0;
                 }
 
+                #零售店
+                $shop_area = $this->ls($where);
+                $data[$k]['countys']['l_price'] =$shop_area['price'] * 0.03;
+                $data[$k]['countys']['l_num'] = $shop_area['num'];
+                $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
+                // $entry = Dever::db('mail/area_entry')->getNum($where);
+                // if ($entry && $entry['num']){
+                //     $data[$k]['countys']['l_num'] = $entry['num'];
+                //     $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
+                // }else{
+                //     $data[$k]['countys']['l_num'] = 0;
+                // }
+                // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+                // if ($entry_price && $entry_price['cprice'] ){
+                //     $data[$k]['countys']['l_price'] =  $entry_price['cprice'] * 0.4;
+                //     $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
+                // }else{
+                //     $data[$k]['countys']['l_price'] = 0;
+                // }
+
                 $w['mid'] = $data[$k]['countys']['mid'];
                 $w['area'] = $data[$k]['countys']['area'];
                 $w['price'] = $data[$k]['countys']['price'];
@@ -665,6 +801,8 @@ class Manage
                 $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'];
+                $w['l_num'] = $data[$k]['countys']['l_num'];
+                $w['l_price'] = $data[$k]['countys']['l_price'];
                 $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);
@@ -678,9 +816,16 @@ class Manage
                 $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;
+                $jia = $this->caigou($where);
+                $data[$k]['towns']['price'] = $jia * 0.05;
+                // $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'];
+                if($mid && $mid['id']){
+                    $data[$k]['towns']['mid'] = $mid['id'];
+                }else{
+                    $data[$k]['towns']['mid'] = '';
+                }
+                
                 $whe['town'] = $v['town'];
                 $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
                 #体验店
@@ -694,6 +839,26 @@ class Manage
                     $data[$k]['towns']['t_price'] = 0;
                 }
 
+                #零售店
+                $shop_area = $this->ls($where);
+                $data[$k]['towns']['l_price'] =$shop_area['price'] * 0.05;
+                $data[$k]['towns']['l_num'] = $shop_area['num'];
+                $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
+                // $entry = Dever::db('mail/area_entry')->getNum($where);
+                // if ($entry && $entry['num']){
+                //     $data[$k]['towns']['l_num'] = $entry['num'];
+                //     $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
+                // }else{
+                //     $data[$k]['towns']['l_num'] = 0;
+                // }
+                // $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+                // if ($entry_price && $entry_price['cprice'] ){
+                //     $data[$k]['towns']['l_price'] =  $entry_price['cprice'] * 0.4;
+                //     $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
+                // }else{
+                //     $data[$k]['towns']['l_price'] = 0;
+                // }
+
                 $w['mid'] = $data[$k]['towns']['mid'];
                 $w['area'] = $data[$k]['towns']['area'];
                 $w['price'] = $data[$k]['towns']['price'];
@@ -701,6 +866,8 @@ class Manage
                 $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'];
+                $w['l_num'] = $data[$k]['towns']['l_num'];
+                $w['l_price'] = $data[$k]['towns']['l_price'];
                 $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);
@@ -712,14 +879,283 @@ class Manage
         }
         return 'ok';
     }
+    // public function area_api(){
+    //     #零售店的采购金额*0.4
+    //     $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;
+    //     }
+    //     $shop_area = Dever::db('mail/area_entry')->getAll($where);
+    //     $res = array();
+    //     if($shop_area){
+    //         foreach($shop_area as $k => $v){
+    //             if($v['area']){
+    //                $area = explode(',',$v['area']);
+    //                if($area && isset($area[0])){
+    //                     $res[$k]['province'] = $area[0];
+    //                }
+    //                if ($area && isset($area[1])){
+    //                     $res[$k]['city'] = $area[1];
+    //                }else{
+    //                     $res[$k]['city'] = 0;
+    //                }
+    //                if($area && isset($area[2])){
+    //                     $res[$k]['county'] = $area[2];
+    //                }else{
+    //                     $res[$k]['county'] = 0;
+    //                }
+    //                if($area && isset($area[3])){
+    //                      $res[$k]['town'] = $area[3];
+    //                }else{
+    //                     $res[$k]['town'] = 0;
+    //                }
+    //             }
+    //         }
+    //     }
+        
+    //     $data = array_values($data);
+    //     $data = array_merge($data,$res);
+    //     // print_R($data);die;
+    //     $result=array_unique($data, SORT_REGULAR);
+    //     $rest=array();
+    //     foreach($data as $k=>$v){
+    //         $rest[$v['county']]=$v;
+    //     }
+    //     $data=array_values($rest);
+    //     foreach ($data as $k => $v) {
+    //       $edition[] = $v['province'];
+    //     }
+    //     array_multisort($edition, SORT_ASC, $data);
+    //     foreach($data as $k => $v){
+    //         $w['month'] = $where['start'];
+    //         #城市
+    //         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'];
+               
+    //             if($mid && $mid['id']){
+    //                 $data[$k]['citys']['mid'] = $mid['id'];
+    //             }else{
+    //                  $data[$k]['citys']['mid'] = '';
+    //             }
+                
+    //             $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_num'] = count($t_shop);
+    //             if($data[$k]['citys']['t_num']>0){
+    //                 $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
+                    
+    //             }else{
+    //                 $data[$k]['citys']['t_price'] = 0;
+    //             }
+    //             #零售店
+    //             $entry = Dever::db('mail/area_entry')->getNum($where);
+    //             if ($entry && $entry['num']){
+    //                 $data[$k]['citys']['l_num'] = $entry['num'];
+    //                 $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
+    //             }else{
+    //                 $data[$k]['citys']['l_num'] = 0;
+    //             }
+    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+    //             if ($entry_price && $entry_price['cprice'] ){
+    //                 $data[$k]['citys']['l_price'] =  $entry_price['cprice'] * 0.4;
+    //                 $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
+    //             }else{
+    //                 $data[$k]['citys']['l_price'] = 0;
+    //             }
+
+    //             $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'];
+    //             $w['l_num'] = $data[$k]['citys']['l_num'];
+    //             $w['l_price'] = $data[$k]['citys']['l_price'];
+
+    //             $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);
+    //             }
+    //         }
+            
+    //         #区县
+    //         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);
+    //             if($mid && $mid['id']){
+    //                 $data[$k]['countys']['mid'] = $mid['id'];
+    //             }else{
+    //                 $data[$k]['countys']['mid'] = '';
+    //             }
+    //             $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_num'] = count($t_shop);
+    //             if($data[$k]['countys']['t_num']>0){
+    //                 $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
+    //             }else{
+    //                 $data[$k]['countys']['t_price'] = 0;
+    //             }
+
+    //             #零售店
+    //             $entry = Dever::db('mail/area_entry')->getNum($where);
+    //             if ($entry && $entry['num']){
+    //                 $data[$k]['countys']['l_num'] = $entry['num'];
+    //                 $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
+    //             }else{
+    //                 $data[$k]['countys']['l_num'] = 0;
+    //             }
+    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+    //             if ($entry_price && $entry_price['cprice'] ){
+    //                 $data[$k]['countys']['l_price'] =  $entry_price['cprice'] * 0.4;
+    //                 $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
+    //             }else{
+    //                 $data[$k]['countys']['l_price'] = 0;
+    //             }
+
+    //             $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'];
+    //             $w['l_num'] = $data[$k]['countys']['l_num'];
+    //             $w['l_price'] = $data[$k]['countys']['l_price'];
+    //             $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['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);
+    //             if($mid && $mid['id']){
+    //                 $data[$k]['towns']['mid'] = $mid['id'];
+    //             }else{
+    //                 $data[$k]['towns']['mid'] = '';
+    //             }
+                
+    //             $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_num'] = count($t_shop);
+    //             if($data[$k]['towns']['t_num']>0){
+    //                 $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
+    //             }else{
+    //                 $data[$k]['towns']['t_price'] = 0;
+    //             }
+
+    //             #零售店
+    //             $entry = Dever::db('mail/area_entry')->getNum($where);
+    //             if ($entry && $entry['num']){
+    //                 $data[$k]['towns']['l_num'] = $entry['num'];
+    //                 $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
+    //             }else{
+    //                 $data[$k]['towns']['l_num'] = 0;
+    //             }
+    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
+    //             if ($entry_price && $entry_price['cprice'] ){
+    //                 $data[$k]['towns']['l_price'] =  $entry_price['cprice'] * 0.4;
+    //                 $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
+    //             }else{
+    //                 $data[$k]['towns']['l_price'] = 0;
+    //             }
+
+    //             $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'];
+    //             $w['l_num'] = $data[$k]['towns']['l_num'];
+    //             $w['l_price'] = $data[$k]['towns']['l_price'];
+    //             $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);
+    //             }
+    //         }
+    //     }
+    //     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'];
+            $res = $member['name']."<br/>".$member['mobile'];
+        }else{
+            $res = '-';
+        }
+        return $res;
+    }
+
+    public function entry_member($id){
+        $info = Dever::db('mail/area_entry')->find($id);
+        if($info['shop_id']){
+            $member = Dever::db('shop/info')->find($info['shop_id']);
+            // print_R($member);die;
+            $res = $member['name'].'<br/>'.$member['sid'];
         }else{
             $res = '-';
         }
         return $res;
     }
+
+    public function updateArea_entry($id,$name,$data){
+        $sid = Dever::param('sid',$data);
+        $month = Dever::param('month',$data);
+        if ($id && $sid) {
+            $info = Dever::db('mail/area_entry')->find($id);
+            $member = Dever::db('shop/info')->find(array('sid'=>$sid));
+            // print_R($member);die;
+            $where['where_id'] = $id ;
+            $where['shop_id'] = $member['id'];
+            $where['month'] = strtotime($month);
+            Dever::db('mail/area_entry')->update($where);
+        }
+    }
 }