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($id) { $where = $this->where($id); $data['search_value'] = $where; $data['search_value']['day'] = $day = Dever::input('day'); if ($day) { $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) { $where['start'] = Dever::maketime($start); $where['end'] = Dever::maketime($end); } $order_num = Dever::input('order_num'); if ($order_num) { $where['order_num'] = $order_num; } $status = Dever::input('status'); if ($status) { $where['status'] = $status; } $out_type = Dever::input('out_type'); if ($out_type) { $where['out_type'] = $out_type; } $data['order'] = Dever::db('shop/out_order')->getAll($where); if ($data['order']) { foreach ($data['order'] as $k => $v) { $data['order'][$k] = $this->getInfo($v); } } return $data; } # 查看订单详情 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); } return $result; } # 出库下单 public function action($type_id, $name, $num, $goods, $price, $member_id, $out_type, $info, $status = 2) { $order_data = $this->where($type_id); $order_data['name'] = $name; $order_data['num'] = $num; $order_data['info'] = $info; $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(); $id = Dever::db('shop/out_order')->insert($order_data); if (!$id) { Dever::alert('出库失败'); } foreach($goods as $k => $v) { if ($v['ku_state'] == 1) { $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) { # 出库成功 去掉库存 Dever::load('shop/lib/goods')->oper($order_data, 2, 1, array($data)); } } } return array('order_id' => $id); } # 生成订单号 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(); } } # 审核出库单 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) { $info['goods'] = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id'])); $info['cdate'] = date('Y-m-d H:i', $info['cdate']); $type = Dever::db('shop/out_order')->config['config_type']; $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) { $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']); } $info['member'] = Dever::db('shop/member')->find($info['member_id']); } 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 = '
基本信息
'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; 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 .= ''; } $html .= ''; $html .= ''; if ($info['info']) { $html .= ''; } 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[] = '  '; } $print = Dever::url('admin/out.print?id=' . $info['id'] . '&type=2', 'store'); $button[] = '打印出库单'; $config['phone'] = '您的专属客服:' . $config['kf_name'] . ',联系电话:' . $config['phone']; $button[] = ''; $html .= ''; } elseif ($info['status'] == 1) { $button = array(); $url = Dever::url('lib/out.yes?id='.$info['type_id'].'&order_id='.$info['id'], 'mshop'); $button[] = '  '; $html .= ''; } $html .= '
项目详情
订单号 '.$this->table(false, array($info['order_num'])).'
出库单状态 '.$this->table(false, array($status)).'
填单时间 '.$this->table(false, array($cdate)).'
来源信息 '.$this->table(false, array(array($type_info['name'] . ',' . $type_info['truename'] . ',' . $type_info['mobile'] . ',' . $type_info['address']))).'
操作人 '.$this->table(false, array($member['name'])).'
出库类别 '.$this->table(false, array($out_type)).'
订单备注 '.$this->table(false, array(array($info['info']))).'
功能按钮 '.$this->table(false, array($button)).'
功能按钮 '.$this->table(false, array($button)).'
'; $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']; 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[2]); } $body[] = $d; $price = $v['price']*$v['num']; $body_total['price'] += $price; $body_total['num'] += $v['num']; } if ($body) { $head = array('商品名称', '商品属性', '商品单价', '商品数量'); $d = array ( '合计', '-', round($body_total['price'], 2), $body_total['num'], ); if ($type == 2) { unset($head[2]); unset($d[2]); } $body[] = $d; $html .= '
商品清单
' . $this->table($head, $body) . '
'; } $html .= '
'; return '
' . $html . '
'; } private function table($head, $data) { $html = ''; if ($head) { $html = ''; $html .= ''; foreach ($head as $k => $v) { $html .= ''; } $html .= ''; $html .= ''; foreach ($data as $k => $v) { $html .= ''; foreach ($v as $k1 => $v1) { $html .= ''; } $html .= ''; } $html .= ''; $html .= '
'.$v.'
'.$v1.'
'; } else { foreach ($data as $k => $v) { $html .= ''; if (is_array($v)) { foreach ($v as $k1 => $v1) { $html .= $v1 . '    '; } } else { $html .= $v . '    '; } $html .= ''; } } return $html; } public function printer($user) { $id = Dever::input('id'); $type = Dever::input('type', 2); $factory_config = Dever::db('main/factory_config')->find(); $main_config = Dever::db('main/config')->find(); $config = Dever::db('main/config')->find(); $config = Dever::db('shop/out_order')->config; $info = Dever::db('shop/out_order')->one($id); 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']); } $status = $config['config_status'][$info['status']]; $out_type = $config['config_type'][$info['out_type']]; $cdate = date('Y-m-d H:i', $info['cdate']); $pdf = Dever::load('pdf/lib/base')->init(); $pdf->hr('-', $main_config['name']); $pdf->br()->font(20)->center('出库单号:' . $info['order_num']); $pdf->font(10); $pdf->br(2); $pdf->br()->left('仓库名称:' . $type_info['name'], 80)->left('制单人:' . $user['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40); $pdf->hr(); $pdf->br()->left('出库单状态:' . $status, 140)->left('出库填单时间:' . $cdate, 40); $pdf->left('出库类别:' . $out_type); $pdf->left('原因备注:' . $info['info']); $pdf->hr(); $head = array(array('商品编号', 40), array('商品名称', 70), array('商品属性', 60), array('出库数量', 20)); $data = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id'])); if ($data) { $body = array(); $body_total = array(); $body_total['num'] = 0; foreach ($data as $k => $v) { $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']); if (isset($goods_info['sku'])) { $sku = $goods_info['sku']['string']; } else { $sku = ''; } $body[] = array ( $goods_info['id'], $goods_info['name'], $sku, 'x ' . $v['num'], ); $body_total['num'] += $v['num']; } $pdf->br(); foreach ($head as $k => $v) { $pdf->left($v[0], $v[1]); } foreach ($body as $k => $v) { $pdf->br(); foreach ($head as $k1 => $v1) { $pdf->left($v[$k1], $v1[1]); } } $pdf->br(); $pdf->right('共'.$body_total['num'].'件商品'); $pdf->hr(); } $pdf->br(1); $pdf->right('如遇任何问题请致电客服'); $pdf->br(); $pdf->font(20); $pdf->left($main_config['name'], 160); $pdf->font(10); $pdf->right('电话:' . $factory_config['phone'], 30); $pdf->br(); $pdf->left($main_config['site'], 160); $pdf->font(10); $pdf->right($main_config['worktime'], 30); $pdf->out('库存清单'); } }