dever 3 years ago
parent
commit
5d596578d7

+ 4 - 3
app/goods/lib/Info.php

@@ -241,9 +241,9 @@ class Info
     }
 
     # 获取支付所需要的信息
-    public function getPayInfo($id, $sku, $num = 1, $user = array())
+    public function getPayInfo($id, $sku = 0, $num = 1, $user = array())
     {
-        $info = Dever::db($this->table_info)->find($id);
+        $info = is_array($id) ? $id : Dever::db($this->table_info)->find($id);
 
         if ($info) {
             unset($info['f_price']);
@@ -257,11 +257,12 @@ class Info
                     $info['price'] = $sku['price'];
                     $info['s_price'] = $sku['s_price'];
                     //$info['num'] = $sku['num'];
-                    $info['attr_json'] = $sku['attr'];
+                    //$info['attr_json'] = $sku['attr'];
                     $info['attr'] = Dever::json_decode($sku['attr']);
 
                     if ($info['attr']) {
                         $info['attr'] = Dever::load('attr/api')->getInfoByJson($info['attr']);
+                        $info['sku_name'] = $info['attr']['string'];
                     }
                 }
             }

+ 1 - 0
app/mshop/lib/Core.php

@@ -14,6 +14,7 @@ class Core
         }
         if ($this->uid) {
             $this->user = Dever::db('shop/member')->find($this->uid);
+            $this->user['uid'] = $this->uid;
         }
 
         $this->checkLogin();

+ 4 - 5
app/mshop/src/Data.php

@@ -358,7 +358,7 @@ class Data extends Core
         $invoice_id = Dever::input('invoice_id');
         $pay_type = Dever::input('pay_type', 1);
         $mobile = Dever::input('mobile');
-        $cash = Dever::input('cash');
+        $cash = Dever::input('cash', 0);
         Dever::setInput('pay_method', 2);
 
         if (!$mobile) {
@@ -370,11 +370,12 @@ class Data extends Core
         $this->data['shop'] = $this->shop;
 
         Dever::load('shop/lib/sell')->goods($this->data);
-        Dever::load('shop/lib/sell')->coupon($this->data, 2);
+        Dever::load('shop/lib/sell')->coupon($this->data, 3);
 
         if ($this->data['pay_method'] > 1) {
             $cart = false;
         }
+        $cart = true;
 
         if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
             Dever::alert('已售空');
@@ -394,9 +395,7 @@ class Data extends Core
             'mobile' => $mobile,
         );
 
-        if ($cash) {
-            $this->data['price'] -= $cash;
-        }
+        $this->data['price'] -= $cash;
         $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
         return $pay;
     }

+ 10 - 1
app/mshop/src/Goods.php

@@ -10,7 +10,16 @@ class Goods extends Core
 {
     public function getList()
     {
-        $this->data['data'] = Dever::load('shop/lib/info')->getGoods($this->shop_id);
+    	$this->data['search'] = array();
+    	$this->data['search']['total'] = array
+    	(
+    		array('name' => '全部', 'value' => ''),
+    		array('name' => '库存<3件', 'value' => '3'),
+    		array('name' => '库存<5件', 'value' => '5'),
+    		array('name' => '库存<10件', 'value' => '10'),
+    		array('name' => '无库存', 'value' => '1'),
+    	);
+        $this->data['data'] = Dever::load('shop/lib/info')->getGoodsSku($this->shop_id);
 
         return $this->data;
     }

+ 98 - 26
app/mshop/src/Out.php

@@ -10,22 +10,59 @@ class Out extends Core
     # 获取所有商品列表
     public function getGoods()
     {
-        $where = array();
+        $this->data['data'] = Dever::load('shop/lib/info')->getGoods($this->shop_id);
 
-        $name = Dever::input('name');
-        if ($name) {
-            $where['name'] = $name;
+        return $this->data;
+    }
+
+    # 采购订单列表
+    public function getList()
+    {
+        $where['shop_id'] = $this->shop_id;
+
+        $this->data['search_value'] = $where;
+        $this->data['search_value']['day'] = $day = Dever::input('day');
+        if ($day) {
+            $where['start'] = Dever::maketime($day . ' 00:00:00');
+            $where['end'] = Dever::maketime($day . ' 23:59:59');
         }
-        $this->data['data'] = Dever::db('goods/info')->getPageAll($where);
-        if ($this->data['data']) {
-            foreach ($this->data['data'] as $k => $v) {
-                $this->data['data'][$k] = Dever::load('shop/lib/info')->getGoodsInfo($this->shop_id, $v);
+
+        $this->data['order'] = Dever::db('shop/out_order')->getAll($where);
+
+        if ($this->data['order']) {
+            foreach ($this->data['order'] as $k => $v) {
+                $this->data['order'][$k] = $this->getInfo($v);
             }
         }
 
         return $this->data;
     }
 
+    # 查看订单详情
+    public function view()
+    {
+    	$where['shop_id'] = $this->shop_id;
+        $where['id'] = Dever::input('order_id');
+
+        $this->data = Dever::db('shop/out_order')->find($where);
+
+        if (!$this->data) {
+            Dever::alert('订单不存在');
+        }
+
+        $this->data = $this->getInfo($this->data, true);
+
+        return $this->data;
+    }
+
+    # 下单填写用途信息
+    public function info()
+    {
+        $this->data['user'] = $this->user;
+        $this->data['type'] = Dever::db('shop/out_order')->config['type'];
+        return $this->data;
+    }
+
     # 确认订单页面
     public function confirm()
     {
@@ -63,30 +100,44 @@ class Out extends Core
             $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
             $n = isset($num[$k]) ? $num[$k] : 1;
             $this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
+            $this->data['list'][$k]['num'] = $n;
+
+            # 2是库存不足
+            $this->data['list'][$k]['ku_state'] = 1;
 
-            $this->data['list'][$k]['buy_num'] = $n;
-            $this->data['num'] += $n;
-            $this->data['price'] += $this->data['list'][$k]['price'] * $n;
-            $this->data['name'][] = $this->data['list'][$k]['name'];
+            # 验证是否有货
+            $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
+
+            if ($total <= 0) {
+                $this->data['list'][$k]['ku_state'] = 2;
+                $this->data['list'][$k]['buy_num'] = 0;
+            }
+
+            if ($this->data['list'][$k]['ku_state'] == 1) {
+                $this->data['list'][$k]['buy_num'] = $n;
+                $this->data['num'] += $n;
+                $this->data['price'] += $this->data['list'][$k]['price'] * $n;
+                $this->data['name'][] = $this->data['list'][$k]['name'];
+            }
         }
 
         $this->data['name'] = implode(',', $this->data['name']);
     }
 
     # 出库下单
-    public function action()
+    public function action_commit()
     {
         $info = Dever::input('info');
+        $type = Dever::input('type', 1);
 
         $this->goods();
-
-        $pay = Dever::load('mshop/lib/buy')->action($this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer);
         
         $order_data['shop_id'] = $this->shop['id'];
         $order_data['mobile'] = $this->shop['mobile'];
         $order_data['name'] = $this->data['name'];
         $order_data['num'] = $this->data['num'];
         $order_data['info'] = $info;
+        $order_data['type'] = $type;
         $order_data['price'] = $this->data['price'];
         $order_data['member_id'] = $this->uid;
 
@@ -104,17 +155,20 @@ class Out extends Core
         }
 
         foreach($this->data['list'] as $k => $v) {
-            $data['shop_id'] = $shop['id'];
-            $data['order_id'] = $id;
-            $data['goods_id'] = $v['id'];
-            $data['sku_id'] = $v['sku_id'];
-            $data['price'] = $v['price'];
-            $data['num'] = $v['buy_num'];
-
-            $state = Dever::db('shop/out_order_goods')->insert($data);
-            if ($state) {
-            	# 出库成功 去掉库存
-            }
+        	if ($v['ku_state'] == 1) {
+	            $data['shop_id'] = $this->shop['id'];
+	            $data['order_id'] = $id;
+	            $data['goods_id'] = $v['id'];
+	            $data['sku_id'] = $v['sku_id'];
+	            $data['price'] = $v['price'];
+	            $data['num'] = $v['buy_num'];
+
+	            $state = Dever::db('shop/out_order_goods')->insert($data);
+	            if ($state) {
+	            	# 出库成功 去掉库存
+	            	Dever::load('shop/lib/goods')->oper(2, 1, array($data));
+	            }
+	        }
         }
 
         return 'ok';
@@ -131,4 +185,22 @@ class Out extends Core
             return $this->getOrderId();
         }
     }
+
+    # 获取订单详细信息
+    private function getInfo($info, $view = false)
+    {
+        $info['goods'] = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id']));
+        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+
+        $type = Dever::db('shop/out_order')->config['type'];
+        $info['type_name'] = $type[$info['type']];
+        if ($view) {
+            foreach ($info['goods'] as $k => $v) {
+                $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
+            }
+
+            $info['member'] = Dever::db('shop/member')->find($info['member_id']);
+        }
+        return $info;
+    }
 }

+ 33 - 0
app/shop/database/goods_sku.php

@@ -139,6 +139,39 @@ $config = array
     # request 请求接口定义
     'request' => array
     (
+        'getDataPage' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => array('yes-t_1.shop_id'),
+                'name' => array('yes-t_2.name', 'like'),
+                'total' => array('yes|t_1.total_num-t_1.sell_num', '<'),
+                'column' => array('yes-t_2.column_id', 'like'),
+                'category' => array('yes-t_2.category', 'like'),
+                'top_category_id' => array('yes-t_2.top_category_id'),
+                'second_category_id' => array('yes-t_2.second_category_id'),
+                'category_id' => array('yes-t_2.category_id'),
+                'status' => array('yes-t_2.status', 1),
+                'state' => array('yes-t_2.state', 1),
+            ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'goods/info',
+                    'type' => 'left join',
+                    'on' => array('goods_id','id'),
+                    'col' => 'goods_id',
+                ),
+            ),
+            'type' => 'all',
+            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc', 't_2.price' => 'asc'),
+            'page' => array(30, 'list'),
+            'col' => '*,t_2.name,t_2.cover,t_2.id as id,t_1.total_num-t_1.sell_num as total,t_1.sell_num',
+        ),
+
        # 列表
         'getData' => array
         (

+ 13 - 0
app/shop/database/out_order.php

@@ -21,6 +21,7 @@ return array
     'lang' => '出库订单',
     'order' => 99,
     'menu'	=> false,
+    'type' => $type,
     # 数据结构
     'struct' => array
     (
@@ -179,6 +180,18 @@ return array
             //'update'  => 'text',
         ),
 
+        'type'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '类型',
+            'default'   => '1',
+            'desc'      => '类型',
+            'match'     => 'is_numeric',
+            'option'    => $type,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint-1',

+ 1 - 1
app/shop/database/sell_order.php

@@ -556,7 +556,7 @@ return array
                 'state' => 1,
             ),
             'type' => 'one',
-            'col' => 'sum(price) as total',
+            'col' => 'sum(price-refund_cash) as total',
         ),
 
         # 获取商品数量

+ 9 - 1
app/shop/lib/Cron.php

@@ -17,12 +17,20 @@ class Cron
     }
 
     /**
-     * 处理销售数据
+     * 处理销售数据 生成每天的销量统计、每月对账单
      *
      * @return mixed
      */
     public function sell()
     {
+        $start = Dever::input('start', date('Y-m-d'));
+        $end = Dever::input('end', date('Y-m-d'));
+        $where['start'] = Dever::maketime($start . ' 00:00:00');
+        $where['end'] = Dever::maketime($end . ' 23:59:59');
+
         
+
     }
+
+
 }

+ 41 - 0
app/shop/lib/Info.php

@@ -82,6 +82,47 @@ class Info
         return $data;
     }
 
+    # 获取店铺的商品SKU列表
+    public function getGoodsSku($shop)
+    {
+        $table = 'shop/goods_sku';
+        $where['shop_id'] = isset($shop['id']) ? $shop['id'] : $shop;
+        $method = 'getDataPage';
+        
+        $name = Dever::input('name');
+        if ($name) {
+            $where['name'] = $name;
+        }
+        $total = Dever::input('total');
+        if ($total) {
+            $where['total'] = $total;
+        }
+        
+        $data = Dever::db($table)->$method($where);
+
+        $result = array();
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $data[$k] = Dever::load('goods/lib/info')->getPayInfo($v, $v['sku_id']);
+                if (!isset($result[$v['id']])) {
+                    $result[$v['id']] = $v;
+                }
+                if (isset($data[$k]['attr']) && $data[$k]['attr']) {
+                    $result[$v['id']]['price_array'][] = array
+                    (
+                        'name' => $data[$k]['sku_name'],
+                        'total' => $data[$k]['total'] <= 0 ? 0 : $data[$k]['total'],
+                        'price' => $data[$k]['price'],
+                        's_price' => $data[$k]['s_price'],
+                    );
+                }
+                
+            }
+        }
+
+        return $result;
+    }
+
     # 获取详细信息
     private function getInfo($data)
     {

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

@@ -101,6 +101,7 @@ class Refund
             Dever::alert('当前订单状态不允许退货退款');
         }
 
+        $dec = $num;
         $data = Dever::load($this->lib)->set($type, 1)->getView($id, $order_id, false);
         $auth = false;
         if ($type == 1) {
@@ -123,8 +124,14 @@ class Refund
                 	} else {
                 		$cash = $info['price'];
                 	}
+                    if ($num > 0) {
+                        $dec = $num;
+                    } else {
+                        $dec = $info['num'];
+                    }
                     
                     if ($num > 0 && $info['num'] >= $num) {
+                        $dec = $info['num'];
                         $price = round($cash / $info['num'], 2);
                         $cash = round($price * $num, 2);
                     }
@@ -136,7 +143,7 @@ class Refund
             }
 
             if ($cash > 0) {
-                $log = $this->up($data['shop_id'], $data['id'], $order_goods_id, $status, $cash, $num, $desc, $pic, $process);
+                $log = $this->up($data['shop_id'], $data['id'], $order_goods_id, $status, $cash, $dec, $desc, $pic, $process);
 
                 if ($this->type == 'buy' && ($data['status'] == 5 || $data['status'] == 6)) {
                     # 如果是采购单,这里要把库存先减掉
@@ -147,6 +154,10 @@ class Refund
                 $update = array();
                 $update['where_id'] = $data['id'];
                 $update['refund_cash'] = $data['refund_cash'] + $cash;
+                if ($dec > 0) {
+                    $update['num'] = $data['num'] - $dec;
+                }
+                
                 Dever::db($this->order_table)->update($update);
 
                 if ($id && $process == 2) {
@@ -188,6 +199,9 @@ class Refund
 
         $update = array();
         if ($process == 3) {
+            if ($info['num'] && $info['num'] > 0) {
+                $update['num'] = $order['num'] + $info['num'];
+            }
             $update['refund_cash'] = $order['refund_cash'] - $info['cash'];
             $update['where_id'] = $order['id'];
             $state = Dever::db($this->order_table)->update($update);

+ 10 - 0
main/database/sell_config.php

@@ -79,6 +79,16 @@ return array
             'update'    => 'text',
         ),
 
+        'dz_phone'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '对账专员电话',
+            'default'   => '',
+            'desc'      => '请输入对账专员电话',
+            'match'     => 'option',
+            'update'    => 'text',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 1 - 1
package/manage/plugin/Console.php

@@ -11,7 +11,7 @@ class Console
         $where['start'] = Dever::maketime(date('Y-m-d 00:00:00'));
         $where['end'] = Dever::maketime(date('Y-m-d 23:59:59'));
 
-        $where['status'] = '1,2,3,4';
+        $where['status'] = '1,2,3,4,5,6';
         $today_sell_cash = Dever::db('shop/sell_order')->getCashNum($where);
         $today_sell_order = Dever::db('shop/sell_order')->getOrderNum($where);