id; # 待处理订单 $data['order_num'] = Dever::db('shop/buy_order')->getOrderNum($where); # 超时待处理订单:72小时 $where['end_o'] = time() - 72*3600; $data['cs_order_num'] = Dever::db('shop/buy_order')->getOrderNum($where); return $data; } # 订单列表 public function getList() { $data = Dever::load('mshop/lib/buy')->set(13, 1)->getList($this->id); $html = ''; if ($data && $data['order']) { $out_status = Dever::db('shop/buy_order')->config['out_status']; $excel = Dever::input('excel', 1); if ($excel == 2) { Dever::load('factory/admin/excel')->out($this->id, $this->user, $data['order']); die; return; } foreach ($data['order'] as $k => $v) { if ($v['ps_info']) { $ps_date = $v['ps_info']['cdate']; } else { $ps_date = '-'; } $view = Dever::url('order_view?type=2&order_id=' . $v['id'] . '&cash=2', 'factory'); $send = Dever::url('order_send?id=' . $v['id'], 'factory'); $button = ''; if ($v['status'] < 5) { $print = Dever::url('admin/order.print?id=' . $v['id'] . '&type=1', 'factory'); $button .= '  '; } if ($v['status'] == 3) { $button .= '  '; } if ($v['refund_status'] == 2 && $v['status'] != 8) { $v['status_name'] .= '[缺货报损中]'; } $order = array(); if ($v['parent_type'] == 2) { $order = Dever::db('shop/sell_order')->find($v['parent_order_id']); if ($order && $order['uid']) { if ($order['address_id']) { $order['address'] = Dever::load('passport/address')->getOne($order['uid'], $order['address_id']); if ($order['address']) { $v['type_info']['name'] = $order['address']['contact']; } else { $user = Dever::db('passport/user')->find($order['uid']); $v['type_info']['name'] = $user['username']; } } else { $user = Dever::db('passport/user')->find($order['uid']); $v['type_info']['name'] = $user['username']; } } } elseif ($v['parent_type'] == 3) { $order = Dever::db('agent/dh_order')->find($v['parent_order_id']); if ($order && $order['mid']) { if ($order['address_id']) { $order['address'] = Dever::load('agent/address')->getOne($order['mid'], $order['address_id']); if (isset($order['address']['contact']) && $order['address']['contact']) { $v['type_info']['name'] = $order['address']['contact']; } else { $v['type_info']['name'] = ''; } } else { $user = Dever::db('agent/member')->find($order['mid']); $v['type_info']['name'] = $user['name']; } } } $v['out_status_name'] = $out_status[$v['source_out_status']]; $dao_date = '-'; if ($v['source_out_date']) { $dao_date = date('Y-m-d H:i', $v['source_out_date']); } $html .= ''.$v['order_num'].''.$v['operdate'].''.$v['type_info']['name'].''.$ps_date.''.$v['p_price'].''.$v['status_name'].''.$v['out_status_name'].''.$dao_date.''.$button.''; } } return $html; } # 获取列表页搜索信息 public function getSearch() { $config = array ( array('value' => '0', 'name' => '全部'), array('value' => 3, 'name' => '待生产发货'), array('value' => 4, 'name' => '已发货'), array('value' => '5,6', 'name' => '已到货'), array('value' => '7,8,11', 'name' => '已取消'), array('value' => 'refund', 'name' => '缺货与报损'), ); $status = Dever::input('status'); $html = ''; foreach ($config as $k => $v) { $selected = ''; if ((!$status && $k == 0) || $status == $v['value']) { $selected = 'selected=""'; } $html .= ''; } return $html; } # 获取列表页搜索信息 public function getSearchOutStatus() { $config = array ( array('value' => '0', 'name' => '全部'), array('value' => 1, 'name' => '未导出'), array('value' => 2, 'name' => '已导出'), ); $status = Dever::input('source_out_status'); $html = ''; foreach ($config as $k => $v) { $selected = ''; if ((!$status && $k == 0) || $status == $v['value']) { $selected = 'selected=""'; } $html .= ''; } return $html; } # 获取列表页搜索信息 public function getService() { $service = Dever::db('shop/service')->select(); $html = ''; foreach ($service as $k => $v) { $selected = ''; if ($k == 0) { $selected = 'selected=""'; } $html .= ''; } return $html; } # 获取基本信息 public function getConfig() { $data['search'] = Dever::url('order', 'factory'); # 发货 $data['send'] = Dever::url('admin/order.send', 'factory'); # 退款 $data['tui'] = Dever::url('lib/buy.refund_apply_info_one_commit?json=1', 'mshop'); # 导入物流单号 $data['import'] = Dever::load('upload/import.url', 'factory/admin/order.import', 10); return $data; } # 导入物流单号 public function import($file) { $file = Dever::local($file); $data = Dever::excelImport($file, 0); if ($data) { $psinfo = array(); foreach ($data as $k => $v) { if ($k >= 2) { $order_num = $v['A']; if ($order_num) { $order = Dever::db('shop/buy_order')->find(array('order_num' => $order_num)); if ($order && $order['status'] == 3) { if (!isset($psinfo[$order['id']])) { $psinfo[$order['id']] = array(); } $psinfo[$order['id']][] = array($v['B'], $v['C'], $v['D']); } } } } if ($psinfo) { foreach ($psinfo as $k => $v) { $update = array(); $update['order_id'] = $k; $service = array(); foreach ($v as $k1 => $v1) { if ($v1[2] && strstr($v1[2], '-')) { $update['cdate'] = Dever::maketime($v1[2]); } else { $update['cdate'] = time(); } $service_info = Dever::db('shop/service')->find(array('name' => $v1[1], 'clear' => true)); if (!$service_info) { $service_id = Dever::db('shop/service')->insert(array('name' => $v1[1], 'type' => 1)); } else { $service_id = $service_info['id']; } $service[] = array ( 'order' => $k1, 'service_id' => $service_id, 'order_num' => $v1[0], ); } if ($service) { $update['service'] = $service; } $this->send_action($update); } } } } # 发货 public function send_api() { $input = Dever::input(); $service = array(); $order_id = Dever::input('update_where_id'); foreach ($input as $k => $v) { if (strpos($k, '_c_') !== false) { if ($v == 'null') { $v = ''; } $temp = explode('_c_', $k); $k = str_replace('update_', '', $temp[0]); if (!isset($c[$k])) { $c[$k] = array(); } if (strpos($temp[1], '_i_') !== false) { $temp = explode('_i_', $temp[1]); if (!isset($c[$k][$temp[1]])) { $c[$k][$temp[1]] = 0; } else { $c[$k][$temp[1]]++; } $num = $c[$k][$temp[1]]; $service[$k][$num][$temp[1]] = $v; } } } $update = array(); if ($service) { $update = $service; } $update['order_id'] = $order_id; $update['cdate'] = $input['update_cdate']; /* $update['service_id'] = $input['update_service_id']; $update['order_num'] = $input['update_order_num']; $update['num'] = $input['update_num']; $update['phy'] = $input['update_phy']; $update['dby'] = $input['update_dby']; $update['zl'] = $input['update_zl']; $update['tj'] = $input['update_tj']; $update['price'] = $input['update_price']; */ return $this->send_action($update); } private function send_action($update = array()) { $info = Dever::db('shop/buy_order_ps')->find(array('order_id' => $update['order_id'])); if (isset($update['service'])) { $update['service'] = Dever::array_encode($update['service']); } if ($info) { $update['where_id'] = $info['id']; Dever::db('shop/buy_order_ps')->update($update); } else { Dever::db('shop/buy_order_ps')->insert($update); } Dever::db('shop/buy_order')->update(array('status' => 4, 'where_id' => $update['order_id'],'fadate'=>time())); # 检测是否是关联订单 $order = Dever::db('shop/buy_order')->find($update['order_id']); if ($order && $order['parent_type'] > 1) { $data = Dever::db('shop/buy_order')->find(array('status' => 3, 'parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id'])); if (!$data) { # 更改关联订单状态 if ($order['parent_type'] == 2) { Dever::db('shop/sell_order')->update(array('where_id' => $order['parent_order_id'], 'status' => 4)); $data = Dever::db('shop/buy_order')->getDataToId(array('parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id'])); $data = array_keys($data); $ps_info = Dever::db('shop/buy_order_ps')->getData(array('order_id' => $data)); if ($ps_info) { $sell_order = array('id' => $order['parent_order_id']); foreach ($ps_info as $k => $v) { $v['service'] = Dever::array_decode($v['service']); foreach ($v['service'] as $k1 => $v1) { if (isset($v1['order_num']) && $v1['order_num']) { Dever::load('shop/lib/sell')->updatePs($sell_order, 2, $v1['service_id'], $v1['order_num'], $v['cdate']); } } } } } elseif ($order['parent_type'] == 3) { Dever::db('agent/dh_order')->update(array('where_id' => $order['parent_order_id'], 'status' => 4)); $data = Dever::db('shop/buy_order')->getDataToId(array('parent_type' => $order['parent_type'], 'parent_order_id' => $order['parent_order_id'])); $data = array_keys($data); $ps_info = Dever::db('shop/buy_order_ps')->getData(array('order_id' => $data)); if ($ps_info) { $dh_order = array('id' => $order['parent_order_id']); foreach ($ps_info as $k => $v) { $v['service'] = Dever::array_decode($v['service']); foreach ($v['service'] as $k1 => $v1) { if (isset($v1['order_num']) && $v1['order_num']) { Dever::load('agent/lib/dhorder')->updatePs($dh_order, 2, $v1['service_id'], $v1['order_num'], $v['cdate']); } } } } } } } # 给仓库发消息 if (Dever::project('message') && $order && $order['type'] == 2) { $msg_param['type'] = 3;//消息头类型3是入库订单消息 $msg_param['id'] = $order['id']; $msg_param = Dever::json_encode($msg_param); $msg = '您有新的入库订货单已发货,请及时查收后确认。'; Dever::load('message/lib/data')->push(-1, $order['type_id'], '入库订货单通知', $msg, 7, 3, false, $msg_param); } return 'reload'; } # 打印订单单 public function print_api() { return Dever::load('mshop/lib/buy')->printer($this->user); } # 获取报损信息 public function refund() { $data = Dever::load('mshop/lib/buy')->refund_apply_info_one_info(); if (isset($data['tui_price'])) { $data['tui_price_info'] = '¥' . $data['tui_price']; } else { $data['tui_price_info'] = '¥0'; } return $data; } }