config = Dever::db($this->table)->config; } # 设置订单的类型 public function set($type, $view) { return $this; } # 获取公共的where public function where($id) { $where = array(); $where['mid'] = $id; if (!$where) { Dever::alert('参数错误'); } return $where; } # 获取订单列表 public function getList($id) { $result = array(); $where = $this->where($id); $mobile = Dever::input('mobile'); if ($mobile) { $where['mobile'] = $mobile; } $status = Dever::input('status'); if ($status) { $where['status'] = $status; } $result['order'] = Dever::db($this->table)->getAll($where); if ($result['order']) { foreach ($result['order'] as $k => $v) { $result['order'][$k] = $this->getInfo($v, false); } } return $result; } # 查看详情 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); } return $result; } # 获取订单详细信息 public function getInfo($info, $view = true) { $info['status_name'] = Dever::status($this->config['status'], $info['status']); $info['cdate'] = date('Y-m-d H:i', $info['cdate']); if ($info['operdate']) { $info['operdate'] = date('Y-m-d H:i', $info['operdate']); } else { $info['operdate'] = ''; } if ($info['fdate']) { $info['fdate'] = date('Y-m-d H:i', $info['fdate']); } else { $info['fdate'] = ''; } if ($view && $info['type'] == 1) { $info['ps_info'] = Dever::db('agent/dh_order_ps')->find(array('order_id' => $info['id'])); if ($info['ps_info']) { $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']); $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']); if ($info['ps_info']['qu_date']) { $info['ps_info']['qu_date'] = date('Y-m-d H:i', $info['ps_info']['qu_date']); } if ($info['ps_info']['qs_date']) { $info['ps_info']['qs_date'] = date('Y-m-d H:i', $info['ps_info']['qs_date']); } $status = Dever::db('agent/dh_order_ps')->config['status']; $info['ps_info']['status_name'] = $status[$info['ps_info']['status']]; if ($info['ps_info']['service']) { foreach ($info['ps_info']['service'] as $k => $v) { if (isset($v['order_num']) && $v['order_num']) { $info['ps_info']['service'][$k]['service_name'] = '商家自送'; if ($v['service_id'] > 0) { $service = Dever::db('shop/service')->find($v['service_id']); $info['ps_info']['service'][$k]['service_name'] = $service['name']; } } else { unset($info['ps_info']['service'][$k]); } } } } $goods_status = Dever::db('agent/dh_order_goods')->config['status']; if ($info['address_id']) { $info['address'] = Dever::db('agent/member_address')->find($info['address_id']); } $info['goods'] = Dever::db('agent/dh_order_goods')->select(array('order_id' => $info['id'])); foreach ($info['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 = ''; } $info['goods'][$k] += array ( 'pic' => $goods_info['cover'], 'name' => $goods_info['name'], 'sku' => $sku, 'price' => $goods_info['price'], ); } } if ($info['type'] == 2) { $info['card'] = Dever::db('card/info')->find($info['type_id']); } if ($info['type'] == 3) { $info['prize'] = Dever::db('setting/prize')->find($info['type_id']); } return $info; } # 取消订单 public function cancel($id, $order_id) { $data = $this->getView($id, $order_id, false); if ($data['status'] == 1) { $state = Dever::db('agent/dh_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time())); if ($state) { $this->updateSell($data, 2); } return 'ok'; } else { Dever::alert('当前订单状态不允许取消'); } } # 得到商品和总价 public function goods($mid) { $goods_id = Dever::input('goods_id'); if (!$goods_id) { Dever::alert('请传入商品'); } $goods_id = explode(',', $goods_id); $num = Dever::input('num'); if (!$num) { Dever::alert('请传入商品数量'); } $num = explode(',', $num); $data['price'] = 0; $data['num'] = 0; $data['name'] = array(); $count = count($goods_id); $data['list'] = array(); $i = 0; foreach ($goods_id as $k => $v) { $n = isset($num[$k]) ? $num[$k] : 1; $data['list'][$i] = Dever::db('agent/member_goods')->find(array('mid' => $mid, 'id' => $v)); if ($data['list'][$i]) { $data['list'][$i]['num'] = $n; # 2是库存不足 $data['list'][$i]['ku_state'] = 1; $total = $data['list'][$i]['total_num'] - $data['list'][$i]['sell_num']; if ($total >= $n) { $data['list'][$i]['buy_num'] = $n; } else { $data['list'][$i]['buy_num'] = $total; } if ($data['list'][$i]['buy_num'] <= 0) { $data['list'][$i]['ku_state'] = 2; $data['list'][$i]['buy_num'] = 0; } $goods_info = Dever::load('goods/lib/info')->getInfoBySku($data['list'][$i]['type_id'], $data['list'][$i]['sku_id']); if (isset($goods_info['sku'])) { $sku = $goods_info['sku']['string']; } else { $sku = ''; } $data['list'][$i] += array ( 'pic' => $goods_info['cover'], 'name' => $goods_info['name'], 'sku' => $sku, 'price' => $goods_info['price'], ); if ($data['list'][$i]['ku_state'] == 1) { $data['num'] += $data['list'][$i]['buy_num']; $data['price'] += $goods_info['price'] * $data['list'][$i]['buy_num']; $data['name'] = '兑换商品'; } $i++; } } if ($data['num'] <= 0) { Dever::alert('没有商品可以兑换'); } return $data; } # 确认兑换 public function action($user, $name, $num, $price, $goods, $address_id, $dh_type, $type, $type_id, $info, $refer = '') { # 获取平台店 $shop = Dever::db('shop/info')->find(array('type' => 10)); if (!$shop) { Dever::alert('没有平台店'); } $order_data['shop_id'] = $shop['id']; $order_data['mid'] = $user['id']; $order_data['mobile'] = $user['mobile']; $order_data['address_id'] = $address_id; $order_data['name'] = $name; $order_data['num'] = $num; $order_data['info'] = $info; $order_data['price'] = $price; $order_data['dh_type'] = $dh_type; $order_data['type'] = $type; if ($type_id) { $order_data['type_id'] = $type_id; } if ($dh_type == 2) { $order_data['status'] = 5; } else { $order_data['status'] = 2; } $order_data['refund_cash'] = 0; $order_data['audit'] = 2; if ($type == 1) { $time = time(); $order_data_where = $order_data; $order_data_where['start'] = $time - 60; $order_data_where['end'] = $time; $order_data_where['option']['start'] = array('yes-cdate', '>='); $order_data_where['option']['end'] = array('yes-cdate', '<='); $info = Dever::db('agent/dh_order')->find($order_data_where); } else { $info = false; } $order_data['order_num'] = $this->getOrderId(); if (!$info) { $id = Dever::db('agent/dh_order')->insert($order_data); } else { return array ( 'order' => '', 'order_num' => $info['order_num'], 'order_id' => $info['id'], 'type' => 'test', ); } if (!$id) { Dever::alert('兑换失败'); } if ($goods) { foreach($goods as $k => $v) { if ($v['ku_state'] == 1) { $data['mid'] = $user['id']; $data['order_id'] = $id; $data['shop_id'] = $shop['id']; $data['goods_id'] = $v['type_id']; $data['sku_id'] = $v['sku_id']; $data['price'] = $v['price']; $data['num'] = $v['buy_num']; Dever::db('agent/dh_order_goods')->insert($data); } } } # 减少库存 增加销量 $order_data['id'] = $id; $this->updateSell($order_data); return array ( 'order_num' => $order_data['order_num'], 'order_id' => $id, 'type' => 'dh', ); } # 添加配送信息 public function updatePs($order, $status = 1, $service_id = -1, $order_num = '', $cdate = false) { $order = Dever::db('agent/dh_order')->find($order['id']); $where['order_id'] = $order['id']; $where['clear'] = true; $data = Dever::db('agent/dh_order_ps')->find($where); $service = array(); if ($service_id) { $service['service_id'] = $service_id; } if ($order_num) { $service['order_num'] = $order_num; } if (!$data) { $insert = $where; if ($service) { $insert['service'][] = $service; $insert['service'] = Dever::array_encode($insert['service']); } $insert['status'] = $status; if ($status == 2) { $insert['qu_date'] = time(); } $insert['mid'] = $order['mid']; if ($cdate) { $insert['cdate'] = $cdate; } Dever::db('agent/dh_order_ps')->insert($insert); } else { $update = $where; $update['where_id'] = $data['id']; $update['status'] = $status; if ($status == 2) { $update['qu_date'] = time(); } if ($status == 3) { $update['qs_date'] = time(); } if ($service) { $data['service'] = Dever::array_decode($data['service']); $update['service'] = $data['service']; $update['service'][] = $service; $update['service'] = Dever::array_encode($update['service']); } $update['mid'] = $order['mid']; if ($cdate) { $update['cdate'] = $cdate; } Dever::db('agent/dh_order_ps')->update($update); } } # 减少库存,增加销量 public function updateSell($order, $type = 1) { $method = 'incSell'; $name = '兑换商品'; $name_3 = '兑换名额'; if ($type == 2) { $method = 'decSell'; $name = '退回商品'; $name_3 = '退回名额'; } if ($order['type'] == 1) { $where['order_id'] = $order['id']; //$where['status'] = 3; $data = Dever::db('agent/dh_order_goods')->select($where); if ($data) { foreach ($data as $k => $v) { $up = array(); $up['where_mid'] = $order['mid']; $up['where_type'] = $order['type']; $up['where_type_id'] = $v['goods_id']; $up['where_sku_id'] = $v['sku_id']; $up['clear'] = true; $info = Dever::db('agent/member_goods')->findData($up); $up['set_sell_num'] = $v['num']; Dever::db('agent/member_goods')->$method($up); if ($type == 2) { Dever::load('agent/lib/member_set')->log($up['where_mid'], '', $up['where_type'], $up['where_type_id'], $up['where_sku_id'], $up['set_sell_num'], $info['num'], $info['num']+$up['set_sell_num'], $info['name'], $name); } else { Dever::load('agent/lib/member_set')->log($up['where_mid'], '', $up['where_type'], $up['where_type_id'], $up['where_sku_id'], $up['set_sell_num'], $info['num'], $info['num']-$up['set_sell_num'], $info['name'], $name); } } } } elseif ($order['type'] == 3) { $up['where_mid'] = $order['mid']; $up['where_type'] = $order['type']; $up['where_type_id'] = $order['type_id']; $up['where_sku_id'] = -1; $info = Dever::db('agent/member_goods')->findData($up); $up['set_sell_num'] = $order['num']; Dever::db('agent/member_goods')->$method($up); if ($type == 2) { Dever::load('agent/lib/member_set')->log($up['where_mid'], '', $up['where_type'], $up['where_type_id'], $up['where_sku_id'], $up['set_sell_num'], $info['num'], $info['num']+$up['set_sell_num'], $info['name'], $name_3); } else { Dever::load('agent/lib/member_set')->log($up['where_mid'], '', $up['where_type'], $up['where_type_id'], $up['where_sku_id'], $up['set_sell_num'], $info['num'], $info['num']-$up['set_sell_num'], $info['name'], $name_3); } } } # 完成 public function finish($info, $shop_id) { if ($info && $info['shop_id'] == $shop_id && $info['status'] <= 4) { $status = 5; $state = Dever::db('agent/dh_order')->update(array('where_id' => $info['id'], 'status' => $status, 'fdate' => time())); $this->updatePs($info, 3); $w['parent_type'] = 3; $w['parent_order_id'] = $info['id']; $w['status'] = 4; $buy_order = Dever::db('shop/buy_order')->select($w); if ($buy_order) { foreach ($buy_order as $k => $v) { Dever::load('mshop/lib/buy')->set(1,1)->finish($shop_id, $v['id']); } } return 'ok'; } else { Dever::alert('您没有权限核销'); } } # 平台订单已收货 public function yes_api() { $shop_id = Dever::input('shop_id'); $order_id = Dever::input('order_id'); $info = Dever::db('agent/dh_order')->find(array('id' => $order_id)); if ($info && $info['type'] == 10) { $this->finish($info, $shop_id); } else { Dever::alert('您没有权限核销'); } return 'reload'; } # 生成订单号 public function getOrderId() { $where['order_num'] = Dever::order('DH'); $state = Dever::db('agent/dh_order')->one($where); if (!$state) { return $where['order_num']; } else { return $this->getOrderId(); } } # 展示订单详情 public function show() { $id = Dever::input('order_id'); $config = Dever::db('agent/dh_order')->config; $info = Dever::db('agent/dh_order')->one($id); if ($info['type'] > 1) { return; } $tk_status = Dever::db('agent/dh_order_refund')->config['status']; $tk_process = Dever::db('agent/dh_order_refund')->config['process']; $status = $config['status'][$info['status']]; $tk = Dever::db('agent/dh_order_refund')->find(array('order_id' => $info['id'], 'type' => 1)); $shop = Dever::db('shop/info')->find($info['shop_id']); $user = Dever::db('agent/member')->find($info['mid']); $cdate = date('Y-m-d H:i', $info['cdate']); if ($info['operdate']) { $opertime = date('Y-m-d H:i', $info['operdate']); } else { $opertime = ''; } if ($info['fdate']) { $fdate = date('Y-m-d H:i', $info['fdate']); } else { $fdate = ''; } if (!$user) { $user['username'] = '无'; } if (!isset($user['name'])) { $user['truename'] = $user['name']; } if ($tk && $tk['process'] == 1) { $status = '申请' . $tk_status[$tk['status']]; $process = $tk_process[$tk['process']]; $process = ''; } $time = array(); $time[] = array('下单时间', $cdate); if ($opertime) { if ($info['status'] == 2) { $time[] = array('通知时间', $opertime); } if ($info['status'] == 7) { $time[] = array('取消时间', $opertime); } } if ($fdate) { $time[] = array('完成时间', $fdate); } $time[] = array('审核备注', $info['audit_desc']); $result = array(); $result[$info['order_num']] = array ( 'type' => 'info', 'content' => array ( array ( array('订单状态', $status), array('代理商姓名', $user['name']), array('联系电话', $info['mobile']), ), $time, ) ); if ($info['address_id'] > 0) { $address = Dever::load('agent/address')->getOne($info['mid'], $info['address_id']); if ($address) { $result['收货地址'] = array ( 'type' => 'info', 'content' => array ( array ( array('联系人', $address['contact']), array('联系电话', $address['mobile']), ), array ( array('收货地址', $address['address_info']), array('门牌号', $address['house_number']), ), ), ); } } $info['ps_info'] = Dever::db('agent/dh_order_ps')->find(array('order_id' => $info['id'])); if ($info['ps_info']) { $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']); $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']); if ($info['ps_info']['qs_date']) { $info['ps_info']['qs_date'] = date('Y-m-d H:i', $info['ps_info']['qs_date']); } else { $info['ps_info']['qs_date'] = '无'; } $status = Dever::db('agent/dh_order_ps')->config['status']; $info['ps_info']['status_name'] = $status[$info['ps_info']['status']]; $service = array(); if ($info['ps_info']['service']) { foreach ($info['ps_info']['service'] as $k => $v) { if (isset($v['order_num']) && $v['order_num']) { $info['ps_info']['service'][$k]['service_name'] = '商家自送'; if ($v['service_id'] > 0) { $service_info = Dever::db('shop/service')->find($v['service_id']); $info['ps_info']['service'][$k]['service_name'] = $service_info['name']; } $service[] = array ( array('名称', $info['ps_info']['service'][$k]['service_name']), array('单号', isset($v['order_num']) ? $v['order_num'] : ''), ); } } } $result['物流信息'] = array ( 'type' => 'info', 'content' => array ( array ( array('发货时间', $info['ps_info']['cdate']), array('收货时间', $info['ps_info']['qs_date']), array('查单', '点此手动查单'), ), ), ); $result['物流信息']['content'] = array_merge($result['物流信息']['content'], $service); } if (!$info['refund_cash']) { $info['refund_cash'] = 0; } if ($info['refund_cash'] > 0 && $tk) { $process = $tk_process[$tk['process']]; $tk['cdate'] = date('Y-m-d H:i', $tk['cdate']); $result['退款信息'] = array ( 'type' => 'info', 'content' => array ( array ( array('退款金额', $info['refund_cash']), array('数量', $info['num']), array('退款进度', $process), ), array ( array('申请时间', $tk['cdate']), array('退款原因', $tk['desc']), ), ), ); } $body = $refund_body = array(); $body_total = array(); $body_total['price'] = 0; $body_total['num'] = 0; $refund_body_total = array(); $refund_body_total['price'] = 0; $refund_body_total['num'] = 0; $goods = Dever::db('agent/dh_order_goods')->select(array('order_id' => $info['id'])); $goods_status = Dever::db('agent/dh_order_goods')->config['status']; foreach ($goods as $k => $v) { $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']); $status = Dever::status($goods_status, $v['status']); $tk = Dever::db('agent/dh_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2)); if ($tk && $tk['process'] == 1) { $status = '申请' . $tk_status[$tk['status']]; //$status .= '  [' . $tk_process[$tk['process']] . ']'; } if (isset($goods_info['sku'])) { $sku = $goods_info['sku']['string']; } else { $sku = '无'; } if ($info['status'] > 1 && $info['status'] < 7) { $tui = Dever::url('buy_order_tui?shop_id='.$v['shop_id'].'&order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&cash=' . $v['price'], 'shop'); $status = '退款'; $status = ''; } $d = array ( 'pic' => $goods_info['cover'], 'name' => $goods_info['name'], 'sku' => $sku, 'price' => $v['price'], 'num' => $v['num'], 'status' => $status, ); if ($tk && $v['status'] == 3) { $d['status'] = $tk_status[$tk['status']]; $refund_body[] = $d; $price = $v['price']*$v['num']; $refund_body_total['price'] += $price; $refund_body_total['num'] += $v['num']; } else { $body[] = $d; $price = $v['price']*$v['num']; $body_total['price'] += $price; $body_total['num'] += $v['num']; } } if ($body) { if ($refund_body_total['price']) { $body_total['set_price'] = $body_total['price'] - $refund_body_total['price']; } if ($refund_body_total['num']) { $body_total['set_num'] = $body_total['num'] - $refund_body_total['num']; } $result['商品清单'] = array ( 'type' => 'list', 'content' => $body, 'total' => $body_total, ); } if ($refund_body) { $result['退款商品'] = array ( 'type' => 'list', 'content' => $refund_body, 'total' => $refund_body_total, ); } # 平台门店采购单 $buy_order = Dever::db('shop/buy_order')->getDataToId(array('type' => 1, 'type_id' => $info['shop_id'], 'parent_type' => 3, 'parent_order_id' => $info['id'])); $source_order_id = array(); if ($buy_order) { $source_order_id = array_keys($buy_order); } # 平台门店结算单 if ($source_order_id) { $cash_order = Dever::db('cash/order')->getDataByOrderId(array('source_order_id' => $source_order_id)); $col = 'cash'; } if (isset($cash_order) && $cash_order) { $head = array('序号', '结算单号', '数量', '金额', '结算类型', '入账状态', '审核状态', '结算时间', '审核备注', '管理'); $body = array(); $config = Dever::db('cash/order')->config; foreach ($cash_order as $k => $v) { $cdate = date('Y-m-d H:i', $v['cdate']); $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : ''; $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : ''; $cash = $v[$col]; $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1', 'manage'); $v['source_order_num'] = ''.$v['source_order_num'].''; $m = ''; if ($v['audit'] == 1 && $v['audit_type'] == 2) { $url = Dever::url('project/database/update?project=cash&table=order&where_id='.$v['id'].'&col=audit,desc', 'manage'); $m = '审核'; } $d = array ( $k+1, $v['order_num'], $v['num'], $cash, $config['config_jstype'][$v['jstype']], $config['config_status'][$v['status']], $config['config_audit'][$v['audit']], $operdate, $v['desc'], $m, ); $body[] = $d; } $result['对账清单'] = array ( 'type' => 'table', 'content' => array ( 'head' => $head, 'body' => $body, ) ); } $head_btn[] = array ( 'type' => 'link', 'link' => Dever::url('project/database/list?project=agent&table=dh_order&menu=agent&search_option_state=1', 'manage'), 'name' => '返回上一页', ); if (Dever::load('manage/auth')->checkFunc('agent.dh_order', 'editdhaddress', '修改地址')) { if ($info['address_id']>0){ $head_btn[] = array ( 'type' => 'edit', 'link' => Dever::url('project/database/update?project=agent&table=member_address&search_option_info_id='.$info['id'].'&search_option_mid='.$info['mid'].'&search_option_contact='.$address['contact'].'&search_option_mobile='.$address['mobile'].'&search_option_area='.$address['area'].'&search_option_address='.$address['address'].'&search_option_house_number='.$address['house_number'].'&status=1&col=contact,mobile,area,address,house_number,mid,info_id', 'manage'), 'name' => '修改地址', ); } } $audit = Dever::input('audit'); if($audit==1){ # 审核信息 $this->show_audit($info, $result); } $head = array ( 'name' => '基本信息', 'btn' => $head_btn, ); $html = Dever::show($head, $result); return $html; } public function addressUpdate($id,$name,$data) { $info_id = Dever::param('info_id',$data); if ($info_id) { $info = Dever::db('agent/dh_order')->find($info_id); if ($info) { $where['where_id'] = $info['id']; $where['address_id'] = $id; Dever::db('agent/dh_order')->update($where); } } } private function show_audit($info, &$result) { $info['type'] = 3; $goods = Dever::db('agent/dh_order_goods')->select(array('order_id' => $info['id'], 'status' => 1)); $shop = Dever::db('shop/info')->find($info['shop_id']); list($data, $source) = Dever::load('mshop/lib/buy')->assign($goods, $info, $shop, true); // print_R($data);die; if ($info) { $head = array('序号', '商品编号', '商品名称', '供货商', '订货总数量', '商品计量单位', '订货单总金额'); $body = array(); $i = 0; if ($data) { foreach ($data 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, Dever::load('mshop/lib/buy')->getSelect($source, $v1['source_id'], $v1['order_goods_id']), $v1['num'], $goods_info['unit'], $v1['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, Dever::load('mshop/lib/buy')->getSelect($source, false, $v['id']), $v['num'], $goods_info['unit'], $v['price'] * $v['num'], ); $body[] = $d; $i++; } } $btn = array(); $btn[] = array( 'type' => 'click', 'content' => 'setAudit()', 'name' => '全部调整' ); $result['商品拆单'] = array ( 'type' => 'table', 'head' => array('name' => '供货商:' . Dever::load('mshop/lib/buy')->getSelect($source, false, false), 'btn' => $btn), 'content' => array ( 'head' => $head, 'body' => $body, ) ); $url = Dever::url('lib/dhorder.audit_set_commit?json=1&order_id=' . $info['id'], 'agent'); // print_R($url);die; $result['审核结果'] = array ( 'type' => 'html', 'content' => '
审核通过    审核未通过   
保存
', ); } } # 采购订单审核 手动拆单 public function audit_set_commit_api() { Dever::config('base')->hook = true; //{goods: "2_4_audit_615,2_4_audit_614,-1_-1_audit_617,-1_-1_audit_616,-1_-1_audit_613", audit: "1", audit_text: "1231"} $id = Dever::input('order_id'); $goods = Dever::input('goods'); $audit = Dever::input('audit'); $audit_text = Dever::input('audit_text'); $info = Dever::db('agent/dh_order')->one($id); if ($audit > 1 && $info && $info['status'] == 2) { $shop = Dever::db('shop/info')->find($info['shop_id']); if ($audit == 2) { Dever::db('agent/dh_order')->update(array('where_id' => $info['id'], 'audit' => $audit, 'audit_desc' => $audit_text)); # 成功 if (strstr($info['order_num'], '_')) { $temp = explode('_', $info['order_num']); $info['order_num'] = $temp[0]; $info['order_index'] = $temp[1]; } else { $info['order_index'] = 0; } $goods = explode(',', $goods); $data = $other = array(); foreach ($goods as $k => $v) { list($source_type, $source_id, $name, $goods_id) = explode('_', $v); $gv = Dever::db('agent/dh_order_goods')->find($goods_id); if ($source_id > 0) { $key = $source_type . '_' . $source_id; $data[$key][] = array ( 'area' => $shop['area'], 'order_id' => $info['id'], 'order_type' => 3, 'order_num' => $info['order_num'], 'order_index' => $info['order_index'], 'type' => 1, 'type_id' => $shop['id'], 'source_type' => $source_type, 'source_id' => $source_id, 'order_goods_id' => $gv['id'], 'goods_id' => $gv['goods_id'], 'sku_id' => $gv['sku_id'], 'price' => $gv['price'], 'p_price' => $gv['price'], 'num' => $gv['num'], ); } else { $other[] = $gv; } } $this->audit_action($data, $other, $info, $shop, 1); } else { Dever::db('agent/dh_order')->update(array('where_id' => $info['id'], 'audit' => $audit, 'audit_desc' => $audit_text, 'status' => 7)); Dever::load('agent/lib/dhorder')->updateSell($info, 2); if (Dever::project('sms')) { $member = Dever::db('agent/member')->find($info['mid']); Dever::load('sms/api')->send('daili_goods_no', $member['mobile'], array('name' => $member['name'], 'content' => $audit_text)); } } } return Dever::url('project/database/list&project=agent&table=dh_order&menu=agent&search_option_state=1&search_option_shop_type=2&menu_id=218', 'manage'); } # 采购订单审核 拆单 public function audit_commit() { $order_id = Dever::input('order_id'); $order = Dever::db('agent/dh_order')->find($order_id); if (!$order || ($order && $order['status'] != 2)) { Dever::alert('当前订单状态无法拆单'); } // if ($order['shop_type'] != 2) { // Dever::alert('这不是平台店的订单'); // } $order['type'] = 3; $goods = Dever::db('agent/dh_order_goods')->select(array('order_id' => $order_id)); $shop = Dever::db('shop/info')->find($order['shop_id']); $data = Dever::load('mshop/lib/buy')->assign($goods, $order, $shop); $this->audit_action($data, $goods, $order, $shop); return 'ok'; } private function audit_action($data, $goods, $order, $shop, $state = 2) { $send = array(); if (!$goods && $data) { # 开始生成订单 $i = $order['order_index']; foreach ($data as $k => $v) { foreach ($v as $k1 => $v1) { $v1['order_num'] .= '_' . $i; $state = Dever::load('mshop/lib/buy')->createOrder($v1); $send[$state] = $v1; } $i++; } Dever::db('agent/dh_order')->update(array('where_id' => $order['id'], 'status' => 3)); } else { Dever::db('agent/dh_order')->update(array('where_id' => $order['id'], 'audit' => 1)); if ($goods) { $string = array(); foreach ($goods as $k => $v) { $info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']); if ($info['sku_name']) { $info['name'] .= '('.$info['sku_name'].')'; } $string[] = $info['name']; } $string = implode('、', $string); if ($state == 1) { Dever::alert('商品:'.$string.'未选择供货商'); } else { Dever::alert('商品:'.$string.'库存不足或厂家未生产,请联系供货商备货,该订单进入重新审核状态'); } Dever::alert('商品:'.$string.'库存不足或厂家未生产,请联系供货商备货,该订单进入重新审核状态'); } else { if ($state == 1) { Dever::alert('未选择供货商,该订单进入重新审核状态'); } else { Dever::alert('供货商库存不足,请联系供货商备货,该订单进入重新审核状态'); } } } if ($send) { foreach ($send as $k => $v) { Dever::load('mshop/lib/buy')->sendMsg($v['source_type'], $v['source_id'], $k); $order_info = Dever::db('shop/buy_order')->find(array('id' => $k, 'clear' => true)); Dever::load('cash/lib/order')->up($order_info, 1, 1); } } } # 第三方确认 public function tixian() { $param = array(); ksort($param); $string = array(); foreach ($param as $k => $v) { if (strstr($v, '&') || strstr($v, '@')) { $v = urlencode($v); } $string[] = $k . '=' . $v; } } # 发货 public function notice($info) { $config = Dever::db('agent/dh_order')->config; $state = Dever::db('agent/dh_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time())); } # 采购订单审核 拆单 /* public function audit_commit() { $order_id = Dever::input('order_id'); $order = Dever::db('agent/dh_order')->find($order_id); if (!$order || ($order && $order['status'] != 2)) { Dever::alert('当前订单状态无法拆单'); } $order['type'] = 3; $goods = Dever::db('agent/dh_order_goods')->select(array('order_id' => $order_id)); $shop = Dever::db('shop/info')->find($order['shop_id']); $data = Dever::load('mshop/lib/buy')->assign($goods, $order, $shop); $send = array(); if (!$goods && $data) { # 开始生成订单 $i = $order['order_index']; foreach ($data as $k => $v) { foreach ($v as $k1 => $v1) { $v1['order_num'] .= '_' . $i; $state = Dever::load('mshop/lib/buy')->createOrder($v1); $send[$state] = $v1; } $i++; } Dever::db('agent/dh_order')->update(array('where_id' => $order['id'], 'status' => 3)); } else { Dever::db('agent/dh_order')->update(array('where_id' => $order['id'], 'audit' => 1)); if ($goods) { $string = array(); foreach ($goods as $k => $v) { $info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']); if ($info['sku_name']) { $info['name'] .= '('.$info['sku_name'].')'; } $string[] = $info['name']; } $string = implode('、', $string); Dever::alert('商品:'.$string.'库存不足或厂家未生产,请联系供货商备货,该订单进入重新审核状态'); } else { Dever::alert('供货商库存不足,请联系供货商备货,该订单进入重新审核状态'); } } if ($send) { foreach ($send as $k => $v) { Dever::load('mshop/lib/buy')->sendMsg($v['source_type'], $v['source_id'], $k); $order_info = Dever::db('shop/buy_order')->find(array('id' => $k, 'clear' => true)); Dever::load('cash/lib/order')->up($order_info, 1, 1); } } return 'ok'; } */ public function goodsd_api($id){ $name = ''; $goods = Dever::db('agent/dh_order_goods')->state(array('order_id'=>$id)); foreach($goods as $k1 => $v1){ $goods_info[] = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']); } if(isset($goods_info)){ foreach($goods_info as $v2){ $goods_name[] = $v2['name']; } $name = implode(',',$goods_name); } return $name; } #权益订单导出 public function out_dhorder_api($data){ $header = array('订单编号', '会员姓名', '会员等级', '会员手机号', '收货姓名(或自提人)', '联系电话', '收货地址', '商品名称', '商品数量', '商品原价','订单状态','下单时间', '付款时间', '发货时间','完成时间','卖家订单备注','权益发放时间','代理商终审时间'); $body = array(); foreach($data as $k => $v){ $member = Dever::db('agent/member')->find(array('id'=>$v['mid'])); $role = Dever::db('setting/role')->find(array('id'=>$member['role'])); $address = $res = array(); if ($v['address_id'] && $v['address_id'] > 0) { $address = Dever::db('agent/member_address')->find(array('id'=>$v['address_id'])); if ($address) { $res=Dever::load('agent/address')->getOne($address['mid'],$address['id']); } } $fhdate = ''; $buy_order = Dever::db('shop/buy_order')->find(array('parent_id' => 3, 'parent_order_id' => $v['id'])); if ($buy_order) { $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $buy_order['id'])); $fhdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-'; } $fdate = ''; if($v['fdate']){ $fdate = date('Y-m-d H:i',$v['fdate']); } $quanyi = ''; $member_goods = Dever::db('agent/member_goods')->getQone(array('type'=>$v['type'],'type_id'=>$v['type_id'])); if($member_goods && $member_goods['cdate']){ $quanyi = date('Y-m-d H:i',$member_goods['cdate']); } $order = Dever::db('agent/order')->find(array('mid'=>$member['id'])); $zhongshen = ''; $process = Dever::db('agent/order_process')->state(array('order_id'=>$order['id'])); foreach($process as $k1 => $v1){ if($v1['status'] == 2){ $zhongshen = date('Y-m-d H:i',$v1['cdate']); } } $name = ''; if($v['type'] == 1){ $name = $this->goodsd_api($v['id']); }elseif($v['type'] == 2){ $goods = Dever::db('card/info')->find(array('id'=>$v['type_id'])); if($goods){ $name = $goods['name']; } }elseif($v['type'] == 3){ $goods = Dever::db('setting/prize')->find(array('id'=>$v['type_id'])); if($goods){ $name = $goods['name']; } } $goods_status = Dever::db('agent/dh_order')->config['status']; $status = Dever::status($goods_status, $v['status']); $d = array ( $v['order_num'], $member['name'], $role['name'], $member['mobile'], isset($address['contact']) ? $address['contact'] : '', isset($address['mobile']) ? $address['mobile'] : '', (isset($res['address_info']) ? $res['address_info'] : '').(isset($address['house_number']) ? $address['house_number'] : ''), $name, $v['num'], $v['price'], $status, date('Y-m-d H:i',$v['cdate']), date('Y-m-d H:i',$v['cdate']), $fhdate, $fdate, $v['audit_desc'], $quanyi, $zhongshen, ); $body[] = $d; } $file = Dever::input('excel_name'); return Dever::excelExport($body, $header, $file); } #权益管理导出'5月已用面值', public function out_member_goods_api($data){ $header = array('权益名称', '会员等级', '姓名', '手机号', '卡号','剩余数量', '总数量', '单件价值', '未兑换价值', '已兑换价值', '已用面值','备注','获取方式', '获取时间','代理商注册时间','礼品卡有效期'); $body = array(); foreach($data as $k => $v){ $member = Dever::db('agent/member')->find(array('id'=>$v['mid'])); $member_cdate = '-'; if($member && $member['cdate']){ $member_cdate = date('Y-m-d H:i',$member['cdate']); } $role = Dever::db('setting/role')->find(array('id'=>$member['role'])); $wd = ($v['total_num'] - $v['sell_num'])*$v['price']; $yd = $v['sell_num']*$v['price']; $card = '-'; $mianzhi = '-'; $money = '-'; $youxiao = ''; if($v['type'] == 2){ $code = Dever::db('card/code')->find($v['sku_id']); $start = '1651334400'; $end = '1654012799'; if($code){ $card_info = Dever::db('card/info')->find($code['card_id']); if ($card_info && $card_info['end_dh_day']) { $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate'])); } // $sell_order = Dever::db('shop/sell_order')->getSumCdate(array('start'=>$start,'end'=>$end,'card_code_id'=>$code['id'],'state'=>1)); // if($sell_order && $sell_order['total']){ // $money = $sell_order['total']; // } $card = $code['card']."\t"; $mianzhi = $code['use_cash']; } } $desc = ''; $member_goods_log = Dever::db('agent/member_goods_log')->getOne(array('type'=>$v['type'],'type_id'=>$v['type_id'],'sku_id'=>$v['sku_id'],'state'=>1)); if($member_goods_log && $member_goods_log['desc']){ $desc = $member_goods_log['desc']; } $d = array ( $v['name'], $role['name'], $member['name'], $member['mobile'], $card, $v['total_num']-$v['sell_num'], $v['total_num'], $v['price'], $wd, $yd, $mianzhi, // $money, $desc, '', date('Y-m-d H:i',$v['cdate']), $member_cdate, $youxiao, ); $body[] = $d; } $file = Dever::input('excel_name'); return Dever::excelExport($body, $header, $file); } #未使用数据导出 public function out_member_nogoods($data) { $header = array('权益名称', '会员等级', '姓名', '手机号', '剩余数量', '总数量', '单件价值', '未兑换价值', '已兑换价值', '已用面值','备注','获取方式', '获取时间','代理商注册时间','礼品卡有效期'); $body = array(); foreach ($data as $k => $v) { $member = Dever::db('agent/member')->find(array('id'=>$v['mid'])); $member_cdate = '-'; if($member && $member['cdate']){ $member_cdate = date('Y-m-d H:i',$member['cdate']); } $role = Dever::db('setting/role')->find(array('id'=>$member['role'])); $wd = ($v['total_num'] - $v['sell_num'])*$v['price']; $yd = $v['sell_num']*$v['price']; $card = '-'; $mianzhi = '-'; $money = '-'; $youxiao = ''; if ($v['type'] == 1) { if ($v['total_num'] - $v['sell_num'] == 0) { continue; } } if($v['type'] == 2){ $code = Dever::db('card/code')->find($v['sku_id']); if($code){ if ($code['use_cash'] == $yd && $v['sell_num'] != 0){ continue; } $card_info = Dever::db('card/info')->find($code['card_id']); if ($card_info && $card_info['end_dh_day']) { $youxiao = date('Y-m-d H:i',strtotime(+ $card_info['end_dh_day'].'day',$code['bdate'])); } $card = $code['card']."\t"; $mianzhi = $code['use_cash']; } } $desc = ''; $member_goods_log = Dever::db('agent/member_goods_log')->getOne(array('type'=>$v['type'],'type_id'=>$v['type_id'],'sku_id'=>$v['sku_id'],'state'=>1)); if($member_goods_log && $member_goods_log['desc']){ $desc = $member_goods_log['desc']; } $d = array ( $v['name'], $role['name'], $member['name'], $member['mobile'], // $card, $v['total_num']-$v['sell_num'], $v['total_num'], $v['price'], $wd, $yd, $mianzhi, $desc, '', date('Y-m-d H:i',$v['cdate']), $member_cdate, $youxiao, ); $body[] = $d; } $file = Dever::input('excel_name'); return Dever::excelExport($body, $header, $file); } public function head($type=false){ $data = Dever::db('agent/member_goods')->getProduct(array('type'=>'1,2','state'=>1)); $res = array(); foreach($data as $k => $v){ if($v['name'] && $v['total_num']>0 && $v['type_id']!=8){ $key = $v['type'] . '_' . $v['type_id']; if ($v['type'] == 2) { $card = Dever::db('card/info')->find($v['type_id']); $v['name'] = $card['name']; } if ($v['type'] == 1) { $res[0][$key] = array($v['name'], '价值'); } else { $res[0][$key] = array($v['name'], ''); $res[2][$key] = $v['name']; } $res[1][$key] = $v['name']; } } return $res; } public function out_equity_api($data){ $start = Dever::input('search_option_start_udate'); $end = Dever::input('search_option_end_udate'); $fstart = Dever::input('search_option_start_dever_auth'); $fend = Dever::input('search_option_end_dever_auth'); if($start && $end){ $where['start'] = $start; $where['end'] = $end; }else{ $where['start']=Dever::maketime(date('Y-m-01') . ' 00:00:00'); $where['end'] = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-01')."+1 month - 1 day"))); } $w = array(); if ($fstart) { $w['start'] = $fstart; } if ($fend) { $w['end'] = $fend; } $where['type'] = '1,2'; $res = $this->head(1); $header = array('基础信息', '', '', '', '','', '', '', ''); $body = array(); $pg = Dever::input('pg'); if ($pg == 1) { $body[] = array('代理商姓名', '角色', '电话', '区域','应收合计', '代理费', '产品费(商品)', '产品费(电器卡)','产品费(菜卡)'); } // print_R($res[0]);die; $i = 0; foreach ($res[0] as $k => $v) { if ($i == 0) { $header[] = '发放权益'; } else { $header[] = ''; } isset($body[0]) && $body[0][] = $v[0]; if ($v[1]) { isset($body[0]) && $body[0][] = $v[1]; $header[] = ''; } $i++; } $i = 0; foreach ($res[1] as $k => $v) { isset($body[0]) && $body[0][] = $v; if ($i == 0) { $header[] = '兑换权益'; } else { $header[] = ''; } $i++; } $i = 0; foreach ($res[2] as $k => $v) { isset($body[0]) && $body[0][] = $v; if ($i == 0) { $header[] = '使用金额'; } else { $header[] = ''; } $i++; } $body_member = array(); // $data = Dever::db('agent/member_goods')->getSearchAll($where); foreach ($data as $k => $v) { $member_goods[] = Dever::db('agent/member_goods')->getTOne(array('mid'=>$v['id'],'type'=>'1,2')); } foreach($member_goods as $k => $v){ if($v){ $body_member[] = $v; } } foreach ($body_member as $k => $v) { $month = date('Y-m',$v['cdate']); $member = Dever::db('agent/member')->find($v['mid']); $role = Dever::db('setting/role')->find(array('id'=>$member['role'])); $area = ''; if($member['area']){ $area = Dever::load("area/api.string", $member['area']); } $order = Dever::db('agent/order')->getOrder(array('mid'=>$v['mid'])); // print_R($order);die; // $order = Dever::db('agent/order')->find(array('mid'=>$v['mid'])); $heji = 0; $product_cash = 0; $dianqi_cash = 0; $caipin_cash = 0; $d = array ( $member['name'], $role['name'], $member['mobile'], $area, 0, // $order['agent_cash'], // $month, 0, 0, 0, 0, ); $i = count($d); $goods = array(); foreach ($res[0] as $k1 => $v1) { list($type, $type_id) = explode('_', $k1); $goods[$k1] = Dever::db('agent/member_goods')->getTotal(array('end'=>$where['end'],'mid'=>$v['mid'],'type'=>$type, 'type_id' => $type_id)); $d[$i] = 0; if ($goods[$k1]) { if(strstr($v1[0],'卡')){ $d[$i] = $goods[$k1]['cash'] ? $goods[$k1]['cash'] : 0; }else{ $d[$i] = $goods[$k1]['total_num'] ? $goods[$k1]['total_num'] : 0; } } if ($v1[1]) { $i++; $d[$i] = 0; if ($goods[$k1]) { $d[$i] = $goods[$k1]['cash'] ? $goods[$k1]['cash'] : 0; } } if ($type == 1) { $product_cash += $goods[$k1]['cash'] ? $goods[$k1]['cash'] : 0; } if ($type == 2 ) { if(strstr($v1[0], '器具')){ $dianqi_cash += $goods[$k1]['cash'] ? $goods[$k1]['cash'] : 0; } else { $caipin_cash += $goods[$k1]['cash'] ? $goods[$k1]['cash'] : 0; } } $i++; } // $heji = $order['agent_cash'] + $product_cash + $dianqi_cash + $caipin_cash; $d[4] = $order['agent_cash'] - $product_cash - $dianqi_cash - $caipin_cash; $d[5] = $order['agent_cash']; $d[6] = $product_cash; $d[7] = $dianqi_cash; $d[8] = $caipin_cash; $w1 = $w; $w1['mid'] = $v['mid']; $dh_order_ps = Dever::db('agent/dh_order_ps')->getDui($w1); foreach ($res[1] as $k1 => $v1) { $d[$i] = 0; list($type, $type_id) = explode('_', $k1); if ($goods[$k1]) { if ($type == 2 && strstr($v1,'卡')) { $n = $w; $n['mid'] = $v['mid']; $n['type'] = $type; $n['type_id'] = $type_id; $dh_goods = Dever::db('agent/member_goods')->getDhTotal($n); $d[$i] = $dh_goods['sell_num'] ? $dh_goods['cash']*$dh_goods['sell_num'] : 0; } elseif($type == 1) { if ($dh_order_ps) { foreach($dh_order_ps as $a => $b) { $dh_order_goods = Dever::db('agent/dh_order_goods')->find(array('order_id'=>$b['order_id'], 'goods_id' => $type_id, 'status' => 1)); if($dh_order_goods){ $d[$i] += $dh_order_goods['num']; } } } // $d[$i] = $goods[$k1]['sell_num'] ? $goods[$k1]['sell_num'] : 0; } } $i++; } foreach ($res[2] as $k1 => $v1) { list($type, $type_id) = explode('_', $k1); $w1 = array(); $w1['mid'] = $v['mid']; $w1['type'] = $type; $w1['type_id'] = $type_id; $sku = Dever::db('agent/member_goods')->getCardAll($w1); $array = array_column($sku, 'sku_id'); $sku_id = implode(",",$array); if($sku_id){ $w1 = $w; $w1['card_code_id'] = $sku_id; $w1['status'] = '4,5,6'; $sell_order[$k1] = Dever::db('shop/sell_order')->getCardAlls($w1); }else{ $sell_order[$k1]['total'] = 0; } if($sell_order[$k1]){ $d[$i] = $sell_order[$k1]['total'] ? $sell_order[$k1]['total'] : 0 ; } $i++; } $body[] = $d; } $file = Dever::input('excel_name'); return Dever::excelExport($body, $header, $file); } }