dever 3 年之前
父節點
當前提交
4760f8acb3
共有 3 個文件被更改,包括 610 次插入0 次删除
  1. 134 0
      app/mshop/src/Out.php
  2. 305 0
      app/shop/database/out_order.php
  3. 171 0
      app/shop/database/out_order_goods.php

+ 134 - 0
app/mshop/src/Out.php

@@ -0,0 +1,134 @@
+<?php
+
+namespace Mshop\Src;
+
+use Dever;
+use Mshop\Lib\Core;
+
+class Out extends Core
+{
+    # 获取所有商品列表
+    public function getGoods()
+    {
+        $where = array();
+
+        $name = Dever::input('name');
+        if ($name) {
+            $where['name'] = $name;
+        }
+        $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);
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 确认订单页面
+    public function confirm()
+    {
+        $this->goods();
+
+        return $this->data;
+    }
+
+    # 得到商品和总价
+    private function goods()
+    {
+        $goods_id = Dever::input('goods_id');
+        if (!$goods_id) {
+            Dever::alert('请传入商品');
+        }
+        $goods_id = explode(',', $goods_id);
+
+        $sku_id = Dever::input('price_id');
+        if ($sku_id) {
+            $sku_id = explode(',', $sku_id);
+        }
+        
+        $num = Dever::input('num');
+        if (!$num) {
+            Dever::alert('请传入商品数量');
+        }
+        $num = explode(',', $num);
+
+        $this->data['price'] = 0;
+        $this->data['num'] = 0;
+        $this->data['name'] = array();
+        $count = count($goods_id);
+        # 计算总价格
+        foreach ($goods_id as $k => $v) {
+            $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]['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()
+    {
+        $info = Dever::input('info');
+
+        $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['price'] = $this->data['price'];
+        $order_data['member_id'] = $this->uid;
+
+        $order_data['area'] = $this->shop['area'];
+        $order_data['province'] = $this->shop['province'];
+        $order_data['city'] = $this->shop['city'];
+        $order_data['county'] = $this->shop['county'];
+        $order_data['town'] = $this->shop['town'];
+
+        $order_data['order_num'] = $this->getOrderId();
+        $id = Dever::db('shop/out_order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('出库失败');
+        }
+
+        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) {
+            	# 出库成功 去掉库存
+            }
+        }
+
+        return 'ok';
+    }
+
+    # 生成订单号
+    public function getOrderId()
+    {
+        $where['order_num'] = Dever::order('OUT');
+        $state = Dever::db('shop/out_order')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->getOrderId();
+        }
+    }
+}

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

@@ -0,0 +1,305 @@
+<?php
+
+$type = array
+(
+    1 => '店铺活动',
+    2 => '礼品赠送',
+    3 => '超过保质期销毁',
+    10 => '其他',
+);
+
+$status = array
+(
+    1 => '已出库',
+);
+
+return array
+(
+    # 表名
+    'name' => 'out_order',
+    # 显示给用户看的名称
+    'lang' => '出库订单',
+    'order' => 99,
+    'menu'	=> false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'      => true,
+        ), 
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+        ),
+
+        'mobile'        => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '下单手机号',
+            'default'   => '',
+            'desc'      => '手机号',
+            'match'     => 'option',
+            'search'    => array
+            (
+                'api' => 'shop/info-select',//接口地址,最好是获取多条数据的地址
+                'col' => 'mobile',//要查询的字段
+                'result' => 'id',//返回的字段
+                'search' => 'shop_id',//本表的字段,默认为当前的字段
+            ),
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '订单名称',
+            'default'   => '',
+            'desc'      => '订单名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+        'order_num'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订单编号',
+            'default'   => '',
+            'desc'      => '订单编号',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'price'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '价格',
+            'default'   => '',
+            'desc'      => '价格',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'        => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '数量',
+            'default'   => '',
+            'desc'      => '数量',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            'list'        => true,
+        ),
+
+        'info'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '订单备注',
+            'default'   => '',
+            'desc'      => '订单备注',
+            'match'     => 'option',
+            'update'    => 'textarea',
+        ),
+
+        'area'       => array
+        (
+            'type'      => 'varchar-500',
+            'name'      => '所在地区',
+            'default'   => '',
+            'desc'      => '所在地区',
+            'match'     => 'option',
+            'search'    => 'linkage',
+            'option'    => Dever::url('api.get?level_total=4', 'area'),
+        ),
+
+        'province'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '省份',
+            'default'   => '',
+            'desc'      => '省份',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'city'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '城市',
+            'default'   => '',
+            'desc'      => '城市',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'county'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '县区',
+            'default'   => '',
+            'desc'      => '县区',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'town'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '街道',
+            'default'   => '',
+            'desc'      => '街道',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'member_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '操作人',
+            'default'   => '',
+            'desc'      => '操作人',
+            'match'     => 'option',
+            //'update'  => 'text',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '出库时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'search'    => 'date',
+            'list'        => 'date("Y-m-d H:i:s", {cdate})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+
+        'button' => array
+        (
+            //'导出订单' => array('location', 'user/lib/manage.out'),
+        ),
+
+        'list_button' => array(
+            //'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin', '{status} == 2'),
+            //'delete' => array('删除', '', '{status} == 1'),
+
+            'fast_list' => array('查看详情', '"buy_order_goods&project=shop&order_id={id}&page_type=1"'),
+        ),
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'name' => array('yes', 'like'),
+                'shop_id' => 'yes',
+                'mobile' => 'yes',
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'status' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'desc'),
+            'page' => array(10, 'list'),
+            'col' => '*',
+        ),
+
+        # 获取订单数量
+        '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',
+        ),
+    ),
+);

+ 171 - 0
app/shop/database/out_order_goods.php

@@ -0,0 +1,171 @@
+<?php
+
+$status = array
+(
+    1 => '正常',
+);
+
+return array
+(
+    # 表名
+    'name' => 'out_order_goods',
+    # 显示给用户看的名称
+    '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,
+        ),
+
+        'shop_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属门店',
+            'default'   => '',
+            'desc'      => '所属门店',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_shop_id'),
+            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
+        ),
+
+        'order_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '订单表id',
+            'default'   => '',
+            'desc'      => '订单表id',
+            'match'     => 'is_numeric',
+        ),
+
+        'goods_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品名称',
+            'default'   => '',
+            'desc'      => '商品名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
+        ),
+
+        'sku_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'sku_id',
+            'default'   => '-1',
+            'desc'      => 'sku_id',
+            'match'     => 'is_numeric',
+        ),
+
+        'price'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '价格',
+            'default'   => '',
+            'desc'      => '价格',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'        => true,
+        ),
+
+        'num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买数量',
+            'default'   => '',
+            'desc'      => '购买数量',
+            'match'     => 'is_numeric',
+            'search'    => 'select',
+            'list'        => true,
+        ),
+
+        '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_table' => 'out_order_goods',
+    ),
+
+    'request' => array
+    (
+        # 获取单条数据
+        'getIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'shop_id' => 'yes',
+                'order_id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*|id',
+        ),
+
+        # 获取多条数据
+        'getDataByIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'uid' => 'yes',
+                'shop_id' => 'yes',
+                'order_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
+    ),
+);