dever 3 rokov pred
rodič
commit
6623b7b5cf

+ 15 - 42
app/act/database/info.php

@@ -8,25 +8,9 @@ $page = 10;
 $type = array
 (
     1 => '分享活动',
+    2 => '推广员',
 );
 
-$get = array
-(
-    1 => '获取优惠券',
-);
-
-$coupon = function()
-{
-    $array = array();
-    $info = Dever::db('goods/coupon')->select();
-    
-    if($info)
-    {
-        $array += $info;
-    }
-    return $array;
-};
-
 # 常用的col
 $col = '*';
 
@@ -37,6 +21,7 @@ return array
     # 显示给用户看的名称
     'lang' => '活动管理',
     'order' => 99,
+    'check' => 'type',
 
     # 数据结构
     'struct' => array
@@ -100,31 +85,6 @@ return array
             'list'      => true,
         ),
 
-        'get'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '活动奖励',
-            'default'   => '1',
-            'desc'      => '活动奖励',
-            'match'     => 'is_numeric',
-            'update'    => 'radio',
-            'option'    => $get,
-            'control'   => 'get',
-        ),
-
-        'coupon'      => array
-        (
-            'type'      => 'varchar-5000',
-            'name'      => '优惠券',
-            'default'   => '',
-            'desc'      => '优惠券',
-            'match'     => 'is_string',
-            'update'    => 'checkbox',
-            'option'    => $coupon,
-            'list'      => true,
-            'show'      => 'get=1',
-        ),
-
         'content'       => array
         (
             'type'      => 'text-255',
@@ -169,11 +129,24 @@ return array
             'insert'    => true,
         ),
     ),
+
+    # 默认值
+    'default' => array
+    (
+        'col' => 'name,type,state,cdate',
+        'value' => array
+        (
+            '"分享领取优惠券活动",1,1,' . time(),
+            '"推广员营销活动",2,1,' . time(),
+        ),
+    ),
     
     # 管理功能
     'manage' => array
     (
         //'insert' => false,
+        //'edit' => false,
+        'delete' => false,
         # 列表
         'list_button' => array
         (

+ 12 - 1
app/goods/database/coupon.php

@@ -98,7 +98,7 @@ return array
             //'list'      => 'Dever::load("category/api.string", "{category}")',
         ),
 
-        'total'      => array
+        'total_cash'      => array
         (
             'type'      => 'varchar-100',
             'name'      => '满减金额-如满100减50,这里填写100',
@@ -190,6 +190,17 @@ return array
         ),
     ),
 
+    # 更新表结构
+    'alter' => array
+    (
+        2 => array
+        (
+            array('update', 'total', 'total_cash', 'varchar-100 0 满减金额'),
+            //array('add', 'config', 'config', 'int-11 1 配置'),
+        ),
+        'version' => 2,
+    ),
+
     'manage' => array
     (
         

+ 4 - 3
app/goods/database/info.php

@@ -7,6 +7,7 @@ $price_type = array
     1 => '普通商品',
     2 => '多价商品',
     3 => '套餐商品',
+    4 => '组合商品',
 );
 
 $mode = array
@@ -209,7 +210,7 @@ $config = array
         'price_type'        => array
         (
             'type'      => 'int-11',
-            'name'      => '商品类型',
+            'name'      => '商品类型-套餐商品由多个普通商品组成,可以单独定义库存,组合商品也由多个普通商品组成的,但库存无法自定义',
             'default'   => '1',
             'desc'      => '价格类型',
             'match'     => 'is_numeric',
@@ -263,11 +264,11 @@ $config = array
         'goods'       => array
         (
             'type'      => 'text-1000',
-            'name'      => '套餐商品配置-套餐商品只可以选择普通商品',
+            'name'      => '套餐商品配置-套餐和组合商品只可以选择普通商品',
             'default'   => '',
             'desc'      => '套餐商品配置',
             'match'     => 'is_string',
-            'show'      => 'price_type=3',
+            'show'      => 'price_type=3,4',
             'update'    => array
             (
                 array

+ 17 - 9
app/goods/lib/Info.php

@@ -346,6 +346,8 @@ class Info
         
         if ($info && $attr) {
             $info = $this->info($info, $order, $other, false, $user, $reward);
+        } else {
+            $this->getGroup($info);
         }
 
         if (!isset($info['goods_id'])) {
@@ -356,8 +358,18 @@ class Info
             $info['pic'] = explode(',', $info['pic']);
         }
 
-        if ($info['price_type'] == 3) {
-            # 获取套餐的商品
+        if ($info['tag_id']) {
+            $info['tag'] = Dever::db('goods/tag')->getAllByIds($info['tag_id']);
+        }
+
+        return $info;
+    }
+
+    # 获取组合商品
+    public function getGroup(&$info)
+    {
+        if ($info && $info['price_type'] > 2 && $info['goods'] && is_string($info['goods'])) {
+            # 获取套餐或者组合的商品
             $goods = Dever::array_decode($info['goods']);
             $goods_info = array();
             foreach ($goods as $k => $v) {
@@ -375,16 +387,10 @@ class Info
             }
             $info['goods'] = $goods_info;
         }
-
-        if ($info['tag_id']) {
-            $info['tag'] = Dever::db('goods/tag')->getAllByIds($info['tag_id']);
-        }
-
-        return $info;
     }
 
     # 获取基本信息
-    public function info($info, $key = 'list_reorder', $other = false, $is_sell = false, $user = array(), $reward = false)
+    public function info($info, $key = 'view_reorder', $other = false, $is_sell = false, $user = array(), $reward = false)
     {
         $info['category_array'] = Dever::load('category/api')->string($info['category']);
         if ($info['price_type'] == 2) {
@@ -436,6 +442,8 @@ class Info
 
         $info = $this->getInfoLink($info);
 
+        $this->getGroup($info);
+
         //$info['freight'] = 0;
         unset($info['f_price']);
         unset($info['cdate']);

+ 32 - 8
app/goods/lib/Sku.php

@@ -194,24 +194,37 @@ class Sku
         Dever::out('yes');
     }
 
-    public function table($goods_id, $other = false, $other_id = false, $col = false, $update = true)
+    public function table($goods, $other = false, $other_id = false, $col = false, $update = true, $parent_goods = false)
     {
         if (!$col) {
             $col = $this->getCol($other);
         }
+        $info = is_array($goods) ? $goods : Dever::db('goods/info')->one($goods);
+        $info = Info::init(-1)->info($info, 'view_reorder');
+
+        if ($info && $info['price_type'] == 4) {
+            if ($info['goods'] && is_array($info['goods'])) {
+                $html = '';
+                foreach ($info['goods'] as $k => $v) {
+                    $html .= $this->table($v['id'], $other, $other_id, $col, $update, $v) . '<br />';
+                }
+
+                $html .= '*组合商品的库存为以上商品中的最低库存为准';
+                return $html;
+            } else {
+                return '';
+            }
+        }
+
         $input = '';
         if ($other) {
             $other_col = $other . '_id';
-            $sku_value = Dever::db($other . '/goods_sku')->getData(array('goods_id' => $goods_id, $other_col => $other_id));
+            $sku_value = Dever::db($other . '/goods_sku')->getData(array('goods_id' => $info['id'], $other_col => $other_id));
 
-            $input = '<input type="hidden" name="goods_id" value="'.$goods_id.'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
+            $input = '<input type="hidden" name="goods_id" value="'.$info['id'].'"/><input type="hidden" name="'.$other_col.'" value="'.$other_id.'"/>';
         }
 
-        $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $goods_id));
-
-        $info = Dever::db('goods/info')->one($goods_id);
-
-        $info = Info::init(-1)->info($info, 'list_reorder');
+        $sku = Dever::db('goods/info_sku')->getDataByKeys(array('info_id' => $info['id']));
 
         $option = array();
         $head = '<thead><tr>';
@@ -227,6 +240,9 @@ class Sku
         }
 
         $col_num = 0;
+        if ($parent_goods) {
+            $head .= '<th>商品名称</th>';
+        }
         foreach ($col as $k => $v) {
             if (!$update && strstr($v, '^')) {
                 continue;
@@ -257,6 +273,10 @@ class Sku
 
             $body .= '<tr>';
 
+            if ($parent_goods) {
+                $body .= '<td>'.$parent_goods['name'].'</td>';
+            }
+
             foreach ($col as $k1 => $v1) {
                 if (!$update && strstr($v1, '^')) {
                     continue;
@@ -294,6 +314,10 @@ class Sku
             foreach ($option as $k => $v) {
                 $body .= '<tr data-row="' .($k+1). '">';
 
+                if ($parent_goods) {
+                    $body .= '<td>'.$parent_goods['name'].'</td>';
+                }
+
                 $key = $id = array();
                 foreach ($v['name'] as $k1 => $v1) {
                     $rows = 1;

+ 59 - 1
app/shop/database/buy_order.php

@@ -197,6 +197,18 @@ return array
             //'show'        => 'status=5',
         ),
 
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -239,6 +251,52 @@ return array
 
     'request' => array
     (
-        
+        # 获取订单数量
+        'getOrderNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
+
+        # 获取总金额
+        'getCashNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(price) as total',
+        ),
+
+        # 获取商品数量
+        'getGoodsNum' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'shop_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => 'sum(num) as total',
+        ),
     ),
 );

+ 17 - 1
app/shop/database/coupon.php

@@ -69,7 +69,8 @@ return array
             'default'   => '',
             'desc'      => '城市',
             'match'     => 'option',
-            //'update'  => 'text',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_city'),
         ),
 
         'day'        => array
@@ -142,6 +143,7 @@ return array
             # 匹配的正则或函数 选填项
             'option' => array
             (
+                'id' => 'yes',
                 'shop_id' => 'yes',
                 'coupon_id' => 'yes',
                 'state' => 1,
@@ -151,6 +153,20 @@ return array
             'col' => '*,num-act_num as total',
         ),
 
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'id' => 'yes',
+                'shop_id' => 'yes',
+                'coupon_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*,num-act_num as total',
+        ),
+
         # 更新使用量
         'updateNum' => array
         (

+ 26 - 1
app/shop/database/coupon_act_1.php

@@ -90,6 +90,31 @@ return array
 
     'request' => array
     (
-        
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'shop_coupon_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*',
+        ),
+
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'shop_id' => 'yes',
+                'shop_coupon_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*',
+        ),
     ),
 );

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

@@ -143,7 +143,7 @@ return array
         # 列表里的按钮
         'list_button' => array
         (
-            'fast_list' => array('库存设置', '"info_sku&project=goods&goods_id={goods_id}&other=shop&other_id={shop_id}&page_type=1"', 'price_type <= 2'),
+            'fast_list' => array('库存设置', '"info_sku&project=goods&goods_id={goods_id}&other=shop&other_id={shop_id}&page_type=1"', '{price_type} <= 3'),
         ),
     ),
 

+ 14 - 7
app/shop/database/info.php

@@ -13,11 +13,17 @@ $type = array
     2 => '平台店',
 );
 
-$act = array
-(
-    1 => '分享领取优惠券活动',
-    2 => '推广员营销活动',
-);
+$act = function()
+{
+    $array = array();
+    $info = Dever::db('act/info')->select();
+    
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
 
 $yes = array
 (
@@ -513,7 +519,7 @@ return array
 
             'br2' => array('<br /><br />'),
 
-            'list' => array('优惠券管理', '"coupon&search_option_shop_id={id}&oper_table=info"'),
+            'list' => array('优惠券管理', '"coupon&search_option_shop_id={id}&search_option_city={city}&oper_table=info"'),
             'list1' => array('账号管理', '"member&search_option_shop_id={id}&oper_table=info"'),
             'list2' => array('打印机管理', '"print&search_option_shop_id={id}&oper_table=info"'),
 
@@ -533,12 +539,13 @@ return array
             'option' => array
             (
                 'city' => 'yes',
+                'coupon_city' => 'yes',
                 'id' => 'yes',
                 'status' => 1,
                 'state' => 1,
             ),
             'type' => 'one',
-            'col' => 'id,name,`desc`,truename,mobile,lng,lat,address,open,worktime,method,gotime',
+            'col' => 'id,name,`desc`,truename,mobile,lng,lat,address,open,worktime,method,gotime,city,area,province,county,town,coupon_city',
         ),
     ),
 );

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

@@ -648,7 +648,7 @@ return array
                 'start' => array('yes-cdate', '>='),
                 'end' => array('yes-cdate', '<='),
                 'shop_id' => 'yes',
-                'status' => 'yes',
+                'status' => array('yes', 'in'),
                 'state' => 1,
             ),
             'type' => 'count',
@@ -664,10 +664,10 @@ return array
                 'start' => array('yes-cdate', '>='),
                 'end' => array('yes-cdate', '<='),
                 'shop_id' => 'yes',
-                'status' => 'yes',
+                'status' => array('yes', 'in'),
                 'state' => 1,
             ),
-            'type' => 'count',
+            'type' => 'one',
             'col' => 'sum(price) as total',
         ),
 
@@ -680,10 +680,10 @@ return array
                 'start' => array('yes-cdate', '>='),
                 'end' => array('yes-cdate', '<='),
                 'shop_id' => 'yes',
-                'status' => 'yes',
+                'status' => array('yes', 'in'),
                 'state' => 1,
             ),
-            'type' => 'count',
+            'type' => 'one',
             'col' => 'sum(num) as total',
         ),
     ),

+ 2 - 2
app/shop/database/user_coupon.php

@@ -145,7 +145,7 @@ return array
             (
                 'uid' => 'yes',
                 'city' => 'yes',
-                'edate' => array('yes', '<'),
+                'edate' => array('yes', '>='),
                 'status' => 1,
                 'state' => 1,
             ),
@@ -162,7 +162,7 @@ return array
             (
                 'uid' => 'yes',
                 'city' => 'yes',
-                'edate' => array('yes', '<'),
+                'edate' => array('yes', '>='),
                 'status' => 1,
                 'state' => 1,
             ),

+ 145 - 0
app/shop/database/user_share.php

@@ -0,0 +1,145 @@
+<?php
+$status = array
+(
+    1 => '分享中',
+    2 => '已分享',
+);
+
+$act = function()
+{
+    $array = array();
+    $info = Dever::db('act/info')->select();
+    
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+return array
+(
+    # 表名
+    'name' => 'user_share',
+    # 显示给用户看的名称
+    'lang' => '用户活动分享',
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            //'list'        => true,
+        ),
+
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名',
+            'default'   => '0',
+            'desc'      => '请选择用户',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+        ),
+
+        'act_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '活动id',
+            'default'   => '',
+            'desc'      => '活动id',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("act/info-find#name", {act_id})',
+        ),
+
+        'path'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '分享路径',
+            'default'   => '',
+            'desc'      => '分享路径',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '分享状态',
+            'default'   => '1',
+            'desc'      => '分享状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'edate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '失效时间',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+            'list'      => 'date("Y-m-d H:i:s", {edate})',
+        ),
+
+        '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})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        
+    ),
+
+    'request' => array
+    (
+        
+    ),
+);

+ 75 - 4
app/shop/lib/Coupon.php

@@ -6,18 +6,89 @@ use Dever;
 
 class Coupon
 {
+    # 获取分享活动的优惠券列表
     public function getAll($shop_id)
     {
-        $data = Dever::db('shop/coupon')->getData(array('shop_id' => $shop_id));
+        $data = Dever::db('shop/coupon_act_1')->getData(array('shop_id' => $shop_id));
 
         if ($data) {
         	foreach ($data as $k => $v) {
-        		$info = Dever::db('goods/coupon')->one($v['coupon_id']);
-
-        		$data[$k]['name'] = $info['name'];
+                $shop_coupon = Dever::db('shop/coupon')->getOne($v['shop_coupon_id']);
+                if ($shop_coupon) {
+                    $info = Dever::db('goods/coupon')->one($shop_coupon['coupon_id']);
+                    if (!$info) {
+                        continue;
+                    }
+                    $data[$k]['cash'] = $info['cash'];
+                    $data[$k]['total_cash'] = $info['total_cash'];
+                    $data[$k]['total'] = $shop_coupon['total'];
+                    $data[$k]['shop_coupon_id'] = $v['shop_coupon_id'];
+                    $data[$k]['name'] = $info['name'];
+                } else {
+                    continue;
+                }
         	}
         }
 
         return $data;
     }
+
+    # 验证是否可以领取
+    public function getOne($uid, $shop, $shop_coupon_id)
+    {
+        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 (!$data) {
+            return false;
+        }
+
+        $data = Dever::db('shop/coupon')->getOne($shop_coupon_id);
+
+        if (!$data) {
+            return false;
+        }
+
+        if ($data['total'] <= 0) {
+            return false;
+        }
+
+        $user = Dever::db('shop/user_coupon')->find(array('uid' => $uid, 'shop_coupon_id' => $data['id'], 'status' => 1));
+
+        if ($user) {
+            return false;
+        }
+
+        $state = Dever::load('shop/lib/share')->getOne($uid, $shop['id'], 1);
+        if (!$state) {
+            return false;
+        }
+
+        $state = Dever::load('shop/lib/coupon.take_commit', $uid, $shop, $data);
+        if ($state) {
+            return true;
+        }
+
+        return false;
+    }
+
+    # 领取
+    public function take_commit($uid, $shop, $shop_coupon)
+    {
+        $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);
+        $id = Dever::db('shop/user_coupon')->insert($data);
+
+        if ($id) {
+            Dever::db('shop/coupon')->updateNum(array('where_id' => $shop_coupon['id'], 'act_num' => 1));
+        }
+
+        return $id;
+    }
 }

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

@@ -125,7 +125,7 @@ class Info
 
             $sku_id = $sku_id ? $sku_id : $data['sku_id'];
             $data['total'] = 0;
-            if ($data['price_type'] == 3) {
+            if ($data['price_type'] == 4) {
                 if (isset($data['goods']) && is_array($data['goods'])) {
                     foreach ($data['goods'] as $k => $v) {
                         $data['goods'][$k]['total'] = $this->getTotal($other, -1);

+ 40 - 0
app/shop/lib/Share.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Shop\Lib;
+
+use Dever;
+
+class Share
+{
+    # 验证是否已经分享
+    public function getOne($uid, $shop_id, $act_id)
+    {
+    	$where['uid'] = $uid;
+    	$where['shop_id'] = $shop_id;
+    	$where['act_id'] = $act_id;
+    	$where['status'] = 1;
+        $info = Dever::db('shop/user_share')->find($where);
+
+        if ($info) {
+        	Dever::db('shop/user_share')->update(array('where_id' => $info['id'], 'status' => 2));
+        }
+        return $info;
+    }
+
+    # 分享
+    public function up($uid, $shop_id, $act_id, $path = '')
+    {
+        $data['uid'] = $uid;
+        $data['shop_id'] = $shop_id;
+        $data['act_id'] = $act_id;
+        $where['status'] = 1;
+        $info = Dever::db('shop/user_share')->find($where);
+        if (!$info) {
+        	$data['path'] = $path;
+	        $id = Dever::db('shop/user_share')->insert($data);
+
+	        return $id;
+        }
+        return true;
+    }
+}

+ 49 - 16
app/shop/src/Buy.php

@@ -17,15 +17,47 @@ class Buy extends Core
             Dever::alert('请选择门店');
         }
 
-        $this->shop = Dever::db('shop/info')->find($this->shop_id);
+        $this->shop = Dever::db('shop/info')->getOne($this->shop_id);
 
         if (!$this->shop) {
             Dever::alert('门店不存在');
         }
+    }
 
-        if ($this->shop['status'] != 1) {
-            Dever::alert('门店不存在');
+    # 分享
+    public function share()
+    {
+        $act_id = Dever::input('act_id', 1);
+        $path = Dever::input('path');
+        $this->data = Dever::load('shop/lib/share')->up($this->uid, $this->shop_id, $act_id, $path);
+
+        return $this->data;
+    }
+
+    # 获取店铺的优惠券
+    public function getCoupon()
+    {
+        $this->data['coupon'] = Dever::load('shop/lib/coupon')->getAll($this->shop_id);
+
+        $this->data['shop'] = $this->shop;
+
+        return $this->data;
+    }
+
+    # 领取优惠券 也得判断一下用户是否有权限领取
+    public function takeCoupon()
+    {
+        # 验证这个券是否可以领取
+        $shop_coupon_id = Dever::input('shop_coupon_id');
+        $coupon = explode(',', $shop_coupon_id);
+
+        $this->data['take'] = array();
+        foreach ($coupon as $k => $v) {
+            $this->data['take']['shop_coupon_id'] = $v;
+            $this->data['take']['status'] = Dever::load('shop/lib/coupon')->getOne($this->uid, $this->shop, $v);
         }
+
+        return $this->data;
     }
 
     # 获取商品详细信息
@@ -147,7 +179,7 @@ class Buy extends Core
             Dever::alert('付款价格错误');
         }
 
-        $coupon_id = Dever::input('coupon_id');
+        $user_coupon_id = Dever::input('user_coupon_id');
 
         $this->data['user_coupon_id'] = 0;
         $this->data['coupon_id'] = 0;
@@ -170,7 +202,7 @@ class Buy extends Core
                         $kou = false;
                         if ($coupon_info['type'] == 1) {
                             # 满减券
-                            if ($price >= $coupon_info['total']) {
+                            if ($price >= $coupon_info['total_cash']) {
                                 $kou = true;
                             }
                         } else {
@@ -178,14 +210,15 @@ class Buy extends Core
                         }
 
                         if ($kou) {
+                            $coupon_info['user_coupon_id'] = $v['id'];
                             $coupon_info['uid'] = $v['uid'];
                             $coupon_info['shop_id'] = $v['shop_id'];
                             $coupon_info['edate'] = date('Y-m-d', $v['edate']);
                             $this->data['coupon'][] = $coupon_info;
 
-                            if (!$coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
-                                $this->data['user_coupon_id'] = $coupon['id'];
-                                $this->data['coupon_id'] = $v['id'];
+                            if (!$user_coupon_id && $this->data['coupon_cash'] <= $coupon_info['cash']) {
+                                $this->data['user_coupon_id'] = $v['id'];
+                                $this->data['coupon_id'] = $coupon_info['id'];
                                 $this->data['coupon_cash'] = $coupon_info['cash'];
                             }
                         }
@@ -194,13 +227,13 @@ class Buy extends Core
             }
         }
 
-        if ($coupon_id) {
-            $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $coupon_id, 'status' => 1));
+        if ($user_coupon_id) {
+            $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $this->uid, 'id' => $user_coupon_id, 'status' => 1));
             if (!$coupon) {
                 Dever::alert('优惠券不可用');
             }
             if (time() > $coupon['edate']) {
-                Dever::db('shop/user_coupon')->update(array('where_id' => $coupon_id, 'status' => 2));
+                Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
                 Dever::alert('优惠券已过期');
             }
 
@@ -216,15 +249,15 @@ class Buy extends Core
             }
 
             $goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
-            if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total']) {
+            if ($goods_coupon['type'] == 2 && $this->data['price'] < $goods_coupon['total_cash']) {
                 Dever::alert('优惠券不可用');
             }
-            if ($goods_coupon['method'] != $method || $goods_coupon['method'] != 3) {
+            if ($goods_coupon['method'] != $method && $goods_coupon['method'] != 3) {
                 Dever::alert('优惠券不可用');
             }
 
-            $this->data['user_coupon_id'] = $coupon['id'];
-            $this->data['coupon_id'] = $coupon_id;
+            $this->data['user_coupon_id'] = $user_coupon_id;
+            $this->data['coupon_id'] = $goods_coupon['id'];
             $this->data['coupon_cash'] = $goods_coupon['cash'];
         }
 
@@ -240,7 +273,7 @@ class Buy extends Core
     private function goods()
     {
         # 1自提,2配送
-        $this->data['method'] = Dever::input('method');
+        $this->data['method'] = Dever::input('method', 1);
         $this->data['pay_method'] = Dever::input('pay_method');
         $card = Dever::input('card');
         $pwd = Dever::input('pwd');

+ 6 - 2
app/shop/src/My.php

@@ -35,14 +35,18 @@ class My extends Core
         $this->data = Dever::db('shop/user_coupon')->getAllPage(array('uid' => $this->uid));
 
         if ($this->data) {
+            $time = time();
             foreach ($this->data as $k => $v) {
+                if ($time > $v['edate']) {
+                    $this->data[$k]['status'] = 3;
+                }
                 $this->data[$k]['edate'] = date('Y-m-d', $v['edate']);
                 $this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
                 $this->data[$k]['shop'] = array();
                 $coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
 
                 foreach ($coupon as $k1 => $v1) {
-                    $shop = Dever::db('shop/info')->find(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
+                    $shop = Dever::db('shop/info')->getOne(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
                     if ($shop) {
                         $this->data[$k]['shop'][] = $shop;
 
@@ -56,7 +60,7 @@ class My extends Core
                 }
 
                 if (!$this->data[$k]['shop']) {
-                    $shop = Dever::db('shop/info')->find($v['shop_id']);
+                    $shop = Dever::db('shop/info')->getOne($v['shop_id']);
                     $this->data[$k]['shop'][] = $shop;
                     $this->data[$k]['shop_name'] = $shop['name'];
                 }

+ 17 - 5
package/manage/plugin/Console.php

@@ -8,6 +8,18 @@ class Console
 {
     public function data()
     {
+        $where['start'] = Dever::maketime(date('Y-m-d 00:00:00'));
+        $where['end'] = Dever::maketime(date('Y-m-d 59:59:59'));
+
+        $where['status'] = '1,2,3,4';
+        $today_sell_cash = Dever::db('shop/sell_order')->getCashNum($where);
+        $today_sell_order = Dever::db('shop/sell_order')->getOrderNum($where);
+
+        $where['status'] = '1,2,3,4,5,6';
+        $today_buy_cash = Dever::db('shop/buy_order')->getCashNum($where);
+        $today_buy_order = Dever::db('shop/buy_order')->getOrderNum($where);
+
+        $today_user = Dever::db('passport/user')->total($where);
         $user = Dever::db('passport/user')->total();
         $shop = Dever::db('shop/info')->total();
         $factory = Dever::db('factory/info')->total();
@@ -17,35 +29,35 @@ class Console
         $data[] = array
         (
             'name' => '当日销售额',
-            'num' => $total,
+            'num' => $today_sell_cash['total'] ? $today_sell_cash['total'] : 0,
             'href' => '#',
         );
 
         $data[] = array
         (
             'name' => '销售订单量',
-            'num' => $total,
+            'num' => $today_sell_order,
             'href' => '#',
         );
 
         $data[] = array
         (
             'name' => '采购额',
-            'num' => $total,
+            'num' => $today_buy_cash['total'] ? $today_buy_cash['total'] : 0,
             'href' => '#',
         );
 
         $data[] = array
         (
             'name' => '采购订单量',
-            'num' => $total,
+            'num' => $today_buy_order,
             'href' => '#',
         );
 
         $data[] = array
         (
             'name' => '当日用户新增',
-            'num' => $total,
+            'num' => $today_user,
             'href' => '#',
         );