作者 刘朕
1 个管道 的构建 通过 耗费 7 秒

字段导出添加、订单导出筛选支付方式添加

  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: 29925
  5 + * Date: 2018/8/16
  6 + * Time: 14:14
  7 + */
  8 +
  9 +namespace app\admin\controller;
  10 +
  11 +use app\admin\model\OrderModel;
  12 +use cmf\controller\AdminBaseController;
  13 +use think\Db;
  14 +
  15 +class OrderController extends AdminBaseController
  16 +{
  17 +
  18 + protected $decto_array;
  19 + protected $bin_array;
  20 +
  21 + protected $table;
  22 + protected $order_model;
  23 + protected $option_table;
  24 + protected $sort_model;
  25 + protected $order_sort_table;
  26 + public function _initialize()
  27 + {
  28 + $this->decto_array = [ 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25 ];
  29 + $this->bin_array = [ 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25 ];
  30 +
  31 + $this->table = 'Order';
  32 + $this->order_model = new OrderModel();
  33 + $this->option_table = 'OrderOption';
  34 + $this->order_sort_table = 'OrderSort';
  35 +
  36 + // 订单字段类型定义
  37 + $this->sort_model[1] = '<div class="text_item form_options" data-validate="{validate}">
  38 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  39 + <input type="text" name="" id="" value="{value}" class="baby_input" placeholder="请输入{name}" />
  40 + </div>';
  41 + $this->sort_model[2] = '<div class="text_item form_options" data-validate="{validate}">
  42 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  43 + <input type="number" name="" id="" value="{value}" class="baby_input" placeholder="请输入{name}" />
  44 + </div>';
  45 + $this->sort_model[3] = '<div class="text_item form_options" data-validate="{validate}">
  46 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  47 + <input type="number" maxlength="11" name="" id="" value="{value}" class="baby_input" placeholder="请输入{name}" />
  48 + </div>';
  49 + $this->sort_model[4] = '<div class="write_tit form_options" data-validate="{validate}">
  50 + <p class="tit"><span class=" _validate">{name}</span></p>
  51 + <div class="flex_style">
  52 + {options}
  53 + </div>
  54 + </div>';
  55 + $this->sort_model[5] = '<div class="text_item form_options" data-validate="{validate}">
  56 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  57 + <input type="text" name="" id="" value="{value}" class="baby_input" placeholder="请输入{name}" />
  58 + </div>';
  59 + $this->sort_model[6] = '<div class="text_item form_options" data-validate="{validate}">
  60 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  61 + <textarea class="baby_input">{value}</textarea>
  62 + </div>';
  63 + $this->sort_model[7] = '<div class="text_item form_options" data-validate="{validate}">
  64 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  65 + <input type="text" name="" id="product" value="{value}" class="baby_input" placeholder="请选择{name}" />
  66 + <img src="__TMPL__/public/mobile/images/youjiantou.png" class="jiantou" />
  67 + </div>';
  68 + $this->sort_model[8] = '<div class="write_wrap" style="margin: 0;" data-validate="{validate}">
  69 + <p class="text_tit" style="line-height: 0.6rem;"><span class=" _validate">{name}</span>{must}</p>
  70 + </div>
  71 + <div class="up_wrap form_options">
  72 + <div class="up_pic">
  73 + <i class="iconfont icon-msnui-cloud-upload"></i>
  74 + <p class="click_up">点击上传</p>
  75 + </div>
  76 + </div>';
  77 + $this->sort_model[10] = '<div class="text_item no_margin form_options" data-validate="{validate}">
  78 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  79 + <input type="text" name="" id="birthday" readonly="readonly" value="{value}" class="baby_input" placeholder="请选择{name}" />
  80 + <img src="__TMPL__/public/mobile/images/youjiantou.png" class="jiantou" />
  81 + </div>';
  82 + $this->sort_model[11] = '<div class="text_item form_options" data-validate="{validate}">
  83 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  84 + <weui-distpicker province="广东省" city="广州市" area="海珠区"></weui-distpicker>
  85 + <input type="text" name="" id="address" readonly="readonly" value="{value}" class="baby_input" placeholder="请输入{name}" />
  86 + <img src="__TMPL__/public/mobile/images/youjiantou.png" class="jiantou" />
  87 + </div>';
  88 + $this->sort_model[12] = '<div class="text_item form_options" data-validate="{validate}" data-type="12">
  89 + <p class="text_tit"><span class=" _validate">{name}</span>{must}</p>
  90 + <input type="text" name="" id="" value="{value}" class="baby_input" placeholder="请输入{name}" />
  91 + </div>';
  92 + }
  93 +
  94 + /**
  95 + * 电子订单列表
  96 + * @adminMenu(
  97 + * 'name' => '电子订单列表',
  98 + * 'parent' => 'admin/OrderOption/default',
  99 + * 'display'=> true,
  100 + * 'hasView'=> true,
  101 + * 'order' => 10000,
  102 + * 'icon' => '',
  103 + * 'remark' => '电子订单列表',
  104 + * 'param' => ''
  105 + * )
  106 + */
  107 + public function index() {
  108 + $param = $this->request->param();
  109 + // 查询条件处理
  110 + $where = [
  111 + 'delete_time'=>0
  112 + ];
  113 + if(isset($param['keyword'])) {
  114 + $where['order_sn|sort_name|user_login|number'] = ['like','%'.$param['keyword'].'%'];
  115 + }
  116 + if(!empty($param['sort_id'])) {
  117 + $where['sort_id'] = $param['sort_id'];
  118 + }
  119 + if(isset($param['status']) && $param['status'] >= 0) {
  120 + $where['status'] = $param['status'];
  121 + }
  122 + if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
  123 + $where['is_excel'] = $param['is_excel'];
  124 + }
  125 + if(isset($param['is_over']) && $param['is_over'] >= 0) {
  126 + if($param['is_over'] == 0) {
  127 + $where['over_time'] = ['egt',time()];
  128 + }
  129 + if($param['is_over'] == 1) {
  130 + $where['over_time'] = ['lt',time()];
  131 + }
  132 + }
  133 + $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
  134 + $endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
  135 + if (!empty($startTime) && !empty($endTime)) {
  136 + $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
  137 + } else {
  138 + if (!empty($startTime)) {
  139 + $where['create_time'] = ['>= time', $startTime];
  140 + }
  141 + if (!empty($endTime)) {
  142 + $where['create_time'] = ['<= time', $endTime];
  143 + }
  144 + }
  145 + $list = $this->singleData('order_view',$where,2,[],10);
  146 + $list->appends($param);
  147 + $this->assign('list',$list->items());
  148 + $this->assign('page',$list->render());
  149 + $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : '');
  150 + $this->assign('sort_id',isset($param['sort_id']) ? $param['sort_id'] : '');
  151 + $this->assign('status',isset($param['status']) ? $param['status'] : '');
  152 + $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : '');
  153 + $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : '');
  154 + $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : '');
  155 + $this->assign('end_time',isset($param['end_time']) ? $param['end_time'] : '');
  156 + // 订单类型查询
  157 + $sortList = $this->singleData($this->order_sort_table,['delete_time'=>0],1);
  158 + $this->assign('sortList',$sortList);
  159 + return $this->fetch();
  160 + }
  161 +
  162 + /**
  163 + * 电子订单列表(表单类型下)
  164 + * @adminMenu(
  165 + * 'name' => '电子订单列表',
  166 + * 'parent' => 'admin/OrderSort/index',
  167 + * 'display'=> false,
  168 + * 'hasView'=> false,
  169 + * 'order' => 1,
  170 + * 'icon' => '',
  171 + * 'remark' => '电子订单列表(表单类型下)',
  172 + * 'param' => ''
  173 + * )
  174 + */
  175 + public function index_sort() {
  176 + $param = $this->request->param();
  177 + $where = [
  178 + 'delete_time'=>0
  179 + ];
  180 + if(empty($param['sort_id'])) {
  181 + $this->error('参数错误');
  182 + }
  183 + $where['sort_id'] = $param['sort_id'];
  184 + if(isset($param['status']) && $param['status'] >= 0) {
  185 + $where['status'] = $param['status'];
  186 + }
  187 + if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
  188 + $where['is_excel'] = $param['is_excel'];
  189 + }
  190 + if(isset($param['is_over']) && $param['is_over'] >= 0) {
  191 + if($param['is_over'] == 0) {
  192 + $where['over_time'] = ['egt',time()];
  193 + }
  194 + if($param['is_over'] == 1) {
  195 + $where['over_time'] = ['lt',time()];
  196 + }
  197 + }
  198 + $startTime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
  199 + $endTime = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
  200 + if (!empty($startTime) && !empty($endTime)) {
  201 + $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
  202 + } else {
  203 + if (!empty($startTime)) {
  204 + $where['create_time'] = ['>= time', $startTime];
  205 + }
  206 + if (!empty($endTime)) {
  207 + $where['create_time'] = ['<= time', $endTime];
  208 + }
  209 + }
  210 + $list = $this->singleData('order_view',$where,2,[],10);
  211 + $list->appends($param);
  212 + $this->assign('list',$list->items());
  213 + $this->assign('page',$list->render());
  214 + $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : '');
  215 + $this->assign('status',isset($param['status']) ? $param['status'] : '');
  216 + $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : '');
  217 + $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : '');
  218 + $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : '');
  219 + $this->assign('end_time',isset($param['end_time']) ? $param['end_time'] : '');
  220 + $this->assign('sort_id',$param['sort_id']);
  221 + // 订单类型
  222 + $sortList = $this->singleData($this->order_sort_table,['delete_time'=>0],1);
  223 + $this->assign('sortList',$sortList);
  224 + return $this->fetch();
  225 + }
  226 +
  227 + /**
  228 + * 电子订单列表(销售人员下)
  229 + * @adminMenu(
  230 + * 'name' => '电子订单列表',
  231 + * 'parent' => 'admin/OrderSort/index',
  232 + * 'display'=> false,
  233 + * 'hasView'=> false,
  234 + * 'order' => 2,
  235 + * 'icon' => '',
  236 + * 'remark' => '电子订单列表(销售人员下)',
  237 + * 'param' => ''
  238 + * )
  239 + */
  240 + public function index_sales() {
  241 + $param = $this->request->param();
  242 + $where = [
  243 + 'delete_time'=>0
  244 + ];
  245 + if(empty($param['user_id'])) {
  246 + $this->error('参数错误');
  247 + }
  248 + $where['user_id'] = $param['user_id'];
  249 + if(isset($param['keyword'])) {
  250 + $where['order_sn|sort_name|user_login|number'] = ['like','%'.$param['keyword'].'%'];
  251 + }
  252 + if(!empty($param['sort_id'])) {
  253 + $where['sort_id'] = $param['sort_id'];
  254 + }
  255 + if(isset($param['status']) && $param['status'] >= 0) {
  256 + $where['status'] = $param['status'];
  257 + }
  258 + if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
  259 + $where['is_excel'] = $param['is_excel'];
  260 + }
  261 + if(isset($param['is_over']) && $param['is_over'] >= 0) {
  262 + if($param['is_over'] == 0) {
  263 + $where['over_time'] = ['egt',time()];
  264 + }
  265 + if($param['is_over'] == 1) {
  266 + $where['over_time'] = ['lt',time()];
  267 + }
  268 + }
  269 + $startTime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
  270 + $endTime = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
  271 + if (!empty($startTime) && !empty($endTime)) {
  272 + $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
  273 + } else {
  274 + if (!empty($startTime)) {
  275 + $where['create_time'] = ['>= time', $startTime];
  276 + }
  277 + if (!empty($endTime)) {
  278 + $where['create_time'] = ['<= time', $endTime];
  279 + }
  280 + }
  281 + $list = $this->singleData('order_view',$where,2,[],10);
  282 + $list->appends($param);
  283 + $this->assign('list',$list->items());
  284 + $this->assign('page',$list->render());
  285 + $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : '');
  286 + $this->assign('sort_id',isset($param['sort_id']) ? $param['sort_id'] : '');
  287 + $this->assign('status',isset($param['status']) ? $param['status'] : '');
  288 + $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : '');
  289 + $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : '');
  290 + $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : '');
  291 + $this->assign('end_time',isset($param['end_time']) ? $param['end_time'] : '');
  292 + $this->assign('user_id',$param['user_id']);
  293 + // 订单类型
  294 + $sortList = $this->singleData($this->order_sort_table,['delete_time'=>0],1);
  295 + $this->assign('sortList',$sortList);
  296 + return $this->fetch();
  297 + }
  298 +
  299 + /**
  300 + * 用户数据导出
  301 + * @adminMenu(
  302 + * 'name' => '用户数据导出',
  303 + * 'parent' => 'index',
  304 + * 'display'=> false,
  305 + * 'hasView'=> false,
  306 + * 'order' => 3,
  307 + * 'icon' => '',
  308 + * 'remark' => '用户数据导出',
  309 + * 'param' => ''
  310 + * )
  311 + */
  312 + public function excel()
  313 + {
  314 + $param = $this->request->param();
  315 + // 进行查询条件的处理
  316 + $where = [
  317 + 'delete_time'=>0
  318 + ];
  319 + if(!empty($param['ids'])) {
  320 + $where['id'] = ['in',$param['ids']];
  321 + }
  322 + if(isset($param['keyword'])) {
  323 + $where['order_sn|sort_name|user_login|number'] = ['like','%'.$param['keyword'].'%'];
  324 + }
  325 + if(!empty($param['sort_id'])) {
  326 + $where['sort_id'] = $param['sort_id'];
  327 + }
  328 + if(isset($param['status']) && $param['status'] >= 0) {
  329 + $where['status'] = $param['status'];
  330 + }
  331 + if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
  332 + $where['is_excel'] = $param['is_excel'];
  333 + }
  334 + if(isset($param['is_over']) && $param['is_over'] >= 0) {
  335 + if($param['is_over'] == 0) {
  336 + $where['over_time'] = ['egt',time()];
  337 + }
  338 + if($param['is_over'] == 1) {
  339 + $where['over_time'] = ['lt',time()];
  340 + }
  341 + }
  342 + $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
  343 + $endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
  344 + if (!empty($startTime) && !empty($endTime)) {
  345 + $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
  346 + } else {
  347 + if (!empty($startTime)) {
  348 + $where['create_time'] = ['>= time', $startTime];
  349 + }
  350 + if (!empty($endTime)) {
  351 + $where['create_time'] = ['<= time', $endTime];
  352 + }
  353 + }
  354 + // 查询数据并导出
  355 + $list = $this->singleData('order_view',$where,1);
  356 + $this->expList($list);
  357 + }
  358 +
  359 + /**
  360 + * 数字转字母 (类似于Excel列标)
  361 + * @param Int $index 索引值
  362 + * @param Int $start 字母起始值
  363 + * @return String 返回字母
  364 + */
  365 + private function IntToChr($index, $start = 65) {
  366 + $str = '';
  367 + if (floor($index / 26) > 0) {
  368 + $str .= $this->IntToChr(floor($index / 26)-1);
  369 + }
  370 + return $str . chr($index % 26 + $start);
  371 + }
  372 +
  373 + // 数据导出
  374 + private function expList($array)
  375 + {
  376 + // 获取可显示的字段列表
  377 + $option_list = $this->singleData($this->option_table,['delete_time'=>0],1);
  378 +
  379 + //导出Excel
  380 + $objPHPExcel = new \PHPExcel();
  381 +
  382 + // 设置单元格宽度
  383 + $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  384 + $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
  385 + $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
  386 + $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
  387 + $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
  388 + $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
  389 + $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
  390 + $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
  391 + // 设置水平居中
  392 + $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  393 + // 设置垂直居中
  394 + $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
  395 + //Add some data
  396 + $objPHPExcel->setActiveSheetIndex(0)
  397 + ->setCellValue('A1', 'ID')
  398 + ->setCellValue('B1', '订单号')
  399 + ->setCellValue('C1', '订单类型')
  400 + ->setCellValue('D1', '销售用户名')
  401 + ->setCellValue('E1', '订单确认码')
  402 + ->setCellValue('F1', '订单状态')
  403 + ->setCellValue('G1', '收集状态')
  404 + ->setCellValue('H1', '发布时间')
  405 + ->setCellValue('I1', '失效时间');
  406 +
  407 + // 设置表单字段的单元格宽度及第一行文字
  408 + $option_id_array = [];
  409 + foreach ($option_list as $k=>$v) {
  410 + $column = $this->IntToChr($k+10);
  411 + $objPHPExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
  412 + $objPHPExcel->setActiveSheetIndex(0)
  413 + ->setCellValue($column.'1', $v['name']);
  414 + $option_id_array[$k] = $v['id'];
  415 + }
  416 +
  417 + $i = 2;
  418 +
  419 + // 循环到导出数据
  420 + foreach ($array as $v) {
  421 + $status = '未支付';
  422 + if($v['status'] == 1) {
  423 + $status = '已支付';
  424 + }
  425 + $is_stop = '收集中';
  426 + if($v['is_stop'] == 1) {
  427 + $is_stop = '已停止';
  428 + }
  429 + $objPHPExcel->setActiveSheetIndex(0)
  430 + ->setCellValue('A' . $i, $v['id'])
  431 + ->setCellValueExplicit('B' . $i, $v['order_sn'],\PHPExcel_Cell_DataType::TYPE_STRING)
  432 +// ->setCellValueExplicit('B' . $i, $v['order_sn'],\PHPExcel_Cell_DataType::TYPE_STRING)
  433 + ->setCellValue('C' . $i, $v['sort_name'])
  434 + ->setCellValue('D' . $i, $v['user_login'])
  435 + ->setCellValue('E' . $i, $v['number'])
  436 + ->setCellValue('F' . $i, $status)
  437 + ->setCellValue('G' . $i, $is_stop)
  438 + ->setCellValue('H' . $i, date('Y-m-d H:i',$v['create_time']))
  439 + ->setCellValue('I' . $i, date('Y-m-d H:i',$v['over_time']));
  440 + $v['options'] = json_decode($v['options'],true);
  441 + foreach ($v['options'] as $ks=>$vs) {
  442 +// $where = [
  443 +// 'id' => $vs['id']
  444 +// ];
  445 +// $vs['cell'] = Db::name('OrderOption')->where($where)->value('cell');
  446 + $key = array_search($vs['id'], $option_id_array);
  447 + $vs['cell'] = $this->IntToChr($key+10);
  448 + if($vs['cell']) {
  449 + if($vs['type'] == 3) {
  450 + // 纯数字字段转化为字符串格式,防止以科学计数法进行显示
  451 + $objPHPExcel->setActiveSheetIndex(0)
  452 + ->setCellValueExplicit($vs['cell'] . $i, $vs['user_choose'],\PHPExcel_Cell_DataType::TYPE_STRING);
  453 + } elseif($vs['type'] == 8) {
  454 + // 导出图片格式,高度自适应
  455 + $filePath = './upload/'.$vs['user_choose'];
  456 + if(!empty($vs['user_choose']) && file_exists($filePath)) {
  457 + $image = \think\Image::open('./upload/'.$vs['user_choose']);
  458 + // 返回图片的宽度
  459 + $width = $image->width();
  460 + // 返回图片的高度
  461 + $height = $image->height();
  462 + $default = $height/($width/100);
  463 + //设置默认行高(通过图片缩放比例计算高度)
  464 + $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight($default);
  465 + // 图片生成
  466 + $objDrawing[$i] = new \PHPExcel_Worksheet_Drawing();
  467 + $objDrawing[$i]->setPath($filePath);
  468 + // 设置宽度
  469 + $objDrawing[$i]->setWidth(100); //照片宽度
  470 + /*设置图片要插入的单元格*/
  471 + $objDrawing[$i]->setCoordinates($vs['cell'].$i);
  472 + // 图片偏移距离
  473 + $objDrawing[$i]->setOffsetX(12);
  474 + $objDrawing[$i]->setOffsetY(12);
  475 + $objDrawing[$i]->setWorksheet($objPHPExcel->getActiveSheet());
  476 + }
  477 + } else {
  478 + $objPHPExcel->setActiveSheetIndex(0)
  479 + ->setCellValue($vs['cell'] . $i, $vs['user_choose']);
  480 + }
  481 + }
  482 + }
  483 + $i++;
  484 + Db::name('Order')->where(['order_sn'=>$v['order_sn']])->update(['is_excel'=>1,'excel_time'=>time()]);
  485 + }
  486 +
  487 + $filename = '订单数据导出'. date('Y-m-d').'.xls';
  488 + ob_end_clean();
  489 + header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  490 + header('Content-Type: application/vnd.ms-excel');
  491 + header('Content-Disposition: attachment;filename="' . $filename . '"');
  492 + header('Cache-Control: max-age=0');
  493 + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  494 + $objWriter->save('php://output');
  495 + }
  496 +
  497 + /**
  498 + * 编辑订单
  499 + * @adminMenu(
  500 + * 'name' => '编辑订单',
  501 + * 'parent' => 'index',
  502 + * 'display'=> false,
  503 + * 'hasView'=> false,
  504 + * 'order' => 4,
  505 + * 'icon' => '',
  506 + * 'remark' => '编辑订单',
  507 + * 'param' => ''
  508 + * )
  509 + */
  510 + public function edit() {
  511 + $id = $this->request->param('id',0,'intval');
  512 + if(!$id) {
  513 + $this->error('参数错误');
  514 + }
  515 + $where = [
  516 + 'id' => $id,
  517 + 'delete_time'=>0
  518 + ];
  519 + $info = Db::name('order_view')->where($where)->find();
  520 + $info['options'] = json_decode($info['options'],true);
  521 + foreach ($info['options'] as $k=>$v) {
  522 + $optionsInfo = $this->singleData($this->option_table,['id'=>$v['id']]);
  523 + $v['name'] = $optionsInfo['name'];
  524 + $v['html'] = $this->form_model($v);
  525 + $info['group'][] = $v;
  526 + }
  527 + $this->assign($info);
  528 + return $this->fetch();
  529 + }
  530 +
  531 + // 处理订单模型数据
  532 + private function form_model($formData) {
  533 + $html = $this->sort_model[$formData['type']];
  534 + $html = str_replace('{name}',$formData['name'],$html);
  535 + if($formData['checked'] == 1) {
  536 + $html = str_replace('{must}','*',$html);
  537 + $html = str_replace('{validate}',1,$html);
  538 + } else {
  539 + $html = str_replace('{must}','',$html);
  540 + $html = str_replace('{validate}',0,$html);
  541 + }
  542 + if(!empty($formData['values']) && $formData['values'] != null) {
  543 + $array = explode(',',$formData['values']);
  544 + $options = '';
  545 + foreach ($array as $k=>$v) {
  546 + $active = isset($formData['user_choose'])?($formData['user_choose']==$v?'active':''):($k==0?'active':'');
  547 + $options .= '<p class="order_style '.$active.'">'.$v.'</p>';
  548 + }
  549 + $html = str_replace('{options}',$options,$html);
  550 + }
  551 + if(!empty($formData['user_choose'])) {
  552 + $html = str_replace('{value}',$formData['user_choose'],$html);
  553 + } else {
  554 + $html = str_replace('{value}','',$html);
  555 + }
  556 + return $html;
  557 + }
  558 +
  559 + /**
  560 + * 修改订单收集状态
  561 + * @adminMenu(
  562 + * 'name' => '修改订单收集状态',
  563 + * 'parent' => 'index',
  564 + * 'display'=> false,
  565 + * 'hasView'=> false,
  566 + * 'order' => 5,
  567 + * 'icon' => '',
  568 + * 'remark' => '修改订单收集状态',
  569 + * 'param' => ''
  570 + * )
  571 + */
  572 + public function stop()
  573 + {
  574 + $param = $this->request->param();
  575 + $msg = '';
  576 +
  577 + if (isset($param['ids']) && isset($param["is_stop"])) {
  578 + $stop = $param["is_stop"];
  579 + $ids = $this->request->param('ids/a');
  580 +
  581 + $this->order_model->where(['id' => ['in', $ids]])->update(['is_stop' => $stop, 'update_time' => time()]);
  582 +
  583 + if($stop == 0) {
  584 + $msg = "开启收集成功!";
  585 + }
  586 + if($stop == 1) {
  587 + $msg = "停止收集成功!";
  588 + }
  589 + $this->success($msg, '');
  590 +
  591 + }
  592 + if (isset($param['id']) && isset($param["is_stop"])) {
  593 + $stop = $param["is_stop"];
  594 + $id = $this->request->param('id');
  595 +
  596 + $this->order_model->where(['id' => $id])->update(['is_stop' => $stop, 'update_time' => time()]);
  597 +
  598 + if($stop == 0) {
  599 + $msg = "开启收集成功!";
  600 + }
  601 + if($stop == 1) {
  602 + $msg = "停止收集成功!";
  603 + }
  604 + $this->success($msg,'');
  605 +
  606 + }
  607 + }
  608 +
  609 + /**
  610 + * 删除订单
  611 + * @adminMenu(
  612 + * 'name' => '删除订单',
  613 + * 'parent' => 'index',
  614 + * 'display'=> false,
  615 + * 'hasView'=> false,
  616 + * 'order' => 6,
  617 + * 'icon' => '',
  618 + * 'remark' => '删除订单',
  619 + * 'param' => ''
  620 + * )
  621 + */
  622 + public function delete() {
  623 + $id = $this->request->param('id',0,'intval');
  624 + $ids = $this->request->param('ids/a');
  625 + if(isset($id)) {
  626 + $result = $this->order_model->where(['id'=>$id])->update(['delete_time'=>time()]);
  627 + }
  628 + if(isset($ids)) {
  629 + $result = $this->order_model->where(['id'=>['in',$ids]])->update(['delete_time'=>time()]);
  630 + }
  631 + if(!$result) {
  632 + $this->error('删除失败');
  633 + }
  634 + $this->success('删除成功');
  635 + }
  636 +}
@@ -183,6 +183,9 @@ class OrderController extends AdminBaseController @@ -183,6 +183,9 @@ class OrderController extends AdminBaseController
183 if(isset($param['status']) && $param['status'] >= 0) { 183 if(isset($param['status']) && $param['status'] >= 0) {
184 $where['status'] = $param['status']; 184 $where['status'] = $param['status'];
185 } 185 }
  186 + if(!empty($param['pay_type'])) {
  187 + $where['pay_type'] = $param['pay_type'];
  188 + }
186 if(isset($param['is_excel']) && $param['is_excel'] >= 0) { 189 if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
187 $where['is_excel'] = $param['is_excel']; 190 $where['is_excel'] = $param['is_excel'];
188 } 191 }
@@ -212,6 +215,7 @@ class OrderController extends AdminBaseController @@ -212,6 +215,7 @@ class OrderController extends AdminBaseController
212 $this->assign('page',$list->render()); 215 $this->assign('page',$list->render());
213 $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : ''); 216 $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : '');
214 $this->assign('status',isset($param['status']) ? $param['status'] : ''); 217 $this->assign('status',isset($param['status']) ? $param['status'] : '');
  218 + $this->assign('pay_type',isset($param['pay_type']) ? $param['pay_type'] : '');
215 $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : ''); 219 $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : '');
216 $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : ''); 220 $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : '');
217 $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : ''); 221 $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : '');
@@ -254,6 +258,9 @@ class OrderController extends AdminBaseController @@ -254,6 +258,9 @@ class OrderController extends AdminBaseController
254 if(isset($param['status']) && $param['status'] >= 0) { 258 if(isset($param['status']) && $param['status'] >= 0) {
255 $where['status'] = $param['status']; 259 $where['status'] = $param['status'];
256 } 260 }
  261 + if(!empty($param['pay_type'])) {
  262 + $where['pay_type'] = $param['pay_type'];
  263 + }
257 if(isset($param['is_excel']) && $param['is_excel'] >= 0) { 264 if(isset($param['is_excel']) && $param['is_excel'] >= 0) {
258 $where['is_excel'] = $param['is_excel']; 265 $where['is_excel'] = $param['is_excel'];
259 } 266 }
@@ -284,6 +291,7 @@ class OrderController extends AdminBaseController @@ -284,6 +291,7 @@ class OrderController extends AdminBaseController
284 $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : ''); 291 $this->assign('keyword',isset($param['keyword']) ? $param['keyword'] : '');
285 $this->assign('sort_id',isset($param['sort_id']) ? $param['sort_id'] : ''); 292 $this->assign('sort_id',isset($param['sort_id']) ? $param['sort_id'] : '');
286 $this->assign('status',isset($param['status']) ? $param['status'] : ''); 293 $this->assign('status',isset($param['status']) ? $param['status'] : '');
  294 + $this->assign('pay_type',isset($param['pay_type']) ? $param['pay_type'] : '');
287 $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : ''); 295 $this->assign('is_excel',isset($param['is_excel']) ? $param['is_excel'] : '');
288 $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : ''); 296 $this->assign('is_over',isset($param['is_over']) ? $param['is_over'] : '');
289 $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : ''); 297 $this->assign('start_time',isset($param['start_time']) ? $param['start_time'] : '');
@@ -321,6 +329,9 @@ class OrderController extends AdminBaseController @@ -321,6 +329,9 @@ class OrderController extends AdminBaseController
321 if(isset($param['keyword'])) { 329 if(isset($param['keyword'])) {
322 $where['order_sn|sort_name|user_login|number'] = ['like','%'.$param['keyword'].'%']; 330 $where['order_sn|sort_name|user_login|number'] = ['like','%'.$param['keyword'].'%'];
323 } 331 }
  332 + if(!empty($param['user_id'])) {
  333 + $where['user_id'] = $param['user_id'];
  334 + }
324 if(!empty($param['sort_id'])) { 335 if(!empty($param['sort_id'])) {
325 $where['sort_id'] = $param['sort_id']; 336 $where['sort_id'] = $param['sort_id'];
326 } 337 }
@@ -408,6 +419,12 @@ class OrderController extends AdminBaseController @@ -408,6 +419,12 @@ class OrderController extends AdminBaseController
408 $objPHPExcel->getActiveSheet()->getColumnDimension('AP')->setWidth(20); 419 $objPHPExcel->getActiveSheet()->getColumnDimension('AP')->setWidth(20);
409 $objPHPExcel->getActiveSheet()->getColumnDimension('AQ')->setWidth(20); 420 $objPHPExcel->getActiveSheet()->getColumnDimension('AQ')->setWidth(20);
410 $objPHPExcel->getActiveSheet()->getColumnDimension('AR')->setWidth(20); 421 $objPHPExcel->getActiveSheet()->getColumnDimension('AR')->setWidth(20);
  422 + $objPHPExcel->getActiveSheet()->getColumnDimension('AS')->setWidth(20);
  423 + $objPHPExcel->getActiveSheet()->getColumnDimension('AT')->setWidth(20);
  424 + $objPHPExcel->getActiveSheet()->getColumnDimension('AU')->setWidth(20);
  425 + $objPHPExcel->getActiveSheet()->getColumnDimension('AV')->setWidth(20);
  426 + $objPHPExcel->getActiveSheet()->getColumnDimension('AW')->setWidth(20);
  427 + $objPHPExcel->getActiveSheet()->getColumnDimension('AX')->setWidth(20);
411 // 设置水平居中 428 // 设置水平居中
412 $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); 429 $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
413 // 设置垂直居中 430 // 设置垂直居中
@@ -424,7 +441,7 @@ class OrderController extends AdminBaseController @@ -424,7 +441,7 @@ class OrderController extends AdminBaseController
424 ->setCellValue('H1', '收集状态') 441 ->setCellValue('H1', '收集状态')
425 ->setCellValue('I1', '发布时间') 442 ->setCellValue('I1', '发布时间')
426 ->setCellValue('J1', '失效时间') 443 ->setCellValue('J1', '失效时间')
427 - ->setCellValue('K1', '订购方式') 444 + ->setCellValue('K1', '订单来源')
428 ->setCellValue('L1', '来源渠道') 445 ->setCellValue('L1', '来源渠道')
429 ->setCellValue('M1', '销售人员') 446 ->setCellValue('M1', '销售人员')
430 ->setCellValue('N1', '小朋友姓名') 447 ->setCellValue('N1', '小朋友姓名')
@@ -433,7 +450,7 @@ class OrderController extends AdminBaseController @@ -433,7 +450,7 @@ class OrderController extends AdminBaseController
433 ->setCellValue('Q1', '家长姓名') 450 ->setCellValue('Q1', '家长姓名')
434 ->setCellValue('R1', '家长身份') 451 ->setCellValue('R1', '家长身份')
435 ->setCellValue('S1', '其他身份') 452 ->setCellValue('S1', '其他身份')
436 - ->setCellValue('R1', '家长电话') 453 + ->setCellValue('T1', '联系电话')
437 ->setCellValue('U1', '手机备用电话') 454 ->setCellValue('U1', '手机备用电话')
438 ->setCellValue('V1', '座机备用电话') 455 ->setCellValue('V1', '座机备用电话')
439 ->setCellValue('W1', '地址') 456 ->setCellValue('W1', '地址')
@@ -443,21 +460,27 @@ class OrderController extends AdminBaseController @@ -443,21 +460,27 @@ class OrderController extends AdminBaseController
443 ->setCellValue('AA1', '收货人电话') 460 ->setCellValue('AA1', '收货人电话')
444 ->setCellValue('AB1', '收货区域') 461 ->setCellValue('AB1', '收货区域')
445 ->setCellValue('AC1', '商品选择') 462 ->setCellValue('AC1', '商品选择')
446 - ->setCellValue('AD1', '具体版本')  
447 - ->setCellValue('AE1', '其他版本') 463 + ->setCellValue('AD1', '其他具版本')
  464 + ->setCellValue('AE1', '体版本')
448 ->setCellValue('AF1', '订购长度') 465 ->setCellValue('AF1', '订购长度')
449 ->setCellValue('AG1', '其他订购长度') 466 ->setCellValue('AG1', '其他订购长度')
450 ->setCellValue('AH1', '订购起始月') 467 ->setCellValue('AH1', '订购起始月')
451 ->setCellValue('AI1', '订购价格') 468 ->setCellValue('AI1', '订购价格')
452 ->setCellValue('AJ1', '礼物选择') 469 ->setCellValue('AJ1', '礼物选择')
453 - ->setCellValue('AK1', '加赠礼物')  
454 - ->setCellValue('AL1', '加赠礼物名称')  
455 - ->setCellValue('AM1', '是否适龄')  
456 - ->setCellValue('AN1', '不适龄备注')  
457 - ->setCellValue('AO1', '图片')  
458 - ->setCellValue('AP1', '月龄版升级年份')  
459 - ->setCellValue('AQ1', '备注')  
460 - ->setCellValue('AR1', '客户编号'); 470 + ->setCellValue('AK1', '后期加赠礼物')
  471 + ->setCellValue('AL1', '是否适龄')
  472 + ->setCellValue('AM1', '不适龄备注')
  473 + ->setCellValue('AN1', '不适龄照片')
  474 + ->setCellValue('AO1', '月龄版升级年份')
  475 + ->setCellValue('AP1', '备注')
  476 + ->setCellValue('AQ1', '客户编号')
  477 + ->setCellValue('AR1', '介绍人类型')
  478 + ->setCellValue('AS1', '介绍人信息')
  479 + ->setCellValue('AT1', '介绍人礼物')
  480 + ->setCellValue('AU1', '被介绍人礼物')
  481 + ->setCellValue('AV1', '固定礼')
  482 + ->setCellValue('AW1', '选择礼')
  483 + ->setCellValue('AX1', '商品名称');
461 484
462 $i = 2; 485 $i = 2;
463 486
@@ -33,8 +33,8 @@ @@ -33,8 +33,8 @@
33 支付类型: 33 支付类型:
34 <select class="form-control" name="pay_type" style="width: 140px;"> 34 <select class="form-control" name="pay_type" style="width: 140px;">
35 <option value="0">请选择</option> 35 <option value="0">请选择</option>
36 - <option value="1" <eq name="pay_type" value="0">selected</eq>>微信</option>  
37 - <option value="2" <eq name="pay_type" value="1">selected</eq>>支付宝</option> 36 + <option value="1" <eq name="pay_type" value="1">selected</eq>>微信</option>
  37 + <option value="2" <eq name="pay_type" value="2">selected</eq>>支付宝</option>
38 </select>&nbsp; &nbsp; 38 </select>&nbsp; &nbsp;
39 导出状态: 39 导出状态:
40 <select class="form-control" name="is_excel" style="width: 140px;"> 40 <select class="form-control" name="is_excel" style="width: 140px;">
@@ -25,6 +25,12 @@ @@ -25,6 +25,12 @@
25 <option value="0" <eq name="is_over" value="0">selected</eq>>否</option> 25 <option value="0" <eq name="is_over" value="0">selected</eq>>否</option>
26 <option value="1" <eq name="is_over" value="1">selected</eq>>是</option> 26 <option value="1" <eq name="is_over" value="1">selected</eq>>是</option>
27 </select>&nbsp; &nbsp; 27 </select>&nbsp; &nbsp;
  28 + 支付类型:
  29 + <select class="form-control" name="pay_type" style="width: 140px;">
  30 + <option value="0">请选择</option>
  31 + <option value="1" <eq name="pay_type" value="1">selected</eq>>微信</option>
  32 + <option value="2" <eq name="pay_type" value="2">selected</eq>>支付宝</option>
  33 + </select>&nbsp; &nbsp;
28 导出状态: 34 导出状态:
29 <select class="form-control" name="is_excel" style="width: 140px;"> 35 <select class="form-control" name="is_excel" style="width: 140px;">
30 <option value="-1">请选择</option> 36 <option value="-1">请选择</option>
@@ -130,8 +136,10 @@ @@ -130,8 +136,10 @@
130 $('#excel').click(function () { 136 $('#excel').click(function () {
131 var url1 = "{:url('Order/excel')}"; 137 var url1 = "{:url('Order/excel')}";
132 var url2 = url1.split('.',5); 138 var url2 = url1.split('.',5);
  139 + var user_id = "{$user_id}";
133 var sort_id = $('select[name=sort_id]').val(); 140 var sort_id = $('select[name=sort_id]').val();
134 var status = $('select[name=status]').val(); 141 var status = $('select[name=status]').val();
  142 + var pay_type = $('select[name=pay_type]').val();
135 var is_over = $('select[name=is_over]').val(); 143 var is_over = $('select[name=is_over]').val();
136 var is_excel = $('select[name=is_excel]').val(); 144 var is_excel = $('select[name=is_excel]').val();
137 var keyword = $('input[name=keyword]').val(); 145 var keyword = $('input[name=keyword]').val();
@@ -150,11 +158,17 @@ @@ -150,11 +158,17 @@
150 param += '/ids/' + ids; 158 param += '/ids/' + ids;
151 } 159 }
152 if(sort_id.length > 0) { 160 if(sort_id.length > 0) {
  161 + param += '/user_id/'+user_id;
  162 + }
  163 + if(sort_id.length > 0) {
153 param += '/sort_id/'+sort_id; 164 param += '/sort_id/'+sort_id;
154 } 165 }
155 if(status.length > 0) { 166 if(status.length > 0) {
156 param += '/status/'+status; 167 param += '/status/'+status;
157 } 168 }
  169 + if(pay_type.length > 0) {
  170 + param += '/pay_type/'+pay_type;
  171 + }
158 if(is_over.length > 0) { 172 if(is_over.length > 0) {
159 param += '/is_over/'+is_over; 173 param += '/is_over/'+is_over;
160 } 174 }
@@ -18,6 +18,12 @@ @@ -18,6 +18,12 @@
18 <option value="0" <eq name="is_over" value="0">selected</eq>>否</option> 18 <option value="0" <eq name="is_over" value="0">selected</eq>>否</option>
19 <option value="1" <eq name="is_over" value="1">selected</eq>>是</option> 19 <option value="1" <eq name="is_over" value="1">selected</eq>>是</option>
20 </select>&nbsp; &nbsp; 20 </select>&nbsp; &nbsp;
  21 + 支付类型:
  22 + <select class="form-control" name="pay_type" style="width: 140px;">
  23 + <option value="0">请选择</option>
  24 + <option value="1" <eq name="pay_type" value="1">selected</eq>>微信</option>
  25 + <option value="2" <eq name="pay_type" value="2">selected</eq>>支付宝</option>
  26 + </select>&nbsp; &nbsp;
21 导出状态: 27 导出状态:
22 <select class="form-control" name="is_excel" style="width: 140px;"> 28 <select class="form-control" name="is_excel" style="width: 140px;">
23 <option value="-1">请选择</option> 29 <option value="-1">请选择</option>
@@ -125,6 +131,7 @@ @@ -125,6 +131,7 @@
125 var url2 = url1.split('.',5); 131 var url2 = url1.split('.',5);
126 var sort_id = "{$sort_id}"; 132 var sort_id = "{$sort_id}";
127 var status = $('select[name=status]').val(); 133 var status = $('select[name=status]').val();
  134 + var pay_type = $('select[name=pay_type]').val();
128 var is_over = $('select[name=is_over]').val(); 135 var is_over = $('select[name=is_over]').val();
129 var is_excel = $('select[name=is_excel]').val(); 136 var is_excel = $('select[name=is_excel]').val();
130 var keyword = $('input[name=keyword]').val(); 137 var keyword = $('input[name=keyword]').val();
@@ -148,6 +155,9 @@ @@ -148,6 +155,9 @@
148 if(status.length > 0) { 155 if(status.length > 0) {
149 param += '/status/'+status; 156 param += '/status/'+status;
150 } 157 }
  158 + if(pay_type.length > 0) {
  159 + param += '/pay_type/'+pay_type;
  160 + }
151 if(is_over.length > 0) { 161 if(is_over.length > 0) {
152 param += '/is_over/'+is_over; 162 param += '/is_over/'+is_over;
153 } 163 }