hook = true; if (!$order) { return false; } if ($audit == 2) { $status = 2; } else { $status = 1; } if ($jstype == 2) { $audit_type = 2; } else { $audit_type = 1; } $where['source_order_id'] = $order['id']; $where['jstype'] = $jstype; if (!$refund) { $where['refund_id'] = -1; } else { $where['refund_id'] = $refund['id']; } $where['clear'] = true; $info = Dever::db('cash/order')->find($where); $update = $where; $update['pay_type'] = $pay_type; $update['status'] = $status; $update['audit'] = $audit; $update['audit_type'] = $audit_type; if ($update['status'] == 2) { $update['operdate'] = $operdate ? $operdate : time(); $update['fdate'] = $update['operdate']; if (isset($order['fdate']) && $order['fdate'] && ($order['status'] == 5 || $order['status'] == 6)) { $update['fdate'] = $order['fdate']; } } if (isset($order['record_cash']) && $order['record_cash']) { $order['price'] += $order['record_cash']; } if ($info && $jstype == 3) { } else { $update['type'] = $order['type']; $update['type_id'] = $order['type_id']; if ($order['source_type']) { $update['source_type'] = $order['source_type']; $update['source_id'] = $order['source_id']; } $update['source_order_num'] = $order['order_num']; $update['num'] = $order['num']; if ($refund) { $update['cash'] = $refund['cash']; $update['p_cash'] = isset($refund['p_cash']) ? $refund['p_cash'] : 0; } else { $update['cash'] = $order['price']; $update['p_cash'] = $order['p_price']; } if ($jstype == 2) { $update['cash'] = -1*$update['cash']; $update['p_cash'] = -1*$update['p_cash']; $update['num'] = -1*$update['num']; } } if (isset($update['cash']) && $update['cash'] <= 0) { return; } if ($info) { $update['where_id'] = $info['id']; $state = Dever::db('cash/order')->update($update); } else { $update['order_num'] = $this->getOrderId(); $state = Dever::db('cash/order')->insert($update); } if ($state && $jstype == 2 && $status == 2 && isset($order['status']) && $order['status'] == 8) { # 如果是退款结算,同时要把主订单也结算 $where = array(); $where['source_order_id'] = $order['id']; if ($pay_type > 1) { $where['jstype'] = 3; } else { $where['jstype'] = 1; } $where['audit'] = 1; $where['clear'] = true; $info = Dever::db('cash/order')->find($where); if ($info) { $set['status'] = 2; $set['audit'] = 2; $set['where_id'] = $info['id']; $set['operdate'] = $operdate ? $operdate : time(); $set['fdate'] = $operdate ? $operdate : time(); Dever::db('cash/order')->update($set); } } } # 生成订单号 public function getOrderId() { $where['order_num'] = Dever::order('JS'); $state = Dever::db('cash/order')->one($where); if (!$state) { return $where['order_num']; } else { return $this->getOrderId(); } } #导出Excel public function out_order_api($data){ $header = array('ID', '结算单号', '结算门店', '订货单编号', '数量', '结算金额', '结算类型', '入账状态', '审核状态', '支付类型', '结算时间','审核备注','生成时间', '礼品卡卡号'); $body = array(); foreach($data as $k => $v){ $type_info = Dever::db('shop/info')->find(array('id'=>$v['type_id'])); $config_jstype = Dever::db('cash/order')->config['config_jstype']; if(isset($v['jstype']) && $v['jstype']){ $jstype = Dever::status($config_jstype,$v['jstype']); } $config_status = Dever::db('cash/order')->config['config_status']; if(isset($v['status']) && $v['status']){ $status = Dever::status($config_status,$v['status']); } $config_audit = Dever::db('cash/order')->config['config_audit']; if(isset($v['audit']) && $v['audit']){ $audit = Dever::status($config_audit,$v['audit']); } if(isset($v['pay_type']) && $v['pay_type']){ if($v['pay_type'] == 1){ $pay_type_name = '在线支付'; }elseif($v['pay_type'] == 2){ $pay_type_name = '礼品卡支付'; }else{ $pay_type_name = '钱包支付'; } } $operdate = '-'; if(isset($v['operdate']) && $v['operdate']){ $operdate = date('Y-m-d H:i',$v['operdate']); } $cdate = '-'; if(isset($v['cdate']) && $v['cdate']){ $cdate = date('Y-m-d H:i',$v['cdate']); } $card_code_card = ''; if ($v['pay_type'] == 2) { $sell_order = Dever::db('shop/sell_order')->find($v['source_order_id']); if ($sell_order) { $card_code_card = $sell_order['card_code_card']."\n"; } } $d = array ( $v['id'], $v['order_num'], $type_info['name'], $v['source_order_num'], $v['num'], $v['cash'], $jstype, $status, $audit, $pay_type_name, $operdate, $v['desc'], $cdate, $card_code_card, ); $body[] = $d; } $file = Dever::input('excel_name'); return Dever::excelExport($body, $header, $file); } }