rabin 3 年之前
父节点
当前提交
9ffafdc8c1

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

@@ -208,5 +208,22 @@ return array
             'page' => array(10, 'list'),
             'col' => '*',
         ),
+
+        # 获取总金额
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-day', '>='),
+                'end' => array('yes-day', '<='),
+                'shop_id' => array('yes', 'in'),
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('day'=>'desc','id' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );

+ 5 - 5
app/shop/lib/Refund.php

@@ -460,13 +460,13 @@ class Refund
                 if ($code) {
                     $card_info = Dever::db('card/info')->find($code['card_id']);
                     if ($card_info) {
-                        if ($code['type'] == 2) {
-                            $zhe = 0.9;
+                        if ($card_info['price'] == $card_info['value']) {
+                            $price = $card_cash;
                         } else {
-                            $zhe = $card_info['price']/$card_info['value'];
+                            $zhe = round($card_info['price']/$card_info['value'], 2);
+                            $price = round($card_cash*$zhe, 2);
                         }
-                        //$price = round($card_cash*$zhe, 2);
-                        $price = $card_cash;
+
                         $rorder = $order;
                         $rinfo = $info;
                         $rorder['type'] = 1;

+ 5 - 51
app/shop/lib/Sell.php

@@ -386,29 +386,6 @@ class Sell
                     Dever::db('card/code')->decUseCash(array('where_id' => $data['card_code_id'], 'set_use_cash' => $data['card_code_cash']));
 
                     Dever::load('cash/lib/order')->up($data, 3, 2, false, 2);
-                    /*
-                    $code = Dever::db('card/code')->find($data['card_code_id']);
-                    if ($code) {
-                        $card_info = Dever::db('card/info')->find($code['card_id']);
-                        if ($card_info) {
-                            if ($code['type'] == 2) {
-                                $zhe = 0.9;
-                            } else {
-                                $zhe = $card_info['price']/$card_info['value'];
-                            }
-                            //$price = round($data['card_code_cash']*$zhe, 2);
-                            $price = $data['card_code_cash'];
-                            $data['type'] = 1;
-                            $data['type_id'] = $data['shop_id'];
-                            $data['source_type'] = 4;
-                            $data['source_id'] = -1;
-                            $data['price'] = $price;
-                            $data['p_price'] = $data['card_code_cash'];
-
-                            Dever::load('cash/lib/order')->up($data, 3, 2, false, 2);
-                        }
-                    }
-                    */
 
                 } elseif (isset($data['wallet_cash']) && $data['wallet_cash'] && $data['wallet_cash'] > 0) {
                     # 还原钱包
@@ -1186,13 +1163,13 @@ class Sell
             if ($code) {
                 $card_info = Dever::db('card/info')->find($code['card_id']);
                 if ($card_info) {
-                    if ($code['type'] == 2) {
-                        $zhe = 0.9;
+                    if ($card_info['price'] == $card_info['value']) {
+                        $price = $card['cash'];
                     } else {
-                        $zhe = $card_info['price']/$card_info['value'];
+                        $zhe = round($card_info['price']/$card_info['value'], 2);
+                        $price = round($card['cash']*$zhe, 2);
                     }
-                    //$price = round($card['cash']*$zhe, 2);
-                    $price = $card['cash'];
+
                     $order_data['type'] = 1;
                     $order_data['type_id'] = $order_data['shop_id'];
                     $order_data['source_type'] = 4;
@@ -1445,29 +1422,6 @@ class Sell
                 Dever::db('goods/card_code')->update($card_update);
 
                 Dever::load('cash/lib/order')->up($info, 3, 2, false, 2);
-                /*
-                $code = Dever::db('card/code')->find($info['card_code_id']);
-                if ($code) {
-                    $card_info = Dever::db('card/info')->find($code['card_id']);
-                    if ($card_info) {
-                        if ($code['type'] == 2) {
-                            $zhe = 0.9;
-                        } else {
-                            $zhe = $card_info['price']/$card_info['value'];
-                        }
-                        //$price = round($info['card_code_cash']*$zhe, 2);
-                        $price = $info['card_code_cash'];
-                        $info['type'] = 1;
-                        $info['type_id'] = $info['shop_id'];
-                        $info['source_type'] = 4;
-                        $info['source_id'] = -1;
-                        $info['price'] = $price;
-                        $info['p_price'] = $info['card_code_cash'];
-
-                        Dever::load('cash/lib/order')->up($info, 3, 2, false, 2);
-                    }
-                }
-                */
             } elseif (isset($info['wallet_cash']) && $info['wallet_cash'] && $info['wallet_cash'] > 0) {
                 Dever::load('cash/lib/order')->up($info, 3, 2, false, 3);
             }

+ 1 - 1
service/agent/src/My.php

@@ -1162,7 +1162,7 @@ class My extends Core
     private function getAreaOne($v)
     {
         $date = date('Y年m月', $v['month']);
-        $v['name'] = Dever::load("area/api.string", $v['name'], '') . '区域分润' . $date . '对账单';
+        $v['name'] = Dever::load("area/api.string", $v['name'], '') . '区域收入' . $date . '对账单';
 
         list($year, $month, $end) = explode('-', date('Y-m-t', $v['month']));
 

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

@@ -114,5 +114,20 @@ return array
             'type' => 'all',
             'col' => '*',
         ),
+
+        'getBuyTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-month','>='),
+                'end' => array('yes-month','<='),
+                'shop_id' => 'yes',
+                'state' => 1,
+            ),
+            
+            'type' => 'one',
+            'col' => 'sum(buy) as total',
+        ),
     ),
 );

+ 91 - 31
service/mail/lib/Manage.php

@@ -753,7 +753,7 @@ class Manage
     }
 
     # 体验店毛利:采购价-成本价
-    public function t_buy($where, $shop_id, $per)
+    public function t_buy($where, $shop_id, $shop_name, $per, &$no_t)
     {
         $where['type_id'] = $shop_id;
         $where['status'] = '5,6';
@@ -771,8 +771,10 @@ class Manage
                 $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){
+                    if ($goods['c_price'] && $goods['c_price'] >= 0) {
                         $c_price += $goods['c_price'] * $v1['num'];
+                    } else {
+                        $no_t[$v1['goods_id'] . '_' . $v1['sku_id']] = $goods['name'] . '_' . $goods['sku_name'];
                     }
                 }
                 $price = ($v['price'] - $c_price);
@@ -785,8 +787,9 @@ class Manage
         return array(round($total, 2), round($total*$per, 2), $shop);
     }
     # 零售店毛利
-    public function l_buy($where, $shop_id, $per)
+    public function l_buy($where, $shop_id, $shop_name, $per, &$no_l)
     {
+        /*
         $where['shop_id'] = $shop_id;
         $data = Dever::db('mail/area_entry')->getBuy($where);
         $total = 0;
@@ -803,6 +806,24 @@ class Manage
             }
         }
         return array(round($total, 2), round($total*$per, 2), $shop);
+        */
+        $total = 0;
+        $shop = array();
+        foreach ($shop_id as $k => $v) {
+            $where['shop_id'] = $v;
+            $data = Dever::db('mail/area_entry')->getBuy($where);
+            if ($data && $data['total'] >= 0) {
+                $total += $data['total'];
+                if (!isset($shop[$v])) {
+                    $shop[$v] = 0;
+                }
+                $shop[$v] += $data['total'] * $per;
+                $shop[$v] = round($shop[$v], 2);
+            } else {
+                $no_l[$v] = $shop_name[$k];
+            }
+        }
+        return array(round($total, 2), round($total*$per, 2), $shop);
     }
 
     # 区域分润
@@ -828,6 +849,23 @@ class Manage
         list($where['start'], $where['end']) = Dever::month();
         $month = Dever::maketime(date('Y-m', $where['start']));
 
+        # 获取本月未对账的对账单
+        $cash_shop_where = $where;
+        $cash_shop_where['status'] = 1;
+        $cash_shop = Dever::db('cash/shop')->getData($cash_shop_where);
+        if ($cash_shop) {
+            $shop_data = array();
+            foreach ($cash_shop as $k => $v) {
+                $shop = Dever::db('shop/info')->find($v['shop_id']);
+                if ($shop) {
+                    $shop_data[$v['shop_id']] = $shop['name'];
+                }
+            }
+            if ($shop_data) {
+                Dever::alert('以下门店未完成对账:' . implode(',', $shop_data));
+            }
+        }
+
         # 获取区域
         $area = array();
         $shop = Dever::db('shop/info')->select(array('status' => 1));
@@ -838,16 +876,19 @@ class Manage
                     if ($v['city'] > 0) {
                         $key = $v['province'] . ',' . $v['city'];
                         $area[$key]['shop_id'][$v['type']][] = $v['id'];
+                        $area[$key]['shop_name'][$v['type']][] = $v['name'];
                         $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]['shop_name'][$v['type']][] = $v['name'];
                         $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]['shop_name'][$v['type']][] = $v['name'];
                         $area[$key]['type'] = 3;
                     }
                 }
@@ -855,11 +896,16 @@ class Manage
 
             $area_id = array();
             $shop_data = array();
+            $area_stat = array();
+
+            # 记录体验店和零售店的错误信息
+            $no_t = array();
+            $no_l = array();
+
             foreach ($area as $k => $v) {
                 $update = array();
                 $update['month'] = $month;
                 $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;
@@ -868,14 +914,14 @@ class Manage
                     if ($k1 == 1) {
                         # 体验店
                         $update['t_num'] = count($v1);
-                        list($update['t_buy'], $update['t_cash'], $shop_data) = $this->t_buy($where, $v1, $config[$v['type']]);
+                        list($update['t_buy'], $update['t_cash'], $shop_data) = $this->t_buy($where, $v1, $v['shop_name'][$k1], $config[$v['type']], $no_t);
                         if ($shop_data) {
                             $update['data'] += $shop_data;
                         }
                     } elseif ($k1 == 2) {
                         # 零售店
                         $update['l_num'] = count($v1);
-                        list($update['l_buy'], $update['l_cash'], $shop_data) = $this->l_buy($where, $v1, $config[$v['type']]);
+                        list($update['l_buy'], $update['l_cash'], $shop_data) = $this->l_buy($where, $v1, $v['shop_name'][$k1], $config[$v['type']], $no_l);
                         if ($shop_data) {
                             $update['data'] += $shop_data;
                         }
@@ -883,21 +929,9 @@ class Manage
                 }
 
                 if ($update['t_buy'] == 0 && $update['l_buy'] == 0) {
-                    continue;
+                    //continue;
                 }
 
-                # 设置上级id,用来做列表层级展示
-                if ($v['type'] == 1) {
-                    $update['parent_id'] = -1;
-                } elseif ($v['type'] == 2) {
-                    $area_value = explode(',', $k);
-                    $k2 = $area_value[0] . ',' . $area_value[1];
-                    $update['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
-                } elseif ($v['type'] == 3) {
-                    $area_value = explode(',', $k);
-                    $k2 = $area_value[0] . ',' . $area_value[1] . ',' . $area_value[2];
-                    $update['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
-                }
                 $update['type'] = $v['type'];
 
                 # 设置收益代理商
@@ -917,19 +951,45 @@ class Manage
                     }
                     $num[$v['type']]++;
                 }
-
                 $update['data'] = Dever::json_encode($update['data']);
-                if (!$info) {
-                    $stat_id = Dever::db('mail/area_stat')->insert($update);
-                } else {
-                    $stat_id = $update['where_id'] = $info['id'];
-                    Dever::db('mail/area_stat')->update($update);
-                }
+                $area_stat[$k] = $update;
+            }
 
-                if ($v['type'] == 1) {
-                    $area_id[$k] = $stat_id;
-                } elseif ($v['type'] == 2) {
-                    $area_id[$k] = $stat_id;
+            if ($no_t) {
+                Dever::alert('以下商品未填写成本价:<br />' . implode(',', $no_t));
+            }
+            if ($no_l) {
+                Dever::alert('以下门店未填写毛利:<br />' . implode(',', $no_l));
+            }
+
+            if ($area_stat) {
+                foreach ($area_stat as $k => $v) {
+                    # 设置上级id,用来做列表层级展示
+                    if ($v['type'] == 1) {
+                        $v['parent_id'] = -1;
+                    } elseif ($v['type'] == 2) {
+                        $area_value = explode(',', $k);
+                        $k2 = $area_value[0] . ',' . $area_value[1];
+                        $v['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
+                    } elseif ($v['type'] == 3) {
+                        $area_value = explode(',', $k);
+                        $k2 = $area_value[0] . ',' . $area_value[1] . ',' . $area_value[2];
+                        $v['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
+                    }
+
+                    $info = Dever::db('mail/area_stat')->find(array('month' => $v['month'], 'name' => $v['name'], 'clear' => true));
+                    if (!$info) {
+                        $stat_id = Dever::db('mail/area_stat')->insert($v);
+                    } else {
+                        $stat_id = $v['where_id'] = $info['id'];
+                        Dever::db('mail/area_stat')->update($v);
+                    }
+
+                    if ($v['type'] == 1) {
+                        $area_id[$k] = $stat_id;
+                    } elseif ($v['type'] == 2) {
+                        $area_id[$k] = $stat_id;
+                    }
                 }
             }
         }
@@ -987,7 +1047,7 @@ class Manage
                         $member = Dever::db('agent/member')->find($v['mid']);
                         if ($cash > 0 && $member && $member['status'] == 2) {
 
-                            $desc = Dever::load("area/api.string", $v['name'], '') . $date . '区域分润';
+                            $desc = Dever::load("area/api.string", $v['name'], '') . $date . '区域收入';
                             $state = Dever::load('bill/lib/cash')->up($v['mid'], 15, $cash, $member['role'], $v['id'], $desc, 2, true);
                             if ($state) {
                                 $where = array();