123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com.cn
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
- * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
- * =========================================================
- */
- namespace app\admin\controller;
- use app\model\order\Config as ConfigModel;
- use app\model\order\Order as OrderModel;
- use app\model\order\OrderCommon as OrderCommonModel;
- use app\model\order\OrderExport;
- use app\model\system\Promotion as PromotionModel;
- use phpoffice\phpexcel\Classes\PHPExcel;
- use phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007;
- use think\facade\Config;
- /**
- * 订单管理 控制器
- */
- class Order extends BaseAdmin
- {
- /**
- * 快递订单列表
- */
- public function lists()
- {
- $order_label_list = array(
- "order_no" => "订单号",
- "out_trade_no" => "外部单号",
- "name" => "收货人姓名",
- "order_name" => "商品名称",
- "site_name" => "店铺名称",
- );
- $order_status = input("order_status", "");//订单状态
- $order_name = input("order_name", '');
- $pay_type = input("pay_type", '');
- $order_from = input("order_from", '');
- $start_time = input("start_time", '');
- $end_time = input("end_time", '');
- $site_id = input("site_id", "");
- $order_label = !empty($order_label_list[input("order_label")]) ? input("order_label") : "";
- $search_text = input("search", '');
- $promotion_type = input("promotion_type", '');
- $order_type = input("order_type", 'all');//营销类型
- $order_common_model = new OrderCommonModel();
- if (request()->isAjax()) {
- $page_index = input('page', 1);
- $page_size = input('limit', PAGE_LIST_ROWS);
- $condition = [
- // ["order_type", "=", 1]
- ];
- //订单状态
- if ($order_status != "") {
- $condition[] = ["order_status", "=", $order_status];
- }
- //订单内容 模糊查询
- if ($order_name != "") {
- $condition[] = ["order_name", 'like', "%$order_name%"];
- }
- //订单来源
- if ($order_from != "") {
- $condition[] = ["order_from", "=", $order_from];
- }
- //订单支付
- if ($pay_type != "") {
- $condition[] = ["pay_type", "=", $pay_type];
- }
- //订单类型
- if($order_type != 'all'){
- $condition[] = ["order_type", "=", $order_type];
- }
- //营销类型
- if ($promotion_type != "") {
- if($promotion_type == 'empty'){
- $condition[] = ["promotion_type", "=", ''];
- }else{
- $condition[] = ["promotion_type", "=", $promotion_type];
- }
- }
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = ["create_time", "egt", date_to_time($start_time)];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = ["create_time", "elt", date_to_time($end_time)];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- if ($search_text != "") {
- $condition[] = [$order_label, 'like', "%$search_text%"];
- }
- if(!empty($site_id))
- {
- $condition[] = ["site_id", '=', $site_id];
- }
- $list = $order_common_model->getOrderPageList($condition, $page_index, $page_size, "create_time desc");
- return $list;
- } else {
- $this->assign("order_label_list", $order_label_list);
- $order_model = new OrderModel();
- $order_status_list = $order_model->order_status;
- $this->assign("order_status_list", $order_status_list);//订单状态
- //订单来源 (支持端口)
- $order_from = Config::get("app_type");
- $this->assign('order_from_list', $order_from);
- $pay_type = $order_common_model->getPayType();
- $this->assign("pay_type_list", $pay_type);
- $order_type_list = $order_common_model->getOrderTypeStatusList();
- $this->assign("order_type_list", $order_type_list);
- //营销活动类型
- $promotion_model = new PromotionModel();
- $promotion_type = $promotion_model->getPromotionType();
- $this->assign("promotion_type", $promotion_type);
- return $this->fetch('order/lists');
- }
- }
- /**
- * 快递订单详情
- */
- public function detail()
- {
- $order_id = input("order_id", 0);
- $order_common_model = new OrderCommonModel();
- $order_detail_result = $order_common_model->getOrderDetail($order_id);
- $order_detail = $order_detail_result["data"];
- $this->assign("order_detail", $order_detail);
- switch ($order_detail["order_type"]) {
- case 1 :
- $template = "order/detail";
- break;
- case 2 :
- $template = "storeorder/detail";
- break;
- case 3 :
- $template = "localorder/detail";
- break;
- case 4 :
- $template = "virtualorder/detail";
- break;
- }
- return $this->fetch($template);
- }
- /**
- * 订单设置
- */
- public function config()
- {
- if (request()->isAjax()) {
- //订单事件时间设置数据
- $order_event_time_config_data = [
- 'auto_close' => input('order_auto_close_time', 0),//订单未付款自动关闭时间 数字 单位(天)
- 'auto_take_delivery' => input('order_auto_take_delivery_time', 0),//订单发货后自动收货时间 数字 单位(天)
- 'auto_complete' => input('order_auto_complete_time', 0),//订单收货后自动完成时间 数字 单位(天)
- ];
- // //订单发票设置数据
- // $order_invoice_config_data = [
- // 'is_use' => input('invoice_is_use', 0),//是否启用发票 1:启用 0:不启用
- // 'tax' => input('invoice_tax', 0),//发票税率 0-100 不取小数
- // 'content' => input('invoice_content', ''),//发票内容 文具,服装,水果,建材 格式为逗号分隔的字符串 textarea
- // ];
- $config_model = new ConfigModel();
- $res = $config_model->setOrderEventTimeConfig($order_event_time_config_data);
- // $config_model->setOrderInvoiceConfig($order_invoice_config_data);
- return $res;
- } else {
- $config_model = new ConfigModel();
- //订单事件时间设置
- $order_event_time_config = $config_model->getOrderEventTimeConfig();
- $this->assign('order_event_time_config', $order_event_time_config['data']['value']);
- //订单发票设置
- $order_invoice_config = $config_model->getOrderInvoiceConfig();
- $this->assign('order_invoice_config', $order_invoice_config['data']['value']);
- return $this->fetch('order/config');
- }
- }
- /**
- * 订单导出(已订单为主)
- */
- public function exportOrder()
- {
- $order_status = input("order_status", "");//订单状态
- $order_name = input("order_name", '');
- $pay_type = input("pay_type", '');
- $order_from = input("order_from", '');
- $start_time = input("start_time", '');
- $end_time = input("end_time", '');
- $order_label = !empty($order_label_list[input("order_label")]) ? input("order_label") : "";
- $search_text = input("search", '');
- $promotion_type = input("promotion_type", '');
- $order_type = input("order_type", '1');
- $condition[] = ["order_type", "=", $order_type];
- //订单状态
- if ($order_status != "") {
- $condition[] = ["order_status", "=", $order_status];
- }
- //订单内容 模糊查询
- if ($order_name != "") {
- $condition[] = ["order_name", 'like', "%$order_name%"];
- }
- //订单来源
- if ($order_from != "") {
- $condition[] = ["order_from", "=", $order_from];
- }
- //订单支付
- if ($pay_type != "") {
- $condition[] = ["pay_type", "=", $pay_type];
- }
- //营销类型
- if ($promotion_type != "") {
- if($promotion_type == 'empty'){
- $condition[] = ["promotion_type", "=", ''];
- }else{
- $condition[] = ["promotion_type", "=", $promotion_type];
- }
- }
- if (!empty($start_time) && !empty($end_time)) {
- $condition[] = ["create_time", "between", [date_to_time($start_time), date_to_time($end_time)]];
- }
- if ($search_text != "") {
- $condition[] = [$order_label, 'like', "%$search_text%"];
- }
- $order_common_model = new OrderCommonModel();
- //接收需要展示的字段
- $input_field = input('field', '');
- $order = $order_common_model->getOrderList($condition, $input_field, 'id desc');
- $header_arr = array(
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
- 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ'
- );
- $input_field = explode(',', $input_field);
- //处理数据
- $order_export_model = new OrderExport();
- if (!empty($shop['data'])) {
- $order_list = $order_export_model->handleData($order['data'], $input_field);
- }
- $count = count($input_field);
- // 实例化excel
- $phpExcel = new \PHPExcel();
- $phpExcel->getProperties()->setTitle("订单信息-订单维度");
- $phpExcel->getProperties()->setSubject("订单信息-订单维度");
- //单独添加列名称
- $phpExcel->setActiveSheetIndex(0);
- $field = $order_export_model->order_field;
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . '1', $field[$input_field[$i]]);
- }
- if (!empty($order_list)) {
- foreach ($order_list as $k => $v) {
- $start = $k + 2;
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . $start, $v[$input_field[$i]]);
- }
- }
- }
- // 重命名工作sheet
- $phpExcel->getActiveSheet()->setTitle('订单信息-订单维度');
- // 设置第一个sheet为工作的sheet
- $phpExcel->setActiveSheetIndex(0);
- // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
- $objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
- $file = date('Y年m月d日-订单信息', time()) . '.xlsx';
- $objWriter->save($file);
- header("Content-type:application/octet-stream");
- $filename = basename($file);
- header("Content-Disposition:attachment;filename = " . $filename);
- header("Accept-ranges:bytes");
- header("Accept-length:" . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
- /**
- * 订单导出(已订单商品为主)
- */
- public function exportOrderGoods()
- {
- $order_status = input("order_status", "");//订单状态
- $order_name = input("order_name", '');
- $pay_type = input("pay_type", '');
- $order_from = input("order_from", '');
- $start_time = input("start_time", '');
- $end_time = input("end_time", '');
- $order_label = !empty($order_label_list[input("order_label")]) ? input("order_label") : "";
- $search_text = input("search", '');
- $promotion_type = input("promotion_type", '');
- $order_type = input("order_type", '1');
- $condition[] = ["o.order_type", "=", $order_type];
- //订单状态
- if ($order_status != "") {
- $condition[] = ["o.order_status", "=", $order_status];
- }
- //订单内容 模糊查询
- if ($order_name != "") {
- $condition[] = ["o.order_name", 'like', "%$order_name%"];
- }
- //订单来源
- if ($order_from != "") {
- $condition[] = ["o.order_from", "=", $order_from];
- }
- //订单支付
- if ($pay_type != "") {
- $condition[] = ["o.pay_type", "=", $pay_type];
- }
- //营销类型
- if ($promotion_type != "") {
- if($promotion_type == 'empty'){
- $condition[] = ["promotion_type", "=", ''];
- }else{
- $condition[] = ["promotion_type", "=", $promotion_type];
- }
- }
- if (!empty($start_time) && !empty($end_time)) {
- $condition[] = ["o.create_time", "between", [date_to_time($start_time), date_to_time($end_time)]];
- }
- if ($search_text != "") {
- $condition[] = ['o.' . $order_label, 'like', "%$search_text%"];
- }
- $order_common_model = new OrderCommonModel();
- $order_export_model = new OrderExport();
- //接收需要展示的字段
- $field = array_merge($order_export_model->order_field, $order_export_model->order_goods_field);
- $input_field = input('field', implode(',',array_keys($field)));
- $order = $order_common_model->getOrderGoodsDetailList($condition);
- $header_arr = array(
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
- 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ'
- );
- $input_field = explode(',', $input_field);
- //处理数据
- if (!empty($order['data'])) {
- $order_list = $order_export_model->handleData($order['data'], $input_field);
- }
- $count = count($input_field);
- // 实例化excel
- $phpExcel = new \PHPExcel();
- $phpExcel->getProperties()->setTitle("订单信息-商品维度");
- $phpExcel->getProperties()->setSubject("订单信息-商品维度");
- //单独添加列名称
- $phpExcel->setActiveSheetIndex(0);
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . '1', $field[$input_field[$i]]);
- }
- if (!empty($order_list)) {
- foreach ($order_list as $k => $v) {
- $start = $k + 2;
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . $start, $v[$input_field[$i]]);
- }
- }
- }
- // 重命名工作sheet
- $phpExcel->getActiveSheet()->setTitle('订单信息-商品维度');
- // 设置第一个sheet为工作的sheet
- $phpExcel->setActiveSheetIndex(0);
- // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
- $objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
- $file = date('Y年m月d日-订单信息', time()) . '.xlsx';
- $objWriter->save($file);
- header("Content-type:application/octet-stream");
- $filename = basename($file);
- header("Content-Disposition:attachment;filename = " . $filename);
- header("Accept-ranges:bytes");
- header("Accept-length:" . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
- /**
- * 订单导出(维权订单)
- */
- public function exportRefundOrder()
- {
- $refund_status = input("refund_status", "");//退款状态
- $sku_name = input("sku_name", '');//商品名称
- $refund_type = input("refund_type", '');//退款方式
- $start_time = input("start_time", '');//开始时间
- $end_time = input("end_time", '');//结束时间
- $order_no = input("order_no", '');//订单编号
- $delivery_status = input("delivery_status", '');//物流状态
- $refund_no = input("refund_no", '');//退款编号
- $delivery_no = input("delivery_no", '');//物流编号
- $refund_delivery_no = input("refund_delivery_no", '');//退款物流编号
- $order_common_model = new OrderCommonModel();
- //退款状态
- if ($refund_status != "") {
- $condition[] = ["og.refund_status", "=", $refund_status];
- } else {
- $condition[] = ["og.refund_status", "<>", 0];
- }
- //物流状态
- if ($delivery_status != "") {
- $condition[] = ["og.delivery_status", "=", $delivery_status];
- }
- //商品名称
- if ($sku_name != "") {
- $condition[] = ["og.sku_name", "like", "%$sku_name%"];
- }
- //退款方式
- if ($refund_type != "") {
- $condition[] = ["og.refund_type", "=", $refund_type];
- }
- //退款编号
- if ($refund_no != "") {
- $condition[] = ["og.refund_no", "like", "%$refund_no%"];
- }
- //订单编号
- if ($order_no != "") {
- $condition[] = ["og.order_no", "like", "%$order_no%"];
- }
- //物流编号
- if ($delivery_no != "") {
- $condition[] = ["og.delivery_no", "like", "%$delivery_no%"];
- }
- //退款物流编号
- if ($refund_delivery_no != "") {
- $condition[] = ["og.refund_delivery_no", "like", "%$refund_delivery_no%"];
- }
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = ["og.refund_action_time", "egt", date_to_time($start_time)];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = ["og.refund_action_time", "elt", date_to_time($end_time)];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'og.refund_action_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- $order_export_model = new OrderExport();
- $field = array_merge($order_export_model->order_field, $order_export_model->order_goods_field);
- //接收需要展示的字段
- $input_field = input('field', implode(',',array_keys($field)));
- $order = $order_common_model->getOrderGoodsDetailList($condition);
- $header_arr = array(
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
- 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ'
- );
- $input_field = explode(',', $input_field);
- //处理数据
- if (!empty($order['data'])) {
- $order_list = $order_export_model->handleData($order['data'], $input_field);
- }
- $count = count($input_field);
- // 实例化excel
- $phpExcel = new \PHPExcel();
- $phpExcel->getProperties()->setTitle("退款维权订单");
- $phpExcel->getProperties()->setSubject("退款维权订单");
- //单独添加列名称
- $phpExcel->setActiveSheetIndex(0);
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . '1', $field[$input_field[$i]]);
- }
- if (!empty($order_list)) {
- foreach ($order_list as $k => $v) {
- $start = $k + 2;
- for ($i = 0; $i < $count; $i++) {
- $phpExcel->getActiveSheet()->setCellValue($header_arr[$i] . $start, $v[$input_field[$i]]);
- }
- }
- }
- // 重命名工作sheet
- $phpExcel->getActiveSheet()->setTitle('退款维权订单');
- // 设置第一个sheet为工作的sheet
- $phpExcel->setActiveSheetIndex(0);
- // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
- $objWriter = \PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
- $file = date('Y年m月d日-退款维权订单', time()) . '.xlsx';
- $objWriter->save($file);
- header("Content-type:application/octet-stream");
- $filename = basename($file);
- header("Content-Disposition:attachment;filename = " . $filename);
- header("Accept-ranges:bytes");
- header("Accept-length:" . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
- /**
- * 导出字段
- * @return array
- */
- public function getPrintingField()
- {
- $order_export_model = new OrderExport();
- $data = [
- 'order_field' => $order_export_model->order_field,
- 'order_goods_field' => $order_export_model->order_goods_field
- ];
- return success('1', '', $data);
- }
- /**
- * 交易记录
- */
- public function tradelist()
- {
- $order_common_model = new OrderCommonModel();
- if (request()->isAjax()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $member_id = input('member_id', 0);//会员id
- $search_text = input('search_text', 0);//h关键字查询
- $condition = array();
- if($member_id > 0){
- $condition[] = ["member_id", "=", $member_id];
- }
- if(!empty($search_text)){
- $condition[] = [ 'order_no|order_name', 'like', '%' . $search_text . '%' ];
- }
- return $order_common_model->getTradePageList($condition, $page, $page_size, "create_time desc");
- }
- }
- }
|