|
@@ -6,14 +6,50 @@ use Dever;
|
|
|
|
|
|
class Out
|
|
class Out
|
|
{
|
|
{
|
|
|
|
+ # 1是门店,2是仓库
|
|
|
|
+ public $type = 1;
|
|
|
|
+ # 1是列表,2是详情
|
|
|
|
+ public $view = 1;
|
|
|
|
+ # 获取配置
|
|
|
|
+ public $config = array();
|
|
|
|
+ # table
|
|
|
|
+ public $table = 'shop/out_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();
|
|
|
|
+ $where['type'] = $this->type;
|
|
|
|
+ $where['type_id'] = $id;
|
|
|
|
+
|
|
|
|
+ if (!$where) {
|
|
|
|
+ Dever::alert('参数错误');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $where;
|
|
|
|
+ }
|
|
|
|
+
|
|
# 采购订单列表
|
|
# 采购订单列表
|
|
- public function getList($type, $id)
|
|
|
|
|
|
+ public function getList($id)
|
|
{
|
|
{
|
|
- $where['use_type'] = $type;
|
|
|
|
- $where['use_id'] = $id;
|
|
|
|
|
|
+ $where = $this->where($id);
|
|
|
|
|
|
- $this->data['search_value'] = $where;
|
|
|
|
- $this->data['search_value']['day'] = $day = Dever::input('day');
|
|
|
|
|
|
+ $data['search_value'] = $where;
|
|
|
|
+ $data['search_value']['day'] = $day = Dever::input('day');
|
|
if ($day) {
|
|
if ($day) {
|
|
$where['start'] = Dever::maketime($day . ' 00:00:00');
|
|
$where['start'] = Dever::maketime($day . ' 00:00:00');
|
|
$where['end'] = Dever::maketime($day . ' 23:59:59');
|
|
$where['end'] = Dever::maketime($day . ' 23:59:59');
|
|
@@ -29,111 +65,52 @@ class Out
|
|
$where['status'] = $status;
|
|
$where['status'] = $status;
|
|
}
|
|
}
|
|
|
|
|
|
- $this->data['order'] = Dever::db('shop/out_order')->getAll($where);
|
|
|
|
|
|
+ $out_type = Dever::input('out_type');
|
|
|
|
+ if ($out_type) {
|
|
|
|
+ $where['out_type'] = $out_type;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data['order'] = Dever::db('shop/out_order')->getAll($where);
|
|
|
|
|
|
- if ($this->data['order']) {
|
|
|
|
- foreach ($this->data['order'] as $k => $v) {
|
|
|
|
- $this->data['order'][$k] = $this->getInfo($v);
|
|
|
|
|
|
+ if ($data['order']) {
|
|
|
|
+ foreach ($data['order'] as $k => $v) {
|
|
|
|
+ $data['order'][$k] = $this->getInfo($v);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return $this->data;
|
|
|
|
|
|
+ return $data;
|
|
}
|
|
}
|
|
|
|
|
|
# 查看订单详情
|
|
# 查看订单详情
|
|
- public function view($type, $id)
|
|
|
|
|
|
+ public function getView($id, $order_id, $show = true)
|
|
{
|
|
{
|
|
- $where['use_type'] = $type;
|
|
|
|
- $where['use_id'] = $id;
|
|
|
|
- $where['id'] = Dever::input('order_id');
|
|
|
|
|
|
+ $where = $this->where($id);
|
|
|
|
+ $where['id'] = $order_id;
|
|
|
|
|
|
- $this->data = Dever::db('shop/out_order')->find($where);
|
|
|
|
|
|
+ $result = Dever::db($this->table)->find($where);
|
|
|
|
|
|
- if (!$this->data) {
|
|
|
|
|
|
+ if (!$result) {
|
|
Dever::alert('订单不存在');
|
|
Dever::alert('订单不存在');
|
|
}
|
|
}
|
|
|
|
|
|
- $this->data = $this->getInfo($this->data, true);
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
|
|
+ if ($show) {
|
|
|
|
+ $result = $this->getInfo($result, true);
|
|
}
|
|
}
|
|
-
|
|
|
|
- $num = Dever::input('num');
|
|
|
|
- if (!$num) {
|
|
|
|
- Dever::alert('请传入商品数量');
|
|
|
|
- }
|
|
|
|
- $num = explode(',', $num);
|
|
|
|
-
|
|
|
|
- $this->data['price'] = 0;
|
|
|
|
- $this->data['num'] = 0;
|
|
|
|
- $this->data['name'] = array();
|
|
|
|
- # 计算总价格
|
|
|
|
- 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]['num'] = $n;
|
|
|
|
-
|
|
|
|
- # 2是库存不足
|
|
|
|
- $this->data['list'][$k]['ku_state'] = 1;
|
|
|
|
-
|
|
|
|
- # 验证是否有货
|
|
|
|
- $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
|
|
|
|
-
|
|
|
|
- if ($total <= 0) {
|
|
|
|
- $this->data['list'][$k]['ku_state'] = 2;
|
|
|
|
- $this->data['list'][$k]['buy_num'] = 0;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if ($this->data['list'][$k]['ku_state'] == 1) {
|
|
|
|
- $this->data['list'][$k]['buy_num'] = $n;
|
|
|
|
- $this->data['num'] += $n;
|
|
|
|
- $this->data['price'] += $this->data['list'][$k]['price'] * $n;
|
|
|
|
- $this->data['name'][] = $this->data['list'][$k]['name'];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->data['name'] = implode(',', $this->data['name']);
|
|
|
|
|
|
+ return $result;
|
|
}
|
|
}
|
|
|
|
|
|
# 出库下单
|
|
# 出库下单
|
|
- public function action_commit()
|
|
|
|
|
|
+ public function action($type_id, $name, $num, $goods, $price, $member_id, $out_type, $info, $status = 2)
|
|
{
|
|
{
|
|
- $info = Dever::input('info');
|
|
|
|
- $type = Dever::input('type', 1);
|
|
|
|
-
|
|
|
|
- $this->goods();
|
|
|
|
-
|
|
|
|
- $order_data['use_type'] = 1;
|
|
|
|
- $order_data['use_id'] = $this->shop['id'];
|
|
|
|
- $order_data['name'] = $this->data['name'];
|
|
|
|
- $order_data['num'] = $this->data['num'];
|
|
|
|
|
|
+ $order_data = $this->where($type_id);
|
|
|
|
+ $order_data['name'] = $name;
|
|
|
|
+ $order_data['num'] = $num;
|
|
$order_data['info'] = $info;
|
|
$order_data['info'] = $info;
|
|
- $order_data['type'] = $type;
|
|
|
|
- $order_data['price'] = $this->data['price'];
|
|
|
|
- $order_data['member_id'] = $this->uid;
|
|
|
|
|
|
+ $order_data['out_type'] = $out_type;
|
|
|
|
+ $order_data['price'] = $price;
|
|
|
|
+ $order_data['member_id'] = $member_id;
|
|
|
|
+ $order_data['status'] = $status;
|
|
|
|
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
$id = Dever::db('shop/out_order')->insert($order_data);
|
|
$id = Dever::db('shop/out_order')->insert($order_data);
|
|
@@ -142,7 +119,7 @@ class Out
|
|
Dever::alert('出库失败');
|
|
Dever::alert('出库失败');
|
|
}
|
|
}
|
|
|
|
|
|
- foreach($this->data['list'] as $k => $v) {
|
|
|
|
|
|
+ foreach($goods as $k => $v) {
|
|
if ($v['ku_state'] == 1) {
|
|
if ($v['ku_state'] == 1) {
|
|
$data['order_id'] = $id;
|
|
$data['order_id'] = $id;
|
|
$data['goods_id'] = $v['id'];
|
|
$data['goods_id'] = $v['id'];
|
|
@@ -174,6 +151,46 @@ class Out
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ # 审核出库单
|
|
|
|
+ public function yes_api()
|
|
|
|
+ {
|
|
|
|
+ $id = Dever::input('id');
|
|
|
|
+ $order_id = Dever::input('order_id');
|
|
|
|
+ $this->set(2, 1);
|
|
|
|
+
|
|
|
|
+ $info = $this->getView($id, $order_id, false);
|
|
|
|
+
|
|
|
|
+ if ($info && $info['status'] == 1) {
|
|
|
|
+ $where['where_id'] = $info['id'];
|
|
|
|
+ $where['status'] = 2;
|
|
|
|
+ $state = Dever::db('shop/out_order')->update($where);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 'ok';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # 取消出库单
|
|
|
|
+ public function cancel($id, $order_id)
|
|
|
|
+ {
|
|
|
|
+ $info = $this->getView($id, $order_id, false);
|
|
|
|
+
|
|
|
|
+ if ($info && $info['status'] == 1) {
|
|
|
|
+ $where['where_id'] = $info['id'];
|
|
|
|
+ $where['status'] = 3;
|
|
|
|
+ $state = Dever::db('shop/out_order')->update($where);
|
|
|
|
+
|
|
|
|
+ if ($state) {
|
|
|
|
+ # 取消成功,恢复库存
|
|
|
|
+ $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id']));
|
|
|
|
+ if ($goods) {
|
|
|
|
+ Dever::load('shop/lib/goods')->oper($info, 1, 1, $goods);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 'ok';
|
|
|
|
+ }
|
|
|
|
+
|
|
# 获取订单详细信息
|
|
# 获取订单详细信息
|
|
private function getInfo($info, $view = false)
|
|
private function getInfo($info, $view = false)
|
|
{
|
|
{
|
|
@@ -181,8 +198,11 @@ class Out
|
|
$info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
$info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
|
|
|
$type = Dever::db('shop/out_order')->config['config_type'];
|
|
$type = Dever::db('shop/out_order')->config['config_type'];
|
|
- $info['type_name'] = $type[$info['type']];
|
|
|
|
- if ($view) {
|
|
|
|
|
|
+ $info['type_name'] = $type[$info['out_type']];
|
|
|
|
+
|
|
|
|
+ $status = Dever::db('shop/out_order')->config['config_status'];
|
|
|
|
+ $info['status_name'] = $status[$info['status']];
|
|
|
|
+ if ($view || $this->view == 2) {
|
|
foreach ($info['goods'] as $k => $v) {
|
|
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]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
|
|
}
|
|
}
|
|
@@ -191,4 +211,209 @@ class Out
|
|
}
|
|
}
|
|
return $info;
|
|
return $info;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ # 展示订单详情
|
|
|
|
+ public function show()
|
|
|
|
+ {
|
|
|
|
+ $id = Dever::input('order_id');
|
|
|
|
+
|
|
|
|
+ $type = Dever::input('type', 1);
|
|
|
|
+
|
|
|
|
+ $config = Dever::db('shop/out_order')->config;
|
|
|
|
+
|
|
|
|
+ $info = Dever::db('shop/out_order')->one($id);
|
|
|
|
+
|
|
|
|
+ $status = $config['config_status'][$info['status']];
|
|
|
|
+
|
|
|
|
+ $out_type = $config['config_type'][$info['out_type']];
|
|
|
|
+
|
|
|
|
+ $cdate = date('Y-m-d H:i', $info['cdate']);
|
|
|
|
+
|
|
|
|
+ $html = '<div class="layui-col-md12"><div class="layui-card"><div class="layui-card-header">基本信息</div><div class="layui-card-body">';
|
|
|
|
+ $html .= '<table class="layui-table"><thead><tr><th style="width:20%">项目</th><th style="width:80%">详情</th></tr> </thead><tbody>';
|
|
|
|
+
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>订单号</td>
|
|
|
|
+ <td>'.$this->table(false, array($info['order_num'])).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>出库单状态</td>
|
|
|
|
+ <td>'.$this->table(false, array($status)).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>填单时间</td>
|
|
|
|
+ <td>'.$this->table(false, array($cdate)).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+
|
|
|
|
+ if ($info['type'] == 1) {
|
|
|
|
+ $type_info = Dever::db('shop/info')->find($info['type_id']);
|
|
|
|
+ $member = Dever::db('shop/member')->find($info['member_id']);
|
|
|
|
+ } elseif ($info['type'] == 2) {
|
|
|
|
+ $type_info = Dever::db('store/info')->find($info['type_id']);
|
|
|
|
+ $member = Dever::db('store/member')->find($info['member_id']);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($type == 1) {
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>来源信息</td>
|
|
|
|
+ <td>'.$this->table(false, array(array($type_info['name'] . ',' . $type_info['truename'] . ',' . $type_info['mobile'] . ',' . $type_info['address']))).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>操作人</td>
|
|
|
|
+ <td>'.$this->table(false, array($member['name'])).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>出库类别</td>
|
|
|
|
+ <td>'.$this->table(false, array($out_type)).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+
|
|
|
|
+ if ($info['info']) {
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>订单备注</td>
|
|
|
|
+ <td>'.$this->table(false, array(array($info['info']))).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($type == 2) {
|
|
|
|
+ $config = Dever::load('store/admin/auth.config');
|
|
|
|
+ $button = array();
|
|
|
|
+ if ($info['status'] == 1) {
|
|
|
|
+ $url = Dever::url('admin/out.cancel?order_id='.$info['id'], 'store');
|
|
|
|
+ $button[] = ' <a href="javascript:;" onclick="load(\''.$url.'\')"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>';
|
|
|
|
+ }
|
|
|
|
+ $button[] = '<button class="layui-btn layui-btn-primary" onclick="print(\''.$info['id'].'\')">打印出库单</button>';
|
|
|
|
+
|
|
|
|
+ $config['phone'] = '您的专属客服:' . $config['kf_name'] . ',联系电话:' . $config['phone'];
|
|
|
|
+ $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系平台</button>';
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>功能按钮</td>
|
|
|
|
+ <td>'.$this->table(false, array($button)).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+ } elseif ($info['status'] == 1) {
|
|
|
|
+ $button = array();
|
|
|
|
+ $url = Dever::url('lib/out.yes?id='.$info['type_id'].'&order_id='.$info['id'], 'mshop');
|
|
|
|
+ $button[] = ' <a href="javascript:;" onclick="load(\''.$url.'\')"><button type="button" class="layui-btn layui-btn-primary">审核</button></a>';
|
|
|
|
+ $html .= '<tr>
|
|
|
|
+ <td>功能按钮</td>
|
|
|
|
+ <td>'.$this->table(false, array($button)).'</td>
|
|
|
|
+
|
|
|
|
+ </tr>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '</tbody></table></div></div>';
|
|
|
|
+
|
|
|
|
+ $body = array();
|
|
|
|
+ $body_total = array();
|
|
|
|
+ $body_total['price'] = 0;
|
|
|
|
+ $body_total['num'] = 0;
|
|
|
|
+ $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id']));
|
|
|
|
+ $goods_status = Dever::db('shop/out_order_goods')->config['status'];
|
|
|
|
+
|
|
|
|
+ $refund_body = array();
|
|
|
|
+ $refund_body_total = array();
|
|
|
|
+ $refund_body_total['price'] = 0;
|
|
|
|
+ $refund_body_total['num'] = 0;
|
|
|
|
+ foreach ($goods as $k => $v) {
|
|
|
|
+ $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
|
|
|
|
+ $status = $goods_status[$v['status']];
|
|
|
|
+
|
|
|
|
+ if (isset($goods_info['sku'])) {
|
|
|
|
+ $sku = '[' . $goods_info['sku']['string'] . ']';
|
|
|
|
+ } else {
|
|
|
|
+ $sku = '';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $d = array
|
|
|
|
+ (
|
|
|
|
+ $goods_info['name'] . ' ' . $sku,
|
|
|
|
+ $v['price'],
|
|
|
|
+ $v['num'],
|
|
|
|
+ );
|
|
|
|
+ if ($type == 2) {
|
|
|
|
+ unset($d[1]);
|
|
|
|
+ }
|
|
|
|
+ $body[] = $d;
|
|
|
|
+ $body_total['price'] += $v['price'];
|
|
|
|
+ $body_total['num'] += $v['num'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($body) {
|
|
|
|
+
|
|
|
|
+ $head = array('名称', '金额', '数量');
|
|
|
|
+
|
|
|
|
+ $d = array
|
|
|
|
+ (
|
|
|
|
+ '合计',
|
|
|
|
+ $body_total['price'],
|
|
|
|
+ $body_total['num'],
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if ($type == 2) {
|
|
|
|
+ unset($head[1]);
|
|
|
|
+ unset($d[1]);
|
|
|
|
+ }
|
|
|
|
+ $body[] = $d;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $html .= '<div class="layui-card"><div class="layui-card-header">商品清单</div><div class="layui-card-body" style="max-heights: 500px;overflow: auto;">' . $this->table($head, $body) . '</div></div>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '</div>';
|
|
|
|
+
|
|
|
|
+ return '<div class="layui-card-body">' . $html . '</div>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function table($head, $data)
|
|
|
|
+ {
|
|
|
|
+ $html = '';
|
|
|
|
+ if ($head) {
|
|
|
|
+ $html = '<table class="layui-table">';
|
|
|
|
+
|
|
|
|
+ $html .= '<thead><tr>';
|
|
|
|
+ foreach ($head as $k => $v) {
|
|
|
|
+ $html .= '<th>'.$v.'</th>';
|
|
|
|
+ }
|
|
|
|
+ $html .= '</tr></thead>';
|
|
|
|
+
|
|
|
|
+ $html .= '<tbody>';
|
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
|
+ $html .= '<tr>';
|
|
|
|
+ foreach ($v as $k1 => $v1) {
|
|
|
|
+ $html .= '<td>'.$v1.'</td>';
|
|
|
|
+ }
|
|
|
|
+ $html .= '</tr>';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '</tbody>';
|
|
|
|
+
|
|
|
|
+ $html .= '</table>';
|
|
|
|
+ } else {
|
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
|
+ $html .= '';
|
|
|
|
+ if (is_array($v)) {
|
|
|
|
+ foreach ($v as $k1 => $v1) {
|
|
|
|
+ $html .= $v1 . ' ';
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $html .= $v . ' ';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $html;
|
|
|
|
+ }
|
|
}
|
|
}
|