123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- <?php
- namespace Factory\Admin;
- use Dever;
- class Order extends Core
- {
- # 获取概览数据
- public function getData()
- {
- # 待处理订单
- $where['status'] = 3;
- $where['source_type'] = 3;
- $where['source_id'] = $this->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 = '<a href="'.$view.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">查看详情</button></a>';
- if ($v['status'] < 5) {
- $print = Dever::url('admin/order.print?id=' . $v['id'] . '&type=1', 'factory');
- $button .= ' <a href="'.$print.'" id="print_'.$v['id'].'" target="_blank"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">打印备货单</button></a>';
- }
-
- if ($v['status'] == 3) {
- $button .= ' <a href="javascript:;" id="send_'.$v['id'].'" onclick="fastEdit($(this), \''.$send.'\', \'配送发货\', \'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">配送发货</button></a>';
- }
- 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 .= '<tr><td>'.$v['order_num'].'</td><td>'.$v['operdate'].'</td><td>'.$v['type_info']['name'].'</td><td>'.$ps_date.'</td><td>'.$v['p_price'].'</td><td>'.$v['status_name'].'</td><td>'.$v['out_status_name'].'</td><td>'.$dao_date.'</td><td>'.$button.'</td></tr>';
- }
- }
- 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 .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
- }
- 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 .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
- }
- return $html;
- }
- # 获取列表页搜索信息
- public function getService()
- {
- $service = Dever::db('shop/service')->select();
- $html = '';
- foreach ($service as $k => $v) {
- $selected = '';
- if ($k == 0) {
- $selected = 'selected=""';
- }
- $html .= '<option value="'.$v['id'].'" '.$selected.'>'.$v['name'].'</option>';
- }
- 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;
- }
- }
|