dever 3 năm trước cách đây
mục cha
commit
30ee1077d0

+ 1 - 1
app/mshop/lib/Buy.php

@@ -210,7 +210,7 @@ class Buy
             $data['order_id'] = $id;
             $data['goods_id'] = $v['id'];
             $data['sku_id'] = $v['sku_id'];
-            $data['price'] = $v['price'];
+            $data['price'] = $v['price'] * $v['buy_num'];
             $data['num'] = $v['buy_num'];
 
             Dever::db('shop/buy_order_goods')->insert($data);

+ 44 - 1
app/mshop/src/Data.php

@@ -375,7 +375,7 @@ class Data extends Core
         if ($this->data['pay_method'] > 1) {
             $cart = false;
         }
-        $cart = true;
+        $cart = 2;
 
         if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
             Dever::alert('已售空');
@@ -413,4 +413,47 @@ class Data extends Core
 
 
     # 销量统计
+    public function stat()
+    {
+        $where['shop_id'] = $this->shop_id;
+        $where['end'] = time();
+        $where['start'] = $where['end'] - 86400*30;
+        $this->data['total'] = array();
+        $this->data['total']['cash'] = 0;
+        $this->data['total']['order'] = 0;
+        $this->data['total']['goods'] = 0;
+        $this->data['data'] = Dever::db('shop/sell_stat')->getAll($where);
+
+        $this->data['day'] = $this->data['cash'] = $this->data['order'] = $this->data['goods'] = array();
+
+        if ($this->data['data']) {
+            foreach ($this->data['data'] as $k => $v) {
+                if (!$v['cash']) {
+                    $this->data['data'][$k]['cash'] = 0;
+                }
+                if (!$v['order']) {
+                    $this->data['data'][$k]['order'] = 0;
+                }
+                if (!$v['goods']) {
+                    $this->data['data'][$k]['goods'] = 0;
+                }
+
+                $this->data['data'][$k]['cash'] = floatval($this->data['data'][$k]['cash']);
+                $this->data['data'][$k]['order'] = floatval($this->data['data'][$k]['order']);
+                $this->data['data'][$k]['goods'] = floatval($this->data['data'][$k]['goods']);
+
+                $this->data['data'][$k]['day'] = date('Y-m-d', $v['day']);
+                $this->data['total']['cash'] += $this->data['data'][$k]['cash'];
+                $this->data['total']['order'] += $this->data['data'][$k]['order'];
+                $this->data['total']['goods'] += $this->data['data'][$k]['goods'];
+
+                $this->data['day'][] = $this->data['data'][$k]['day'];
+                $this->data['cash'][] = $this->data['data'][$k]['cash'];
+                $this->data['order'][] = $this->data['data'][$k]['order'];
+                $this->data['goods'][] = $this->data['data'][$k]['goods'];
+            }
+        }
+
+        return $this->data;
+    }
 }

+ 87 - 0
app/mshop/src/My.php

@@ -301,4 +301,91 @@ class My extends Core
 
         return $this->data;
     }
+
+    # 销售对账单管理
+    public function stat_month()
+    {
+        $this->data['config'] = Dever::db('main/sell_config')->find();
+        $where['shop_id'] = $this->shop_id;
+        $month = Dever::input('month');
+        if ($month) {
+            $where['start'] = Dever::maketime($month . '-01 00:00:00');
+            $where['end'] = Dever::maketime($month . '-31 23:59:59');
+        }
+        
+        $this->data['data'] = Dever::db('shop/sell_stat_month')->getAll($where);
+
+        $type = Dever::db('shop/sell_stat_month')->config['type'];
+
+        if ($this->data['data']) {
+            foreach ($this->data['data'] as $k => $v) {
+                $this->data['data'][$k]['name'] = date('Y年m月', $v['month']);
+                $this->data['data'][$k]['start'] = date('Y-m-01', $v['month']);
+                $this->data['data'][$k]['end'] = date('Y-m-t', $v['month']);
+                $this->data['data'][$k]['type_name'] = $type[$v['type']];
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 确认对账
+    public function set_stat_month()
+    {
+        $id = Dever::input('id');
+
+        $where['id'] = $id;
+        $where['shop_id'] = $this->shop_id;
+        $info = Dever::db('shop/sell_stat_month')->find($where);
+        if (!$info) {
+            Dever::alert('账单不存在');
+        }
+        if ($info) {
+            Dever::db('shop/sell_stat_month')->update(array('where_id' => $id, 'type' => 2));
+        }
+
+        return $this->stat_month();
+    }
+
+    # 查看账单详情
+    public function stat_month_view()
+    {
+        $id = Dever::input('id');
+        $where['id'] = $id;
+        $where['shop_id'] = $this->shop_id;
+        $this->data['config'] = Dever::db('main/sell_config')->find();
+        $this->data['info'] = Dever::db('shop/sell_stat_month')->find($where);
+
+        if (!$this->data['info']) {
+            Dever::alert('账单不存在');
+        }
+        $type = Dever::db('shop/sell_stat_month')->config['type'];
+
+        $this->data['info']['name'] = date('Y年m月',  $this->data['info']['month']);
+        $this->data['info']['start'] = date('Y-m-01', $this->data['info']['month']);
+        $this->data['info']['end'] = date('Y-m-t', $this->data['info']['month']);
+        $this->data['info']['type_name'] = $type[$this->data['info']['type']];
+
+        $where = array();
+        $where['shop_id'] = $this->shop_id;
+        $where['start'] = Dever::maketime($this->data['info']['start'] . ' 00:00:00');
+        $where['end'] = Dever::maketime($this->data['info']['end'] . ' 23:59:59');
+        $where['status'] = '1,2,3,4,5,6';
+        $this->data['data'] = Dever::db('shop/sell_order')->getAll($where);
+
+        if ($this->data['data']) {
+            foreach ($this->data['data'] as $k => $v) {
+                if ($v['status'] < 5) {
+                    $this->data['data'][$k]['status_name'] = '未入账';
+                } else {
+                    $this->data['data'][$k]['status_name'] = '已入账';
+                }
+
+                $this->data['data'][$k]['cdate'] = date('Y-m-d H:i', $v['cdate']);
+            }
+        }
+
+        return $this->data;
+    }
+
 }

+ 1 - 1
app/mshop/src/Out.php

@@ -160,7 +160,7 @@ class Out extends Core
 	            $data['order_id'] = $id;
 	            $data['goods_id'] = $v['id'];
 	            $data['sku_id'] = $v['sku_id'];
-	            $data['price'] = $v['price'];
+	            $data['price'] = $v['price'] * $v['buy_num'];
 	            $data['num'] = $v['buy_num'];
 
 	            $state = Dever::db('shop/out_order_goods')->insert($data);

+ 134 - 0
app/shop/database/sell_stat.php

@@ -0,0 +1,134 @@
+<?php
+
+//1待支付2支付成功3处理中4待确认5已完成6已完成(有退款)7已取消8已退款11已过期
+
+return array
+(
+    # 表名
+    'name' => 'sell_stat',
+    # 显示给用户看的名称
+    'lang' => '销售对账单',
+    'order' => 100,
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'      => true,
+        ), 
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            //'search'    => '',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+        ),
+
+        'day'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '账单时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'	=> 'day',
+            'order'		=> 'desc',
+            'list'      => 'date("Y-m-d", {day})',
+        ),
+
+        'order'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订单量',
+            'default'   => '0',
+            'desc'      => '订单量',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'goods'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '商品数',
+            'default'   => '0',
+            'desc'      => '商品数',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售额',
+            'default'   => '0',
+            'desc'      => '销售额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生成时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'    => 'date',
+            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+        'excel'	=> true,
+    ),
+
+    'request' => array
+    (
+        # 获取总金额
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-day', '>='),
+                'end' => array('yes-day', '<='),
+                'shop_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
+    ),
+);

+ 153 - 0
app/shop/database/sell_stat_month.php

@@ -0,0 +1,153 @@
+<?php
+
+$type = array
+(
+    1 => '未对账',
+    2 => '已对账',
+);
+
+return array
+(
+    # 表名
+    'name' => 'sell_stat_month',
+    # 显示给用户看的名称
+    'lang' => '销售月度对账单',
+    'order' => 100,
+    'menu' => false,
+    'type' => $type,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'      => true,
+        ), 
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            //'search'    => '',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+        ),
+
+        'month'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '账单时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'search'	=> 'day',
+            'order'		=> 'desc',
+            'list'      => 'date("Y-m", {month})',
+        ),
+
+        'order'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订单量',
+            'default'   => '0',
+            'desc'      => '订单量',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'goods'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '商品数',
+            'default'   => '0',
+            'desc'      => '商品数',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '销售额',
+            'default'   => '0',
+            'desc'      => '销售额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'		=> true,
+        ),
+
+        'type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '是否已对账',
+            'default'   => '1',
+            'desc'      => '是否已对账',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $type,
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '生成时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'    => 'date',
+            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+        'excel'	=> true,
+    ),
+
+    'request' => array
+    (
+        # 获取总金额
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-month', '>='),
+                'end' => array('yes-month', '<='),
+                'shop_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'page' => array(10, 'list'),
+            'col' => '*',
+        ),
+    ),
+);

+ 61 - 4
app/shop/lib/Cron.php

@@ -23,14 +23,71 @@ class Cron
      */
     public function sell()
     {
-        $start = Dever::input('start', date('Y-m-d'));
+        $num = Dever::input('num', 1);
+        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
         $end = Dever::input('end', date('Y-m-d'));
-        $where['start'] = Dever::maketime($start . ' 00:00:00');
-        $where['end'] = Dever::maketime($end . ' 23:59:59');
 
-        
+        $where['status'] = '1,2,3,4,5,6';
+        $start = Dever::maketime($start . ' 00:00:00');
+        $end = Dever::maketime($end . ' 23:59:59');
+        $day = intval(($end - $start)/86400);
+
+        $shop = Dever::db('shop/info')->select();
 
+        foreach ($shop as $k => $v) {
+            $where['shop_id'] = $v['id'];
+            for($i=0; $i<=$day; $i++) {
+                $where['start'] = $start + 86400*$i;
+                $where['end'] = $start + 86400*$i + 86399;
+                $data['shop_id'] = $v['id'];
+                $data['day'] = $where['start'];
+                $info = Dever::db('shop/sell_stat')->find($data);
+                $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
+                $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
+                $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
+                if (!$info) {
+                    Dever::db('shop/sell_stat')->insert($data);
+                } else {
+                    $data['where_id'] = $info['id'];
+                    Dever::db('shop/sell_stat')->update($data);
+                }
+            }
+        }
     }
 
+    # 处理月度对账数据
+    public function sell_month()
+    {
+        $num = Dever::input('num', 1);
+        if ($num > 0) {
+            $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
+        } else {
+            $month = Dever::input('start', date('Y-m'));
+        }
+        
 
+        $where['status'] = '5,6';
+        $start = Dever::maketime($month . '-01 00:00:00');
+        $end = Dever::maketime($month . '-31 23:59:59');
+
+        $shop = Dever::db('shop/info')->select();
+
+        foreach ($shop as $k => $v) {
+            $where['shop_id'] = $v['id'];
+            $where['start'] = $start;
+            $where['end'] = $end;
+            $data['shop_id'] = $v['id'];
+            $data['month'] = $start;
+            $info = Dever::db('shop/sell_stat_month')->find($data);
+            $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
+            $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
+            $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
+            if (!$info) {
+                Dever::db('shop/sell_stat_month')->insert($data);
+            } else {
+                $data['where_id'] = $info['id'];
+                Dever::db('shop/sell_stat_month')->update($data);
+            }
+        }
+    }
 }

+ 1 - 1
app/shop/lib/Sell.php

@@ -554,7 +554,7 @@ class Sell
                 $data['order_id'] = $id;
                 $data['goods_id'] = $v['id'];
                 $data['sku_id'] = $v['sku_id'];
-                $data['price'] = $v['price'];
+                $data['price'] = $v['price'] * $v['buy_num'];
                 $data['num'] = $v['buy_num'];
 
                 if (isset($v['user_coupon_id']) && $v['user_coupon_id']) {