dever 3 lat temu
rodzic
commit
006f366696

+ 17 - 18
app/card/database/info.php

@@ -1,10 +1,9 @@
 <?php
 $status = Dever::config('base')->status;
-$type = array
-(
-    1 => '永久有效',
-    2 => '固定天数',
-);
+$type = function()
+{
+    return Dever::db('card/type')->select();
+};
 
 $card_type = array
 (
@@ -20,7 +19,7 @@ return array
     # 表名
     'name' => 'info',
     # 显示给用户看的名称
-    'lang' => '礼品卡配置',
+    'lang' => '面值配置',
     # 后台菜单排序
     'order' => 99,
     # 数据结构
@@ -50,6 +49,18 @@ return array
             'list'      => true,
         ),
 
+        'type_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '礼品卡类型',
+            'default'   => '1',
+            'desc'      => '礼品卡类型',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $type,
+            'control'   => 'type',
+        ),
+
         'value'        => array
         (
             'type'      => 'int-11',
@@ -70,18 +81,6 @@ return array
             'update'    => 'text',
         ),
 
-        'type'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '礼品卡类型',
-            'default'   => '1',
-            'desc'      => '礼品卡类型',
-            'match'     => 'is_numeric',
-            'update'    => 'radio',
-            'option'    => $type,
-            'control'   => 'type',
-        ),
-
         'day'        => array
         (
             'type'      => 'int-11',

+ 0 - 9
app/card/database/order.php

@@ -58,15 +58,6 @@ return array
             'desc'      => '手机号',
             'match'     => 'option',
             'search'    => 'fulltext',
-            /*
-            'search'    => array
-            (
-                'api' => 'passport/user-select',//接口地址,最好是获取多条数据的地址
-                'col' => 'mobile',//要查询的字段
-                'result' => 'id',//返回的字段
-                'search' => 'uid',//本表的字段,默认为当前的字段
-            ),
-            */
         ),
 
         'shop_id'      => array

+ 1 - 0
app/card/database/order_card.php

@@ -155,6 +155,7 @@ return array
             # 匹配的正则或函数 选填项
             'option' => array
             (
+                'uid' => 'yes',
                 'order_id' => 'yes',
                 'status' => array('yes', 'in'),
                 'state' => 1,

+ 205 - 0
app/card/database/type.php

@@ -0,0 +1,205 @@
+<?php
+$type = array
+(
+    1 => '平台购买',
+    2 => '门店购买',
+);
+
+$shop_type = Dever::db('shop/info')->config['config_type'];
+
+$city_type = array
+(
+    1 => '全国可用',
+    2 => '所选城市可用',
+);
+
+$city = function() {
+    return Dever::load('shop/lib/info')->getCity();
+};
+
+return array
+(
+    # 表名
+    'name' => 'type',
+    # 显示给用户看的名称
+    'lang' => '类型配置',
+    # 后台菜单排序
+    'order' => -1,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+        ),
+        
+        'name'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '类型名称',
+            'default'   => '',
+            'desc'      => '类型名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '类型描述',
+            'default'   => '',
+            'desc'      => '类型描述',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+        ),
+
+        'type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买方式',
+            'default'   => '1',
+            'desc'      => '购买方式',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $type,
+            'search'    => 'radio',
+            'list'      => true,
+        ),
+
+        'shop_type'        => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '可用门店类型',
+            'default'   => '',
+            'desc'      => '可用门店类型',
+            'match'     => 'is_string',
+            'update'    => 'checkbox',
+            'option'    => $shop_type,
+            'list'      => true,
+        ),
+
+        'city_type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '可用范围',
+            'default'   => '1',
+            'desc'      => '可用范围',
+            'match'     => 'is_numeric',
+            'update'    => 'radio',
+            'option'    => $city_type,
+            'list'      => true,
+            'control'   => 'city_type',
+        ),
+
+        'city'        => array
+        (
+            'type'      => 'varchar-2000',
+            'name'      => '选择城市',
+            'default'   => '',
+            'desc'      => '选择城市',
+            'match'     => 'is_string',
+            'update'    => 'checkbox',
+            'option'    => $city,
+            'show'      => 'city_type=2',
+        ),
+
+        'cover'     => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '封面图',
+            'default'   => '',
+            'desc'      => '封面图',
+            'match'     => 'option',
+            'update'    => 'image',
+            'key'       => '1',
+            'place'     => '300*300',
+        ),
+
+        'content'       => array
+        (
+            'type'      => 'text-255',
+            'name'      => '购买使用须知',
+            'default'   => '',
+            'desc'      => '购买使用须知',
+            'match'     => 'is_string',
+            'update'    => 'editor',
+            'key'       => '1',
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序-数值越大越靠前,相当于置顶',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            //'update'  => 'text',
+            'search'    => 'order',
+            'list'      => true,
+            'order'     => 'desc',
+            '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,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'default' => array
+    (
+        'col' => 'id,name,type,shop_type,city_type,reorder,state,cdate',
+        'value' => array
+        (
+            '1,"通用卡", 1, "1,2,10", 1, 10, 1,' . DEVER_TIME,
+            '2,"商超卡", 1, "2", 1, 9, 1,' . DEVER_TIME,
+            '3,"城市卡", 1, "1,2", 2, 8, 1,' . DEVER_TIME,
+            '4,"体验卡", 2, "1", 1, 7, 1,' . DEVER_TIME,
+            '5,"门店卡", 2, "1,2", 1, 6, 1,' . DEVER_TIME,
+        ),
+    ),
+
+    'manage' => array
+    (
+        //'delete' => false,
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
+    ),
+);

+ 172 - 0
app/card/database/use_log.php

@@ -0,0 +1,172 @@
+<?php
+
+$status = array
+(
+    1 => '正常',
+    2 => '申请退款中',
+    3 => '已取消',
+);
+
+return array
+(
+    # 表名
+    'name' => 'use_log',
+    # 显示给用户看的名称
+    'lang' => '使用记录',
+    'menu' => false,
+    'status' => $status,
+    # 数据结构
+    '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-one',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
+        ),
+
+        'card_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '礼品卡名称',
+            'default'   => '',
+            'desc'      => '礼品卡名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("card/info-find#name", {card_id})',
+        ),
+        
+        'order_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '零售订单表id',
+            'default'   => '',
+            'desc'      => '订单表id',
+            'match'     => 'is_numeric',
+        ),
+
+        'use_cash'        => array
+        (
+            'type'      => 'varchar-11',
+            'name'      => '使用金额',
+            'default'   => '0',
+            'desc'      => '使用金额',
+            'match'     => 'is_string',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            '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})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'delete' => false,
+        //'page_list' => 'sell_order_goods',
+    ),
+
+    'request' => array
+    (
+        # 获取单条数据
+        'getIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'card_id' => 'yes',
+                'order_id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*|id',
+        ),
+
+        # 获取多条数据
+        'getDataByIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'uid' => 'yes',
+                'card_id' => 'yes',
+                'order_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
+
+        # 获取多条数据
+        'getTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'order_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
+    ),
+);

+ 172 - 0
app/card/database/user_card.php

@@ -0,0 +1,172 @@
+<?php
+
+$status = array
+(
+    1 => '正常',
+    2 => '申请退款中',
+    3 => '已取消',
+);
+
+return array
+(
+    # 表名
+    'name' => 'user_card',
+    # 显示给用户看的名称
+    'lang' => '用户礼品卡',
+    'menu' => false,
+    'status' => $status,
+    # 数据结构
+    '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-one',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => 'Dever::load("shop/lib/manage.user", {id})',
+        ),
+
+        'card_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '礼品卡名称',
+            'default'   => '',
+            'desc'      => '礼品卡名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("card/info-find#name", {card_id})',
+        ),
+
+        'total_cash'        => array
+        (
+            'type'      => 'varchar-11',
+            'name'      => '总金额',
+            'default'   => '0',
+            'desc'      => '总金额',
+            'match'     => 'is_string',
+        ),
+
+        'use_cash'        => array
+        (
+            'type'      => 'varchar-11',
+            'name'      => '已用金额',
+            'default'   => '0',
+            'desc'      => '已用金额',
+            'match'     => 'is_string',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            '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})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'delete' => false,
+        //'page_list' => 'sell_order_goods',
+    ),
+
+    'request' => array
+    (
+        # 获取单条数据
+        'getIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'card_id' => 'yes',
+                'order_id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*|id',
+        ),
+
+        # 获取多条数据
+        'getDataByIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'uid' => 'yes',
+                'card_id' => 'yes',
+                'order_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
+
+        # 获取多条数据
+        'getTotal' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'order_id' => 'yes',
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'count',
+            'col' => '*',
+        ),
+    ),
+);

+ 577 - 0
app/card/lib/Buy.php

@@ -0,0 +1,577 @@
+<?php
+
+# 支付
+
+namespace Card\Lib;
+
+use Dever;
+
+class Buy
+{
+    # 1是门店,2是仓库,3是工厂,1,2,3是查看采购人的订单,11,12,13是查看供货商的订单
+    public $type = 1;
+    # 1是列表,2是详情
+    public $view = 1;
+    # 获取配置
+    public $config = array();
+    # table
+    public $table = 'shop/buy_order';
+
+    public function __construct()
+    {
+        $this->config = Dever::db($this->table)->config;
+    }
+
+    # 设置订单的类型
+    public function set($type, $view)
+    {
+        $this->type = $type;
+        $this->view = $view;
+
+        return $this;
+    }
+
+
+    # 获取公共的where
+    public function where($id)
+    {
+        $where = array();
+        if ($this->type > 10) {
+            $type = $this->type - 10;
+            $where['source_type'] = $type;
+            $where['source_id'] = $id;
+        } else {
+            $where['type'] = $this->type;
+            $where['type_id'] = $id;
+        }
+        
+        if (!$where) {
+            Dever::alert('参数错误');
+        }
+
+        return $where;
+    }
+
+    # 获取订单列表
+    public function getList($id)
+    {
+        $result = array();
+        $where = $this->where($id);
+        $status = Dever::input('status');
+        if ($status) {
+            if ($status == 'refund') {
+                $where['refund_status'] = 2;
+            } else {
+                $where['status'] = $status;
+            }
+        }
+
+        $order_num = Dever::input('order_num');
+        if ($order_num) {
+            $where['order_num'] = $order_num;
+        }
+
+        $refund_status = Dever::input('refund_status');
+        if ($refund_status) {
+            $where['refund_status'] = $refund_status;
+        }
+
+        $result['search_value'] = $where;
+        $result['search_value']['day'] = $day = Dever::input('day');
+        if ($day) {
+            if ($this->type > 10) {
+                $where['start_o'] = Dever::maketime($day . ' 00:00:00');
+                $where['end_o'] = Dever::maketime($day . ' 23:59:59');
+            } elseif ($this->type == 2) {
+                $where['start_f'] = Dever::maketime($day . ' 00:00:00');
+                $where['end_f'] = Dever::maketime($day . ' 23:59:59');
+            } else {
+                $where['start'] = Dever::maketime($day . ' 00:00:00');
+                $where['end'] = Dever::maketime($day . ' 23:59:59');
+            }
+        }
+
+        $result['search_value']['start'] = $start = Dever::input('start');
+        $result['search_value']['end'] = $end = Dever::input('end');
+        if ($start && $end) {
+            if ($this->type > 10) {
+                $where['start_o'] = Dever::maketime($start);
+                $where['end_o'] = Dever::maketime($end);
+            } elseif ($this->type == 2) {
+                $where['start_f'] = Dever::maketime($start);
+                $where['end_f'] = Dever::maketime($end);
+            } else {
+                $where['start'] = Dever::maketime($start);
+                $where['end'] = Dever::maketime($end);
+            }
+        }
+
+        $excel = Dever::input('excel', 1);
+        if ($excel == 2) {
+            $result['order'] = Dever::db($this->table)->getData($where);
+        } else {
+            $result['order'] = Dever::db($this->table)->getAll($where);
+        }
+
+        if ($result['order']) {
+            foreach ($result['order'] as $k => $v) {
+                $result['order'][$k] = $this->getInfo($v);
+            }
+        }
+
+        $result['search'] = array();
+        $result['search']['status'] = array
+        (
+            array('value' => 1, 'name' => '待支付'),
+            array('value' => 2, 'name' => '待审核'),
+            array('value' => 3, 'name' => '待发货'),
+            array('value' => 4, 'name' => '待收货确认'),
+            array('value' => 5, 'name' => '已完成'),
+            array('value' => 6, 'name' => '已完成(有退款)'),
+            array('value' => '7,8,11', 'name' => '已取消'),
+        );
+
+        $result['config'] = Dever::db('main/manage_config')->find();
+
+        return $result;
+    }
+
+    # 查看详情
+    public function getView($id, $order_id, $show = true)
+    {
+        $where = $this->where($id);
+        $where['id'] = $order_id;
+
+        $result = Dever::db($this->table)->find($where);
+
+        if (!$result) {
+            Dever::alert('订单不存在');
+        }
+
+        if ($show) {
+            $result = $this->getInfo($result, true);
+        }
+
+        $result['config'] = Dever::db('main/manage_config')->find();
+
+        return $result;
+    }
+
+    # 获取订单详细信息
+    public function getInfo($info, $view = false)
+    {
+        if ($info['status'] == 1) {
+            # 15分钟内支付,900秒
+            $m = 900;
+            # 支付倒计时
+            $info['time'] = time() - $info['cdate'];
+            if ($info['time'] >= $m) {
+                # 已过期,自动取消
+                $info['time'] = -1;
+                Dever::db($this->table)->update(array('where_id' => $info['id'], 'status' => 11));
+                $info['status'] = 11;
+            } else {
+                $info['time'] = $m - $info['time'];
+            }
+        }
+
+        $info['status_name'] = $this->config['status'][$info['status']];
+
+        $info['goods'] = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
+        if ($info['type'] == 1) {
+            $info['type_info'] = Dever::db('shop/info')->getOne($info['type_id']);
+        } elseif ($info['type'] == 2) {
+            $info['type_info'] = Dever::db('store/info')->find($info['type_id']);
+        } elseif ($info['type'] == 3) {
+            $info['type_info'] = Dever::db('factory/info')->find($info['type_id']);
+        }
+
+        if ($info['source_type'] == 1) {
+            $info['source_info'] = Dever::db('shop/info')->getOne($info['source_id']);
+        } elseif ($info['source_type'] == 2) {
+            $info['source_info'] = Dever::db('store/info')->find($info['source_id']);
+        } elseif ($info['source_type'] == 3) {
+            $info['source_info'] = Dever::db('factory/info')->find($info['source_id']);
+        }
+        
+        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+        if ($info['operdate']) {
+            $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
+        } else {
+            $info['operdate'] = $info['cdate'];
+        }
+        $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
+        $goods_process = Dever::db('shop/buy_order_refund')->config['process'];
+        if ($view || $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']);
+                $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']];
+            }
+        }
+
+        if (!$info['refund_cash']) {
+            $info['refund_cash'] = 0;
+        }
+
+        # 配送信息
+        $info['ps_info'] = Dever::db('shop/buy_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']['ydate']) {
+                $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
+            }
+
+            $status = Dever::db('shop/buy_order_ps')->config['status'];
+            $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
+            
+            if ($info['ps_info']['service_id'] > 0) {
+                $service = Dever::db('shop/service')->find($info['ps_info']['service_id']);
+                $info['ps_info']['service_name'] = $service['name'];
+            }
+        }
+
+        return $info;
+    }
+
+    # 发起支付
+    public function pay($uid, $type, $type_id, $name, $num, $goods, $price, $info, $refer = '')
+    {
+        $openid = false;
+        if ($uid > 0) {
+            $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 2));
+
+            if (!$wechat) {
+                Dever::alert('错误的用户信息');
+            }
+
+            $openid = $wechat['openid'];
+        }
+
+        $order_data['type'] = $type;
+        $order_data['type_id'] = $type_id;
+        $order_data['name'] = $name;
+        $order_data['num'] = $num;
+        $order_data['info'] = $info;
+        $order_data['price'] = $price;
+
+        $order_data['order_num'] = $this->getOrderId();
+        $order_data['refund_cash'] = 0;
+        $order_data['refund_p_cash'] = 0;
+        $id = Dever::db('shop/buy_order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('支付失败');
+        }
+
+        foreach($goods as $k => $v) {
+            $data['order_id'] = $id;
+            $data['goods_id'] = $v['id'];
+            $data['sku_id'] = $v['sku_id'];
+            $data['price'] = $v['price'];
+            $data['num'] = $v['buy_num'];
+
+            Dever::db('shop/buy_order_goods')->insert($data);
+        }
+
+        if ($price <= 0) {
+
+            $param['pay_product_id'] = $id;
+            $param['pay_order_id'] = $order_data['order_num'];
+            $param['pay_status'] = 2;
+            $param['pay_cash'] = $price;
+            $param['pay_msg'] = '';
+            $this->success($param);
+            return array
+            (
+                'order' => '',
+                'order_num' => $order_data['order_num'],
+                'order_id' => $id,
+                'type' => 'pay',
+            );
+        }
+
+        $param = array
+        (
+            'project_id' => 2,
+            'channel_id' => 1,
+            'system_source' => 5,
+            'uid' => $uid,
+            'name' => $order_data['name'],
+            'openid' => $openid,
+            'cash' => $price,
+            'product_id' => $id,
+            'order_id' => $order_data['order_num'],
+            'refer' => $refer,
+        );
+
+        $receipt = Dever::input('receipt');
+        if ($receipt) {
+            $param['receipt'] = $receipt;
+        }
+
+        $result = Dever::load('pay/api.pay', $param);
+        //$result['type'] = 'test';
+        //$result['order'] = '';
+
+        $result['order_num'] = $order_data['order_num'];
+        $result['order_id'] = $id;
+        return $result;
+    }
+
+    # 再次发起支付
+    public function raction($id, $refer = '')
+    {
+        $order = Dever::db('shop/buy_order')->find($id);
+
+        if (!$order) {
+            Dever::alert('订单信息错误');
+        }
+
+        if ($order['status'] > 1) {
+            Dever::alert('订单已支付或已取消');
+        }
+
+        $param = array
+        (
+            'project_id' => 2,
+            'channel_id' => 1,
+            'system_source' => 5,
+            'uid' => -1,
+            'name' => $order['name'],
+            'cash' => $order['price'],
+            'product_id' => $id,
+            'order_id' => $order['order_num'],
+            'refer' => $refer,
+        );
+
+        $receipt = Dever::input('receipt');
+        if ($receipt) {
+            $param['receipt'] = $receipt;
+        }
+
+        $result = Dever::load('pay/api.pay', $param);
+        $result['order_num'] = $order['order_num'];
+        $result['order_id'] = $id;
+
+        return $result;
+    }
+
+    # 查询是否支付
+    public function cpay($id, $system_source = 5, $refer = '')
+    {
+        $order = Dever::db('shop/buy_order')->find($id);
+
+        if (!$order) {
+            Dever::alert('订单信息错误');
+        }
+
+        $result['order_num'] = $order['order_num'];
+        $result['order_id'] = $id;
+
+        if ($order['status'] > 1 && $order['status'] <= 6) {
+            # 已支付
+            $result['status'] = 1;
+        } else {
+            # 待支付
+            $result['status'] = 2;
+        }
+
+        return $result;
+    }
+
+    # 支付成功回调 安全加密 设置token
+    public function success_secure_api_token()
+    {
+        $project_id = Dever::input('pay_project_id');
+        $info = Dever::db('pay/project')->one($project_id);
+        if ($info) {
+            return $info['key'];
+        }
+        return 'shop_buy_dever_2020';
+    }
+
+    # 支付成功回调 安全加密
+    public function success_secure_api($param = array())
+    {
+        $this->success($param);
+    }
+
+    # 支付成功回调
+    public function success($param = array())
+    {
+        $send = $param ? $param : Dever::preInput('pay_');
+        $product_id = $send['pay_product_id'];
+        $order_id = $send['pay_order_id'];
+        $status = $send['pay_status'];
+        $cash = $send['pay_cash'];
+        $msg = $send['pay_msg'];
+
+        $order = Dever::db('shop/buy_order')->one(array('id' => $product_id, 'time' => time()));
+        if ($order && $order['status'] == 1 && $status == 2) {
+            $update['status'] = 2;
+            $update['where_id'] = $order['id'];
+            Dever::db('shop/buy_order')->update($update);
+
+            # 生成结算单
+            Dever::load('cash/lib/order')->up($order, 1, 1);
+        }
+
+        return 'ok';
+    }
+
+    # 生成订单号
+    public function getOrderId()
+    {
+        $where['order_num'] = Dever::order('C');
+        $state = Dever::db('shop/buy_order')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderId();
+        }
+    }
+
+    # 添加配送信息
+    public function updatePs($order, $status = 1)
+    {
+        $where['order_id'] = $order['id'];
+        $data = Dever::db('shop/buy_order_ps')->find($where);
+
+        if ($data) {
+            $update['where_id'] = $data['id'];
+            $update['status'] = $status;
+            $update['ydate'] = time();
+            Dever::db('shop/buy_order_ps')->update($update);
+        }
+    }
+
+    # 确认收货
+    public function finish($id, $order_id)
+    {
+        $data = $this->getView($id, $order_id, false);
+        if ($data['status'] <= 4) {
+            if ($data['refund_cash'] > 0) {
+                $status = 6;
+            } else {
+                $status = 5;
+            }
+            $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'fdate' => time()));
+            if ($state) {
+                $this->updatePs($data, 3);
+                # 增加库存
+                $where['order_id'] = $data['id'];
+                $where['status'] = 1;
+                $goods = Dever::db('shop/buy_order_goods')->select($where);
+                if ($goods) {
+                    Dever::load('shop/lib/goods')->oper($data, 1, 1, $goods);
+                }
+
+                # 生成结算单
+                Dever::load('cash/lib/order')->up($data, 1, 2);
+            }
+
+            return 'ok';
+        } else {
+            Dever::alert('您没有权限');
+        }
+    }
+
+    # 取消订单
+    public function cancel($id, $order_id)
+    {
+        $data = $this->getView($id, $order_id, false);
+        if ($data['status'] == 1) {
+            $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
+            # 生成结算单
+            if ($state) {
+                //Dever::load('cash/lib/order')->up($data, 1, 3);
+            }
+            return 'ok';
+        } else {
+            Dever::alert('当前订单状态不允许取消');
+        }
+    }
+
+    # 查看订单状态
+    public function orderStatus($id)
+    {
+        $config = Dever::db('shop/buy_order')->config;
+
+        $info = Dever::db('shop/buy_order')->one($id);
+        $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'process' => 1));
+        $status = $config['status'][$info['status']];
+
+        if ($tk) {
+            $status = '申请退款中';
+        }
+        return $status;
+    }
+
+    # 后台审核退款
+    public function refund_commit_api()
+    {
+        $id = Dever::input('id');
+        $process = Dever::input('process');
+        return Dever::load('shop/lib/refund')->set('buy')->action($id, $process, false);
+    }
+
+    # 货物未发出,仅退款
+    public function refund_apply_commit_api()
+    {
+        $order_id = Dever::input('order_id');
+        $type = Dever::input('type');
+        $type_id = Dever::input('type_id');
+        $desc = Dever::input('desc');
+        $pic = Dever::input('pic');
+
+        return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, false, 3, 0, $desc, $pic, 2);
+    }
+
+    # 货物已收到 全部退款 报损 需要审核
+    public function refund_apply_info_commit_api()
+    {
+        $order_id = Dever::input('order_id');
+        $status = Dever::input('status');
+        $desc = Dever::input('desc');
+        $pic = Dever::input('pic');
+        $type = Dever::input('type');
+        $type_id = Dever::input('type_id');
+
+        return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, false, $status, 0, $desc, $pic, 1);
+    }
+
+    # 部分退款信息 报损
+    public function refund_apply_info_one_info()
+    {
+        $order_id = Dever::input('order_id');
+        $order_goods_id = Dever::input('order_goods_id');
+        $type = Dever::input('type');
+        $type_id = Dever::input('type_id');
+
+        return Dever::load('shop/lib/refund')->set('buy')->getInfo($type, $type_id, $order_id, $order_goods_id);
+    }
+
+    # 部分退款 报损
+    public function refund_apply_info_one_commit_api()
+    {
+        $order_id = Dever::input('order_id');
+        $order_goods_id = Dever::input('order_goods_id');
+        $num = Dever::input('num', 0);
+        $status = Dever::input('status');
+        $desc = Dever::input('desc');
+        $pic = Dever::input('pic');
+        $type = Dever::input('type');
+        $type_id = Dever::input('type_id');
+
+        return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, $order_goods_id, $status, $num, $desc, $pic, 1);
+    }
+}

+ 104 - 0
app/card/src/Buy.php

@@ -0,0 +1,104 @@
+<?php
+
+namespace Shop\Src;
+
+use Dever;
+use Main\Lib\Core;
+
+class Buy extends Core
+{
+    public function __construct()
+    {
+        parent::__construct();
+        $this->checkLogin();
+        $this->shop_id = Dever::input('shop_id');
+
+        if (!$this->shop_id) {
+            Dever::alert('请选择门店');
+        }
+
+        $lng = Dever::input('lng');
+        $lat = Dever::input('lat');
+        if ($lng && $lat) {
+            $this->shop = Dever::load('shop/lib/info')->fetch($this->shop_id, false, $lng, $lat, false);
+        } else {
+            $this->shop = Dever::db('shop/info')->getOne($this->shop_id);
+        }
+
+        if (!$this->shop) {
+            Dever::alert('门店不存在');
+        }
+    }
+
+    # 获取礼品卡
+    public function getCard()
+    {
+        $where['type'] = 1;
+        $this->data['card'] = Dever::db('card/type')->getAll($where);
+
+        if ($this->data['card']) {
+            foreach ($this->data['card'] as $k => $v) {
+                $w['type_id'] = $v['id'];
+                $w['status'] = 1;
+                $this->data['card']['value'] = Dever::db('card/info')->select($w);
+            }
+        }
+
+        # 获取选择的城市
+        $this->data['city'] = Dever::load('shop/lib/info')->getCity();
+
+        return $this->data;
+    }
+
+    # 确认订单页面
+    public function confirm()
+    {
+        $this->data['uid'] = $this->uid;
+        $this->data['user'] = $this->user;
+        $this->data['shop'] = $this->shop;
+        Dever::load('card/lib/buy')->getCard($this->data);
+        return $this->data;
+    }
+
+    # 开始下单
+    public function pay_commit()
+    {
+        $refer = Dever::input('refer');
+        $address_id = Dever::input('address_id');
+
+        $this->data['uid'] = $this->uid;
+        $this->data['user'] = $this->user;
+        $this->data['shop'] = $this->shop;
+
+        Dever::load('card/lib/buy')->getCard($this->data);
+
+        if (!$address_id) {
+            Dever::alert('收货地址不能为空');
+        }
+
+        $pay = Dever::load('card/lib/buy')->pay($this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['oprice'], $this->data['price'], $address_id, $refer);
+        return $pay;
+    }
+
+    # 再次付款
+    public function r_pay()
+    {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('shop/lib/sell')->rpay($order_id, 5, $refer);
+
+        return $pay;
+    }
+
+    # 查询是否支付
+    public function c_pay()
+    {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('shop/lib/sell')->cpay($order_id, 5, $refer);
+
+        return $pay;
+    }
+}

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

@@ -375,6 +375,29 @@ class Buy
         return $result;
     }
 
+    # 查询是否支付
+    public function cpay($id, $system_source = 5, $refer = '')
+    {
+        $order = Dever::db('shop/buy_order')->find($id);
+
+        if (!$order) {
+            Dever::alert('订单信息错误');
+        }
+
+        $result['order_num'] = $order['order_num'];
+        $result['order_id'] = $id;
+
+        if ($order['status'] > 1 && $order['status'] <= 6) {
+            # 已支付
+            $result['status'] = 1;
+        } else {
+            # 待支付
+            $result['status'] = 2;
+        }
+
+        return $result;
+    }
+
     # 支付成功回调 安全加密 设置token
     public function success_secure_api_token()
     {

+ 11 - 0
app/mshop/src/Buy.php

@@ -123,6 +123,17 @@ class Buy extends Core
         return $pay;
     }
 
+    # 查询是否支付
+    public function c_pay()
+    {
+        $refer = Dever::input('refer');
+        $order_id = Dever::input('order_id');
+
+        $pay = Dever::load('mshop/lib/buy')->cpay($order_id, 5, $refer);
+
+        return $pay;
+    }
+
     # 取消订单
     public function order_cancel_commit()
     {

+ 16 - 0
app/shop/database/info.php

@@ -681,5 +681,21 @@ return array
             'type' => 'one',
             'col' => $col,
         ),
+
+        # 获取城市
+        'getCity' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'city' => 'yes',
+                'id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'group' => 'city',
+            'col' => $col,
+        ),
     ),
 );

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

@@ -6,6 +6,28 @@ use Dever;
 
 class Info
 {
+    # 获取城市
+    public function getCity()
+    {
+        $city = Dever::db('shop/city')->getCity();
+
+        $result = array();
+        if ($city) {
+            foreach ($city as $k => $v) {
+                $c = Dever::db('area/city')->find($v['city']);
+                if ($c) {
+                    $result[] = array
+                    (
+                        'id' => $v['city'],
+                        'name' => $c['name'],
+                    );
+                }
+            }
+        }
+
+        return $result;
+    }
+
     # 获取店铺基本信息
     public function getOne($shop_id, $lng, $lat)
     {