dever 3 years ago
parent
commit
67b7ec46e9

+ 3 - 0
app/mshop/lib/Buy.php

@@ -117,15 +117,18 @@ class Buy
         $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
         $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
 
+        $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
         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['goods'][$k]['status_name'] = $goods_status[$v['status']];
             }
         } else {
             foreach ($info['goods'] as $k => $v) {
                 $goods = Dever::db('goods/info')->one($v['goods_id']);
                 $info['goods'][$k]['name'] = $goods['name'];
                 $info['goods'][$k]['cover'] = $goods['cover'];
+                $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
             }
         }
 

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

@@ -56,18 +56,70 @@ class Data extends Core
         return Dever::load('shop/lib/sell')->set(2, 2)->getView($this->shop_id, $order_id);
     }
 
-    # 核销取件码
-    public function hx_code()
+    # 通知用户取件或者配送
+    public function notice()
+    {
+        $order_id = Dever::input('order_id');
+
+        $info = Dever::db('shop/sell_order')->find('id' => $order_id));
+
+        if ($info && $info['shop_id'] == $this->shop_id && $info['status'] < 3) {
+
+            $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
+
+            # 给用户发消息
+            if ($info['uid'] && $info['uid'] > 0) {
+                $shop = Dever::db('shop/info')->one($info['shop_id']);
+                $msg_param['type'] = 1;//消息类型1是订单消息
+                $msg_param['id'] = $info['id'];
+                $msg_param['name'] = $shop['name'];
+                $msg_param = Dever::json_encode($msg_param);
+                if ($info['method'] == 1) {
+                    $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
+                    $name = '取货通知';
+                } else {
+                    $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码::' . $info['code'];
+                    $name = '配送通知';
+
+                    # 分配配送商家
+                    Dever::load('shop/lib/sell')->updatePs($info, 2);
+                }
+                
+                Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
+            }
+            
+            return 'ok';
+        } else {
+            Dever::alert('您没有权限');
+        }
+    }
+
+    # 核销取件码,完成
+    public function finish()
     {
         $code = Dever::input('code');
 
-        $info = Dever::db('shop/sell_order')->find(array('code' => $code));
+        $order_id = Dever::input('order_id');
+
+        $info = Dever::db('shop/sell_order')->find(array('code' => $code, 'id' => $order_id));
 
-        if ($info && $info['shop_id'] == $this->shop_id) {
+        if ($info && $info['shop_id'] == $this->shop_id && $infn['status'] <= 3) {
 
             $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 4, 'operdate' => time()));
 
-            # 发消息?
+            # 给用户发消息
+            if ($info['uid'] && $info['uid'] > 0) {
+                $shop = Dever::db('shop/info')->one($info['shop_id']);
+                $msg_param['type'] = 1;//消息类型1是订单消息
+                $msg_param['id'] = $info['id'];
+                $msg_param['name'] = $shop['name'];
+                $msg_param = Dever::json_encode($msg_param);
+                $msg = '您有一笔订单已签收,祝您用餐愉快~';
+                Dever::load('message/lib/data')->push(-1, $info['uid'], '订单完成通知', $msg, 1, 1, false, $msg_param);
+            }
+            if ($info['method'] == 2) {
+                Dever::load('shop/lib/sell')->updatePs($info, 3);
+            }
             return 'ok';
         } else {
             Dever::alert('您没有权限核销');
@@ -164,6 +216,30 @@ class Data extends Core
         return $this->data;
     }
 
+    # 赠送优惠券
+    public function giveCoupon()
+    {
+        $coupon_id = Dever::input('coupon_id');
+        $coupon = explode(',', $coupon_id);
+
+        $num = Dever::input('num');
+        $coupon_num = explode(',', $num);
+
+        $order_id = Dever::input('order_id');
+
+        $info = Dever::db('shop/sell_order')->find(array('shop_id' => $this->shop_id, 'id' => $order_id));
+
+        if ($info['uid'] && $info['uid'] > 0) {
+            foreach ($coupon as $k => $v) {
+                $num = isset($coupon_num[$k]) ? $coupon_num[$k] : 1;
+                Dever::load('shop/lib/coupon')->getOne($info['uid'], $this->shop, $v, $num, false);
+            }
+        }
+
+        return 'ok';
+
+    }
+
     # 获取购物车的数据
     public function getCart()
     {

+ 1 - 0
app/shop/database/buy_order_goods.php

@@ -14,6 +14,7 @@ return array
     # 显示给用户看的名称
     'lang' => '订单商品表',
     'menu' => false,
+    'status' => $status,
     # 数据结构
     'struct' => array
     (

+ 1 - 0
app/shop/database/sell_order_goods.php

@@ -15,6 +15,7 @@ return array
     # 显示给用户看的名称
     'lang' => '订单商品表',
     'menu' => false,
+    'status' => $status,
     # 数据结构
     'struct' => array
     (

+ 19 - 0
app/shop/database/sell_order_ps.php

@@ -15,6 +15,7 @@ return array
     # 显示给用户看的名称
     'lang' => '订单配送表',
     'menu' => false,
+    'status' => $status,
     # 数据结构
     'struct' => array
     (
@@ -126,6 +127,24 @@ return array
             'edit'      => true,
         ),
 
+        'qu_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '取件时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '取件时间',
+        ),
+
+        'qs_date'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '签收时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '签收时间',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 26 - 17
app/shop/lib/Coupon.php

@@ -49,16 +49,19 @@ class Coupon
     }
 
     # 验证是否可以领取
-    public function getOne($uid, $shop, $shop_coupon_id)
+    public function getOne($uid, $shop, $shop_coupon_id, $num = 1, $act = true)
     {
         if (!$shop_coupon_id) {
             return false;
         }
-        $data = Dever::db('shop/coupon_act_1')->getOne(array('shop_id' => $shop['id'], 'shop_coupon_id' => $shop_coupon_id));
+        if ($act) {
+            $data = Dever::db('shop/coupon_act_1')->getOne(array('shop_id' => $shop['id'], 'shop_coupon_id' => $shop_coupon_id));
 
-        if (!$data) {
-            return false;
+            if (!$data) {
+                return false;
+            }
         }
+        
 
         $data = Dever::db('shop/coupon')->getOne($shop_coupon_id);
 
@@ -81,7 +84,7 @@ class Coupon
             return false;
         }
 
-        $state = Dever::load('shop/lib/coupon.take_commit', $uid, $shop, $data);
+        $state = Dever::load('shop/lib/coupon.take_commit', $uid, $shop, $data, $num);
         if ($state) {
             return true;
         }
@@ -90,19 +93,25 @@ class Coupon
     }
 
     # 领取
-    public function take_commit($uid, $shop, $shop_coupon)
+    public function take_commit($uid, $shop, $shop_coupon, $num = 1)
     {
-        $data['uid'] = $uid;
-        $data['shop_id'] = $shop['id'];
-        $data['city'] = $shop['city'];
-        $data['coupon_id'] = $shop_coupon['coupon_id'];
-        $data['shop_coupon_id'] = $shop_coupon['id'];
-        $data['edate'] = time() + ($shop_coupon['day'] * 86400);
-        //$data['cash'] = $cash;
-        $id = Dever::db('shop/user_coupon')->insert($data);
-
-        if ($id) {
-            Dever::db('shop/coupon')->updateNum(array('where_id' => $shop_coupon['id'], 'act_num' => 1));
+        $add_num = 0;
+        for ($i = 0; $i < $num; $i++) {
+            $data['uid'] = $uid;
+            $data['shop_id'] = $shop['id'];
+            $data['city'] = $shop['city'];
+            $data['coupon_id'] = $shop_coupon['coupon_id'];
+            $data['shop_coupon_id'] = $shop_coupon['id'];
+            $data['edate'] = time() + ($shop_coupon['day'] * 86400);
+            //$data['cash'] = $cash;
+            $id = Dever::db('shop/user_coupon')->insert($data);
+            if ($id) {
+                $add_num += 1;
+            }
+        }
+
+        if ($add_num > 0) {
+            Dever::db('shop/coupon')->updateNum(array('where_id' => $shop_coupon['id'], 'act_num' => $add_num));
         }
 
         return $id;

+ 53 - 4
app/shop/lib/Sell.php

@@ -181,6 +181,17 @@ class Sell
             $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
             if ($info['ps_info']) {
                 $info['ps_info']['service_name'] = '商家自送';
+                $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
+                if ($info['ps_info']['qu_date']) {
+                    $info['ps_info']['qu_date'] = date('Y-m-d H:i', $info['ps_info']['qu_date']);
+                }
+                if ($info['ps_info']['qs_date']) {
+                    $info['ps_info']['qs_date'] = date('Y-m-d H:i', $info['ps_info']['qs_date']);
+                }
+
+                $status = Dever::db('shop/sell_order_ps')->config['status'];
+                $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
+                
                 if ($info['ps_info']['service_id'] > 0) {
                     //暂时还没有
                 }
@@ -188,7 +199,10 @@ class Sell
         }
 
         $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
-        $info['user'] = Dever::load('passport/api')->info($info['uid']);
+        if ($info['uid'] && $info['uid'] > 0) {
+            $info['user'] = Dever::load('passport/api')->info($info['uid']);
+        }
+        
         $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
         $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
 
@@ -196,9 +210,23 @@ class Sell
             $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
         }
 
+        if ($info['status'] == 6 || $info['status'] == 7 || $info['status'] == 8) {
+            
+        } else {
+            $info['tk_cash'] = 0;
+        }
+
+        $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
         if ($this->view == 2) {
+
             foreach ($info['goods'] as $k => $v) {
                 $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
+
+                if ($v['status'] > 2 && $v['tk_cash'] > 0) {
+                    $info['tk_cash'] += $v['tk_cash'];
+                }
+
+                $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
             }
             if ($info['address_id']) {
                 $info['address'] = Dever::db('passport/address')->find($info['address_id']);
@@ -219,6 +247,12 @@ class Sell
                 $goods = Dever::db('goods/info')->one($v['goods_id']);
                 $info['goods'][$k]['name'] = $goods['name'];
                 $info['goods'][$k]['cover'] = $goods['cover'];
+
+                if ($v['status'] > 2 && $v['tk_cash'] > 0) {
+                    $info['tk_cash'] += $v['tk_cash'];
+                }
+
+                $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
             }
         }
 
@@ -799,7 +833,7 @@ class Sell
                 } else {
                     $msg = '您有一件外送商品已订购成功,核销码:' . $update['code'];
                     # 分配配送信息
-                    $this->updatePs($order);
+                    //$this->updatePs($order);
                 }
 
                 # 发消息
@@ -822,7 +856,7 @@ class Sell
     }
 
     # 添加配送信息
-    public function updatePs($order)
+    public function updatePs($order, $status = 1)
     {
         $where['order_id'] = $order['id'];
         $data = Dever::db('shop/sell_order_ps')->find($where);
@@ -833,9 +867,24 @@ class Sell
             $insert['shop_id'] = $order['shop_id'];
             $insert['service_id'] = -1;
             $insert['price'] = 0;
+            $insert['status'] = $status;
             $insert['num'] = $order['num'];
-
+            if ($status == 2) {
+                $insert['qu_date'] = time();
+            }
+        
             Dever::db('shop/sell_order_ps')->insert($insert);
+        } else {
+            $update = $where;
+            $update['where_id'] = $data['id'];
+            $update['status'] = $status;
+            if ($status == 2) {
+                $update['qu_date'] = time();
+            }
+            if ($status == 3) {
+                $update['qs_date'] = time();
+            }
+            Dever::db('shop/sell_order_ps')->update($update);
         }
     }