|
@@ -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'));
|