update($update); Dever::config('base')->hook = false; } } public function updateOrderNum($id, $name, $data) { $table = Dever::input('table'); $prefix = Dever::input('prefix'); if ($table && $prefix) { $servicer_store_id = Dever::param('servicer_store_id', $data); if ($servicer_store_id) { $info = Dever::db('scm_servicer/store')->find($servicer_store_id); if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) { Dever::db($table)->delete($id); Dever::alert('仓库[' . $info['name'] . ']收货地址未填写'); } } $seller_shop_id = Dever::param('seller_shop_id', $data); if ($seller_shop_id) { $info = Dever::db('scm_seller/shop')->find($seller_shop_id); if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) { Dever::db($table)->delete($id); Dever::alert('门店[' . $info['name'] . ']收货地址未填写'); } } $update['order_num'] = $this->getOrderNum($table, $prefix); $update['where_id'] = $id; Dever::db($table)->update($update); Dever::config('base')->hook = false; } } # 生成订单号 public function getOrderNum($table, $prefix = 'C') { $where['order_num'] = Dever::order($prefix); $state = Dever::db($table)->one($where); if (!$state) { return $where['order_num']; } else { return $this->getOrderNum($table); } } # 查看订单详情 public function show($order_table) { $id = Dever::input('order_id'); $order_db = Dever::db($order_table); $order = $order_db->one($id); $order['config'] = $order_db->config['set']; $content = array(); if (isset($order['type'])) { $type = Dever::db($order_table . '_type')->one($order['type']); $content[0][] = array('订单类型', $type['name']); } $content[0][] = array('订单状态', Dever::status($order['config']['status'], $order['status'])); $content[0][] = array('下单时间', date('Y-m-d H:i', $order['cdate'])); $order['info'] && $content[0][] = array('订单备注', $order['info']); $content[1] = $content[2] = array(); $role = $this->show_role(array ( 'seller' => '经销商', 'seller_shop' => '门店', 'servicer' => '配送商', 'servicer_store' => '仓库', 'supplier' => '供应商', ), $order, $content[1]); $this->show_audit($order, $content[2]); $result = array(); $result[$order['order_num']] = array ( 'type' => 'info', 'content' => $content ); $this->show_address($order, $role, $result); $audit = Dever::input('audit'); if ($audit == 1) { $this->show_goods_audit($order, $order_table, $result); } else { $this->show_goods($order, $order_table, $result); } $head = array ( 'name' => '基本信息', 'btn' => $this->show_button($order, $order_table), ); $html = Dever::show($head, $result); return $html; } # 显示订单角色 private function show_role($role, $order, &$data) { $result = array(); foreach ($role as $k => $v) { $col = $k . '_id'; if (isset($order[$col]) && $order[$col] > 0) { $project = $k; $name = 'info'; if (strstr($k, '_')) { $temp = explode('_', $k); $project = $temp[0]; $name = $temp[1]; } $table = 'scm_' . $project . '/' . $name; $result[$k] = Dever::db($table)->one($order[$col]); if ($result[$k]) { $data[] = array($v, $result[$k]['name']); } } } return $result; } # 显示审核信息 private function show_audit($order, &$data) { if (isset($order['audit_admin']) && $order['audit_admin']) { $admin = Dever::db('manage/admin')->find($order['audit_admin']); $data = array ( array('审核人', $admin['username']), array('审核状态', Dever::status($order['config']['audit'], $order['audit'])), array('审核备注', $order['audit_desc']), ); } } # 显示订单地址 private function show_address($order, $role, &$result) { if (!$order['address']) { if (isset($role['servicer_store'])) { $address = $role['servicer_store']; } if (isset($role['seller_shop'])) { $address = $role['seller_shop']; } } else { $address = Dever::json_decode($order['address']); } if ($address) { $address['area'] = Dever::load('area/api')->string($address['area']); $result['收货信息'] = array ( 'type' => 'info', 'content' => array ( array ( array('联系人', $address['truename']), array('联系电话', $address['tel']), array('收货地址', $address['area'] . ',' . $address['address']), ), ), ); } } # 显示订单商品清单 private function show_goods($order, $order_table, &$result) { $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id'])); if ($data) { $table['head'] = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '状态'); $table['body'] = array(); $total_price = $total_num = 0; $status = Dever::db($order_table . '_goods')->config['status']; foreach ($data as $k => $v) { $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id'], $v['unit_id']); $status_name = Dever::status($status, $v['status']); $num = $v['num']; if ($v['status'] == 2 && $v['unit_id'] != $goods_info['base_unit_id']) { if (!isset($order['supplier_id'])) { $order['supplier_id'] = false; } $unit = Dever::load('scm/lib/unit')->convertBase($v['goods_id'], $v['sku_id'], $v['unit_id'], $v['num'], $v['cash'], 0, $order['supplier_id']); if ($unit) { $base_unit = Dever::db('scm/unit')->find($unit['unit_id']); $goods_info['unit'] .= ' => '.$unit['num'].''.$base_unit['name'].''; $num = $unit['num']; } } $cash = Dever::number($v['cash'] * $v['num']); $detail = array ( $goods_info['code'], $goods_info['aname'], ); if (isset($v['batch'])) { $detail[] = $v['batch'] . (isset($v['sdate']) && $v['sdate'] ? '[' . date('Y-m-d', $v['sdate']) . '生产]' : ''); } else { unset($table['head'][3]); } $detail[] = $v['cash']; $detail[] = $v['num'] . $goods_info['unit']; $detail[] = $cash; $detail[] = $status_name; if ($goods_info['goods']) { $detail['goods'] = $goods_info['goods']; } $table['body'][] = $detail; $total_price += $cash; $total_num += $num; } $result['商品清单'] = array ( 'type' => 'table', 'head' => array('name' => '', 'btn' => ''), 'content' => $table, 'total' => '合计金额:' . Dever::number($total_price) . ',合计数量:' . $total_num ); } } # 显示按钮 private function show_button($order, $order_table) { $button = array(); if ($order['status'] == 1) { list($project, $table) = explode('/', $order_table); $url = Dever::url('project/database/update?project='.$project.'&table='.$table.'&where_id='.$order['id'].'&col=audit,audit_desc', 'manage'); $button[] = array ( 'type' => 'edit', 'link' => $url, 'name' => '审核', ); } return $button; } private function show_goods_audit($order, $order_table, &$result) { $order['type'] = 1; $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id'])); print_r($order);die; $seller = Dever::db('scm_seller/info')->find($order['seller_shop_id']); $seller = Dever::db('scm_seller/shop')->find($order['seller_shop_id']); list($assign, $source) = Dever::load('scm/lib/assign')->get($goods, $info, $shop, true); if ($info) { $head = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '供货商'); $body = array(); $i = 0; if ($data) { foreach ($assign as $k => $v) { foreach ($v as $v1) { $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']); if (isset($goods_info['sku'])) { $sku = '[' . $goods_info['sku']['string'] . ']'; } else { $sku = ''; } $d = array ( $i+1, $goods_info['code'], $goods_info['name'] . $sku, $this->getSelect($source, $v1['source_id'], $v1['order_goods_id']), $v1['num'], $goods_info['unit'], $v1['p_price'] * $v1['num'], ); $body[] = $d; $i++; } } } if ($goods) { foreach ($goods 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 = ''; } $d = array ( $i+1, $goods_info['code'], $goods_info['name'] . $sku, $this->getSelect($source, false, $v['id']), $v['num'], $goods_info['unit'], $v['p_price'] * $v['num'], ); $body[] = $d; $i++; } } $btn = array(); $btn[] = array( 'type' => 'click', 'content' => 'setAudit()', 'name' => '全部调整' ); $result['商品拆单'] = array ( 'type' => 'table', 'head' => array('name' => '供货商:' . $this->getSelect($source, false, false), 'btn' => $btn), 'content' => array ( 'head' => $head, 'body' => $body, ) ); $url = Dever::url('lib/buy.audit_set_commit?json=1&order_id=' . $info['id'], 'mshop'); $result['审核结果'] = array ( 'type' => 'html', 'content' => '
审核通过    审核未通过   
保存
', ); } } }