作者 SHW\戥岁。。

加入购物车商品分类添加

@@ -141,8 +141,8 @@ class Fastexport extends Backend @@ -141,8 +141,8 @@ class Fastexport extends Backend
141 'status' => 0,// 0准备好,1进行中,2完成,3失败 141 'status' => 0,// 0准备好,1进行中,2完成,3失败
142 'min' => $min, 142 'min' => $min,
143 'max' => $max, 143 'max' => $max,
144 - 'sql' => $ExportLib->buildSql('limit', [$min, $max])  
145 - ] 144 + 'sql' => $ExportLib->buildSql('limit', [$min, $max]),
  145 + ],
146 ]; 146 ];
147 147
148 // 测试sql 148 // 测试sql
@@ -160,7 +160,7 @@ class Fastexport extends Backend @@ -160,7 +160,7 @@ class Fastexport extends Backend
160 $this->success('导出任务测试准备好~', null, [ 160 $this->success('导出任务测试准备好~', null, [
161 'direct_export' => true, 161 'direct_export' => true,
162 'subtask' => $subtask, 162 'subtask' => $subtask,
163 - 'id' => $ids 163 + 'id' => $ids,
164 ]); 164 ]);
165 } 165 }
166 166
@@ -200,7 +200,7 @@ class Fastexport extends Backend @@ -200,7 +200,7 @@ class Fastexport extends Backend
200 'status' => 0,// 0准备好,1进行中,2完成,3失败 200 'status' => 0,// 0准备好,1进行中,2完成,3失败
201 'min' => $min, 201 'min' => $min,
202 'max' => $xls_max_number, 202 'max' => $xls_max_number,
203 - 'sql' => $ExportLib->buildSql('limit', [$min, $xls_max_number]) 203 + 'sql' => $ExportLib->buildSql('limit', [$min, $xls_max_number]),
204 ]; 204 ];
205 205
206 // 测试sql 206 // 测试sql
@@ -246,7 +246,7 @@ class Fastexport extends Backend @@ -246,7 +246,7 @@ class Fastexport extends Backend
246 $this->success('导出任务初始化成功!', null, [ 246 $this->success('导出任务初始化成功!', null, [
247 'direct_export' => ($subtask_count == 1) ? true : false, 247 'direct_export' => ($subtask_count == 1) ? true : false,
248 'subtask' => $subtask, 248 'subtask' => $subtask,
249 - 'id' => $ids 249 + 'id' => $ids,
250 ]); 250 ]);
251 } 251 }
252 252
@@ -306,6 +306,227 @@ class Fastexport extends Backend @@ -306,6 +306,227 @@ class Fastexport extends Backend
306 } 306 }
307 307
308 /** 308 /**
  309 + * 执行自定义导出
  310 + * @param int $task_id 任务ID
  311 + * @param int $subtask_id 子任务ID
  312 + * @param boolean $direct_export 是否直接反回文件
  313 + */
  314 + public function zdyTask()
  315 + {
  316 + $task_id = 1;
  317 + $subtask_id = 1;
  318 + $direct_export = true;
  319 + \think\Config::set('default_return_type', 'json');
  320 + $row = $this->model->get($task_id);
  321 + if (!$row) {
  322 + $this->error(__('No Results were found'));
  323 + }
  324 +
  325 + if (isset($row['subtask'][$subtask_id]) && is_array($row['subtask'][$subtask_id])) {
  326 + $subtask = $row['subtask'][$subtask_id];
  327 + $task_name = $row['name'];
  328 + } else {
  329 + $this->result(['subtask_id' => $subtask_id], 0, '子任务找不到啦~', 'json');
  330 + }
  331 +
  332 + set_time_limit(0);// 脚本执行时间限制
  333 + ini_set('memory_limit', $row['memory_limit'] . 'M');// 脚本内存限制
  334 + $ExportLib = new ExportLib($row);
  335 + unset($row);
  336 +
  337 + // 检查任务状态
  338 + if (!$direct_export) {
  339 + if ($subtask['status'] == 1) {
  340 + $this->result(['subtask_id' => $subtask_id], 0, '此子任务正在执行中~', 'json');
  341 + } else if ($subtask['status'] == 2) {
  342 + if (file_exists($this->save_dir . $task_id . DS . $subtask_id . '.xlsx')) {
  343 + $this->result(['subtask_id' => $subtask_id], 1, '此子任务已经处理过啦~', 'json');
  344 + }
  345 + }
  346 + }
  347 +
  348 + $spreadsheet = new Spreadsheet();
  349 + $worksheet = $spreadsheet->getActiveSheet();
  350 + $worksheet->setTitle($task_name);
  351 +
  352 + //设置表头
  353 + $head = $ExportLib->getXlsTitle();
  354 + $head_count = count($head);
  355 + for ($i = 0; $i < $head_count; $i++) {
  356 + $worksheet->setCellValueByColumnAndRow($i + 1, 1, $head[$i]);
  357 + }
  358 +
  359 + // 写人数据
  360 + try {
  361 + $data = Db::query($subtask['sql']);
  362 + } catch (PDOException $e) {
  363 + $this->result([
  364 + 'subtask_id' => $subtask_id,
  365 + 'error_msg' => $e->getMessage(),
  366 + ], 0, '任务失败!', 'json');
  367 + }
  368 +
  369 + $y = 2;
  370 + foreach ($data as $row_key => $row) {
  371 + $i = 1;
  372 + foreach ($ExportLib->fields as $key => $value) {
  373 +
  374 + $field = $value['field'];
  375 +
  376 + if ($value['discerns'] == 0) {
  377 + // 文本
  378 + $worksheet->setCellValueByColumnAndRow($i, $y, $row[$field], DataType::TYPE_STRING);
  379 + } else if ($value['discerns'] == 1) {
  380 + // 数字
  381 + $worksheet->setCellValueByColumnAndRow($i, $y, $row[$field] . "\t");
  382 + } else if ($value['discerns'] == 2) {
  383 + // 日期时间
  384 + if ($row[$field]) {
  385 +
  386 + $excelDateValue = date('Y-m-d H:i:s', $row[$field]);
  387 + $worksheet->setCellValueByColumnAndRow($i, $y, $excelDateValue, DataType::TYPE_STRING);
  388 +
  389 + /*$excelDateValue = PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel( $row[$field] );
  390 + if ($excelDateValue) {
  391 + // 以日期日期格式写入,没区别,有需要的可以打开
  392 + $worksheet->setCellValueByColumnAndRow($i, $y, $excelDateValue);
  393 + $worksheet->getStyleByColumnAndRow($i,$y)
  394 + ->getNumberFormat()
  395 + ->setFormatCode('yyyy-mm-dd h:mm:ss');
  396 + $worksheet->getStyleByColumnAndRow($i,$y)->getFont()->setBold(true);
  397 + $worksheet->getStyleByColumnAndRow($i,$y)->getFont()->setBold(false);
  398 + }*/
  399 + } else {
  400 + $worksheet->setCellValueByColumnAndRow($i, $y, '-', DataType::TYPE_STRING);
  401 + }
  402 + } else if ($value['discerns'] == 3) {
  403 + // 图片-太慢,太耗资源,弃用
  404 + /*$file_info = pathinfo($row[$field]);
  405 + $coorrow = $worksheet->getCellByColumnAndRow($i, $y)->getRow();
  406 + $coorcolumn = $worksheet->getCellByColumnAndRow($i, $y)->getColumn();
  407 +
  408 + if ($y == 2) {
  409 + $worksheet->getColumnDimension($coorcolumn)->setWidth(8);
  410 + }
  411 +
  412 + $worksheet->getRowDimension($coorrow)->setRowHeight(40);
  413 +
  414 + if (!empty($file_info['basename'])) {
  415 + $basename = $file_info['basename'];
  416 + $drawing = new Drawing();
  417 + $drawing->setName('图片');
  418 + $drawing->setPath($remote_save_dir . $row[$field]);
  419 + $drawing->setWidth(40);
  420 + $drawing->setHeight(40);
  421 + $drawing->setCoordinates($coorcolumn . $coorrow);
  422 + $drawing->setWorksheet($worksheet);
  423 + } else {
  424 + $worksheet->setCellValueByColumnAndRow($i, $y, $row[$field], DataType::TYPE_STRING);
  425 + }*/
  426 +
  427 + // 以链接导出图片
  428 + $field_value = cdnurl($row[$field], true);
  429 + $worksheet->setCellValueByColumnAndRow($i, $y, $field_value, DataType::TYPE_STRING);
  430 + $worksheet->getCellByColumnAndRow($i, $y)->getHyperlink()->setUrl($field_value);
  431 +
  432 + } else if ($value['discerns'] == 4) {
  433 + // 文件
  434 + $field_value = cdnurl($row[$field], true);
  435 + $worksheet->setCellValueByColumnAndRow($i, $y, $field_value, DataType::TYPE_STRING);
  436 + $worksheet->getCellByColumnAndRow($i, $y)->getHyperlink()->setUrl($field_value);
  437 + } else if ($value['discerns'] == 5) {
  438 + // 赋值
  439 + $field_value = $ExportLib->assignment($row[$field], $value['scheme']);
  440 + $worksheet->setCellValueByColumnAndRow($i, $y, $field_value, DataType::TYPE_STRING);
  441 + }
  442 +
  443 + $i++;
  444 + }
  445 + $y++;
  446 + unset($data[$row_key]); // 能节约一点内存
  447 + }
  448 +
  449 + // xls文件处理
  450 + if ($direct_export) {
  451 + // 直接下载
  452 + ob_end_clean();
  453 + header("Pragma: public");
  454 + header("Expires: 0");
  455 + header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
  456 + header("Content-Type:application/force-download");
  457 + header("Content-Type:application/vnd.ms-execl");
  458 + header("Content-Type:application/octet-stream");
  459 + header("Content-Type:application/download");
  460 +
  461 + $task_name = $task_id . '.' . $task_name . '.xlsx';
  462 + $encoded_filename = urlencode($task_name);
  463 + $ua = $_SERVER["HTTP_USER_AGENT"];
  464 + if (preg_match("/MSIE/", $ua)) {
  465 + header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
  466 + } else if (preg_match("/Firefox/", $ua)) {
  467 + header('Content-Disposition: attachment; filename*="utf8\'\'' . $task_name . '"');
  468 + } else {
  469 + header('Content-Disposition: attachment; filename="' . $task_name . '"');
  470 + }
  471 + header("Content-Transfer-Encoding:binary");
  472 + header('Cache-Control: max-age=0');// 禁止缓存
  473 +
  474 + $writer = new Xlsx($spreadsheet);
  475 + $writer->save('php://output');
  476 + $spreadsheet->disconnectWorksheets();
  477 + unset($spreadsheet);
  478 + } else {
  479 + // 保存
  480 + $writer = new Xlsx($spreadsheet);
  481 + $writer->save($this->save_dir . $task_id . DS . $subtask_id . '.xlsx');
  482 +
  483 + // 设置任务状态
  484 + $result = false;
  485 + Db::startTrans();
  486 + try {
  487 + // 读取最新的 subtask 数据
  488 + $row = $this->model->get($task_id);
  489 + $progress = $row->progress + round(92 / count($row['subtask']), 2);
  490 + $progress = ($progress > 100) ? 100 : $progress;
  491 +
  492 + if (isset($row['subtask'][$subtask_id]) && is_array($row['subtask'][$subtask_id])) {
  493 + $subtask = $row['subtask'];
  494 + $subtask[$subtask_id]['status'] = 2;
  495 + $row->subtask = $subtask;
  496 + $row->progress = $progress;
  497 + $row->save();
  498 + $result = true;
  499 + }
  500 + Db::commit();
  501 + } catch (PDOException $e) {
  502 + Db::rollback();
  503 +
  504 + $this->result([
  505 + 'subtask_id' => $subtask_id,
  506 + 'error_msg' => $e->getMessage(),
  507 + ], 0, '任务失败!', 'json');
  508 +
  509 + } catch (Exception $e) {
  510 + Db::rollback();
  511 +
  512 + $this->result([
  513 + 'subtask_id' => $subtask_id,
  514 + 'error_msg' => $e->getMessage(),
  515 + ], 0, '任务失败!', 'json');
  516 + }
  517 +
  518 + $spreadsheet->disconnectWorksheets();
  519 + unset($spreadsheet);
  520 +
  521 + if ($result) {
  522 + $this->result(['subtask_id' => $subtask_id], 1, '子任务处理成功!', 'json');
  523 + } else {
  524 + $this->result(['subtask_id' => $subtask_id], 0, '子任务找不到啦~', 'json');
  525 + }
  526 + }
  527 + }
  528 +
  529 + /**
309 * 执行子任务 530 * 执行子任务
310 * @param int $task_id 任务ID 531 * @param int $task_id 任务ID
311 * @param int $subtask_id 子任务ID 532 * @param int $subtask_id 子任务ID
@@ -541,7 +762,7 @@ class Fastexport extends Backend @@ -541,7 +762,7 @@ class Fastexport extends Backend
541 $this->result(['file_name' => $row['file']], 1, '此任务已经打过包了!', 'json'); 762 $this->result(['file_name' => $row['file']], 1, '此任务已经打过包了!', 'json');
542 } 763 }
543 764
544 - is_dir($this->fastExportDir) OR mkdir($this->fastExportDir, 0755, true); 765 + is_dir($this->fastExportDir) or mkdir($this->fastExportDir, 0755, true);
545 766
546 foreach ($row['subtask'] as $key => $subtask) { 767 foreach ($row['subtask'] as $key => $subtask) {
547 if (!file_exists($this->save_dir . $task_id . DS . $subtask['id'] . '.xlsx')) { 768 if (!file_exists($this->save_dir . $task_id . DS . $subtask['id'] . '.xlsx')) {
@@ -624,7 +845,7 @@ class Fastexport extends Backend @@ -624,7 +845,7 @@ class Fastexport extends Backend
624 'smallint', 845 'smallint',
625 'mediumint', 846 'mediumint',
626 'integer', 847 'integer',
627 - 'bigint' 848 + 'bigint',
628 ]; 849 ];
629 850
630 $discerns = 0; 851 $discerns = 0;
@@ -651,7 +872,7 @@ class Fastexport extends Backend @@ -651,7 +872,7 @@ class Fastexport extends Backend
651 return [ 872 return [
652 'discerns' => $discerns, 873 'discerns' => $discerns,
653 'name' => $field, 874 'name' => $field,
654 - 'comment' => '' 875 + 'comment' => '',
655 ]; 876 ];
656 } 877 }
657 878
@@ -663,7 +884,7 @@ class Fastexport extends Backend @@ -663,7 +884,7 @@ class Fastexport extends Backend
663 return [ 884 return [
664 'discerns' => 5, 885 'discerns' => 5,
665 'name' => $field_name ? $field_name : $field, 886 'name' => $field_name ? $field_name : $field,
666 - 'comment' => $field_comment 887 + 'comment' => $field_comment,
667 ]; 888 ];
668 } else { 889 } else {
669 890
@@ -675,7 +896,7 @@ class Fastexport extends Backend @@ -675,7 +896,7 @@ class Fastexport extends Backend
675 return [ 896 return [
676 'discerns' => $discerns, 897 'discerns' => $discerns,
677 'name' => $comment ? $comment : $field, 898 'name' => $comment ? $comment : $field,
678 - 'comment' => isset($comment_temp) ? $comment_temp : '' 899 + 'comment' => isset($comment_temp) ? $comment_temp : '',
679 ]; 900 ];
680 } 901 }
681 } 902 }
@@ -898,7 +1119,7 @@ class Fastexport extends Backend @@ -898,7 +1119,7 @@ class Fastexport extends Backend
898 $row['where_field_arr_select'][] = $key; 1119 $row['where_field_arr_select'][] = $key;
899 $row['where_field_arr'][$key] = [ 1120 $row['where_field_arr'][$key] = [
900 'op' => $value, 1121 'op' => $value,
901 - 'condition' => $row['where_field']['condition'][$key] 1122 + 'condition' => $row['where_field']['condition'][$key],
902 ]; 1123 ];
903 } 1124 }
904 } 1125 }
@@ -6,19 +6,33 @@ @@ -6,19 +6,33 @@
6 <div class="tab-pane fade active in" id="one"> 6 <div class="tab-pane fade active in" id="one">
7 <div class="widget-body no-padding"> 7 <div class="widget-body no-padding">
8 <div id="toolbar" class="toolbar"> 8 <div id="toolbar" class="toolbar">
9 - <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>  
10 - <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('litestore/litestoregoods/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>  
11 - <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('litestore/litestoregoods/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>  
12 - <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('litestore/litestoregoods/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>  
13 - <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('litestore/litestoregoods/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a> 9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}"><i
  10 + class="fa fa-refresh"></i> </a>
  11 + <a href="javascript:;"
  12 + class="btn btn-success btn-add {:$auth->check('litestore/litestoregoods/add')?'':'hide'}"
  13 + title="{:__('Add')}"><i class="fa fa-plus"></i> {:__('Add')}</a>
  14 + <a href="javascript:;"
  15 + class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('litestore/litestoregoods/edit')?'':'hide'}"
  16 + title="{:__('Edit')}"><i class="fa fa-pencil"></i> {:__('Edit')}</a>
  17 + <a href="javascript:;"
  18 + class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('litestore/litestoregoods/del')?'':'hide'}"
  19 + title="{:__('Delete')}"><i class="fa fa-trash"></i> {:__('Delete')}</a>
  20 + <a href="javascript:;"
  21 + class="btn btn-danger btn-import {:$auth->check('litestore/litestoregoods/import')?'':'hide'}"
  22 + title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload"
  23 + data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i>
  24 + {:__('Import')}</a>
  25 + <a href="javascript:;"
  26 + class="btn btn-info btn-edit btn-sync"
  27 + title="{:__('批量导出')}"><i class="fa fa-download"></i>{:__('批量导出')}</a>
14 28
15 -<!-- <div class="dropdown btn-group {:$auth->check('litestore/litestoregoods/multi')?'':'hide'}">-->  
16 -<!-- <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->  
17 -<!-- <ul class="dropdown-menu text-left" role="menu">-->  
18 -<!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->  
19 -<!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->  
20 -<!-- </ul>-->  
21 -<!-- </div>--> 29 + <!-- <div class="dropdown btn-group {:$auth->check('litestore/litestoregoods/multi')?'':'hide'}">-->
  30 + <!-- <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>-->
  31 + <!-- <ul class="dropdown-menu text-left" role="menu">-->
  32 + <!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>-->
  33 + <!-- <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>-->
  34 + <!-- </ul>-->
  35 + <!-- </div>-->
22 </div> 36 </div>
23 <table id="table" class="table table-striped table-bordered table-hover table-nowrap" 37 <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
24 data-operate-edit="{:$auth->check('litestore/litestoregoods/edit')}" 38 data-operate-edit="{:$auth->check('litestore/litestoregoods/edit')}"
@@ -36,7 +36,7 @@ class Cart extends Api @@ -36,7 +36,7 @@ class Cart extends Api
36 $number = $this->request->post('number'); 36 $number = $this->request->post('number');
37 37
38 if (!is_numeric($sku_id) || !is_numeric($goods_id) || !is_numeric($number)) $this->error('参数不合法'); 38 if (!is_numeric($sku_id) || !is_numeric($goods_id) || !is_numeric($number)) $this->error('参数不合法');
39 - $category_id = (new \app\api\model\Goods())->where('id', $goods_id)->value('category_id'); 39 + $category_id = (new \app\api\model\Goods())->where('goods_id', $goods_id)->value('category_id');
40 40
41 $data = [ 41 $data = [
42 'user_id' => $this->auth->id, 42 'user_id' => $this->auth->id,
1 -define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoregoods'], function ($, undefined, Backend, Table, Form,Template,litestoregoods) { 1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'litestoregoods'], function ($, undefined, Backend, Table, Form, Template, litestoregoods) {
2 2
3 var Controller = { 3 var Controller = {
4 index: function () { 4 index: function () {
5 - $(".btn-add").data("area", ["1000px","800px"]); 5 + $(".btn-add").data("area", ["1000px", "800px"]);
6 // 初始化表格参数配置 6 // 初始化表格参数配置
7 Table.api.init({ 7 Table.api.init({
8 extend: { 8 extend: {
@@ -22,51 +22,120 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -22,51 +22,120 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
22 url: $.fn.bootstrapTable.defaults.extend.index_url, 22 url: $.fn.bootstrapTable.defaults.extend.index_url,
23 pk: 'goods_id', 23 pk: 'goods_id',
24 sortName: 'goods_sort', 24 sortName: 'goods_sort',
25 - search:false,  
26 - showExport:false, 25 + search: false,
  26 + showExport: false,
27 columns: [ 27 columns: [
28 [ 28 [
29 {checkbox: true}, 29 {checkbox: true},
30 {field: 'goods_id', title: __('Goods_id')}, 30 {field: 'goods_id', title: __('Goods_id')},
31 - {field: 'goods_name', title: __('Goods_name'),operate: 'LIKE'},  
32 - {field: 'keywords', title: __('Keywords'),operate: 'LIKE'},  
33 - {field: 'category.name', title: __('Category.name'),operate: false},  
34 - {field: 'activity.name', title: __('Activity.name'),operate: false},  
35 - {field: 'category_id', visible:false,title: __('Category_id')}, 31 + {field: 'goods_name', title: __('Goods_name'), operate: 'LIKE'},
  32 + {field: 'keywords', title: __('Keywords'), operate: 'LIKE'},
  33 + {field: 'category.name', title: __('Category.name'), operate: false},
  34 + {field: 'activity.name', title: __('Activity.name'), operate: false},
  35 + {field: 'category_id', visible: false, title: __('Category_id')},
36 {field: 'image', title: __('Image'), formatter: Table.api.formatter.image}, 36 {field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
37 {field: 'images', title: __('Images'), formatter: Table.api.formatter.images}, 37 {field: 'images', title: __('Images'), formatter: Table.api.formatter.images},
38 - {field: 'spec_type', title: __('Spec_type'), searchList: {"10":__('Spec_type 10'),"20":__('Spec_type 20')}, formatter: Table.api.formatter.normal},  
39 - {field: 'stock_num', title: __('库存'),operate: false}, 38 + {
  39 + field: 'spec_type',
  40 + title: __('Spec_type'),
  41 + searchList: {"10": __('Spec_type 10'), "20": __('Spec_type 20')},
  42 + formatter: Table.api.formatter.normal
  43 + },
  44 + {field: 'stock_num', title: __('库存'), operate: false},
40 // {field: 'deduct_stock_type', title: __('Deduct_stock_type'), searchList: {"10":__('Deduct_stock_type 10'),"20":__('Deduct_stock_type 20')}, formatter: Table.api.formatter.normal}, 45 // {field: 'deduct_stock_type', title: __('Deduct_stock_type'), searchList: {"10":__('Deduct_stock_type 10'),"20":__('Deduct_stock_type 20')}, formatter: Table.api.formatter.normal},
41 // {field: 'freight.name', title: __('Freight.name')}, 46 // {field: 'freight.name', title: __('Freight.name')},
42 // {field: 'sales_initial', title: __('Sales_initial')}, 47 // {field: 'sales_initial', title: __('Sales_initial')},
43 {field: 'sales_actual', title: __('Sales_actual')}, 48 {field: 'sales_actual', title: __('Sales_actual')},
44 // {field: 'goods_sort', title: __('Goods_sort')}, 49 // {field: 'goods_sort', title: __('Goods_sort')},
45 // {field: 'delivery_id', title: __('Delivery_id')}, 50 // {field: 'delivery_id', title: __('Delivery_id')},
46 - {field: 'goods_status', title: __('Goods_status'), searchList: {"10":__('Goods_status 10'),"20":__('Goods_status 20')}, formatter: Table.api.formatter.status},  
47 - {field: 'is_delete', title: __('Is_delete'), searchList: {"0":__('Is_delete 0'),"1":__('Is_delete 1')}, formatter: Table.api.formatter.normal},  
48 - {field: 'is_index', title: __('Is_index'), searchList: {"0":__('Is_index 0'),"1":__('Is_index 1')}, formatter: Table.api.formatter.normal},  
49 - {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},  
50 - {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},  
51 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} 51 + {
  52 + field: 'goods_status',
  53 + title: __('Goods_status'),
  54 + searchList: {"10": __('Goods_status 10'), "20": __('Goods_status 20')},
  55 + formatter: Table.api.formatter.status
  56 + },
  57 + {
  58 + field: 'is_delete',
  59 + title: __('Is_delete'),
  60 + searchList: {"0": __('Is_delete 0'), "1": __('Is_delete 1')},
  61 + formatter: Table.api.formatter.normal
  62 + },
  63 + {
  64 + field: 'is_index',
  65 + title: __('Is_index'),
  66 + searchList: {"0": __('Is_index 0'), "1": __('Is_index 1')},
  67 + formatter: Table.api.formatter.normal
  68 + },
  69 + {
  70 + field: 'createtime',
  71 + title: __('Createtime'),
  72 + operate: 'RANGE',
  73 + addclass: 'datetimerange',
  74 + formatter: Table.api.formatter.datetime
  75 + },
  76 + {
  77 + field: 'updatetime',
  78 + title: __('Updatetime'),
  79 + operate: 'RANGE',
  80 + addclass: 'datetimerange',
  81 + formatter: Table.api.formatter.datetime
  82 + },
  83 + {
  84 + field: 'operate',
  85 + title: __('Operate'),
  86 + table: table,
  87 + events: Table.api.events.operate,
  88 + formatter: Table.api.formatter.operate
  89 + }
52 ] 90 ]
53 ] 91 ]
54 }); 92 });
55 93
56 // 为表格绑定事件 94 // 为表格绑定事件
57 Table.api.bindevent(table); 95 Table.api.bindevent(table);
58 - table.on('load-success.bs.table',function(data){  
59 - $(".btn-editone").data("area", ["1000px","800px"]); 96 +
  97 + $('.btn-sync').click(function () {
  98 + var index = Layer.load();
  99 + $.ajax({
  100 + // type: "POST",
  101 + url: $.fn.bootstrapTable.defaults.extend.performTask,
  102 + confirm: '确认开始执行任务吗?(数据导出属高IO操作,若本任务数据量超过2万,请择服务器相对闲时执行!)',
  103 + refresh: true,
  104 + // url: "fastexport/zdyTask",
  105 + datatype: "json",
  106 + success: function (data, ret) {
  107 + if (ret.code == 1) {
  108 + if (data.direct_export) {
  109 + Fast.api.msg('任务已开始,请稍等片刻...')
  110 + window.location = 'fastexport/zdyTask';
  111 + } else {
  112 + window.open("fastexport/taskControl/task_id/" + data.id, "_blank");
  113 + }
  114 + } else {
  115 + Layer.alert(ret.msg);
  116 + }
  117 +
  118 + return false;
  119 + },
  120 + error: function (data, ret) {
  121 + Layer.alert(ret.msg);
  122 + return false;
  123 + }
  124 + });
  125 + });
  126 +
  127 + table.on('load-success.bs.table', function (data) {
  128 + $(".btn-editone").data("area", ["1000px", "800px"]);
60 }); 129 });
61 130
62 }, 131 },
63 add: function () { 132 add: function () {
64 - Form.api.bindevent($("form[role=form]"), function(data, ret){ 133 + Form.api.bindevent($("form[role=form]"), function (data, ret) {
65 Fast.api.close(data); 134 Fast.api.close(data);
66 Toastr.success("商品提交成功"); 135 Toastr.success("商品提交成功");
67 - }, function(data, ret){ 136 + }, function (data, ret) {
68 Toastr.success("商品提交失败"); 137 Toastr.success("商品提交失败");
69 - }, function(success, error){ 138 + }, function (success, error) {
70 //注意如果我们需要阻止表单,可以在此使用return false;即可 139 //注意如果我们需要阻止表单,可以在此使用return false;即可
71 //如果我们处理完成需要再次提交表单则可以使用submit提交,如下 140 //如果我们处理完成需要再次提交表单则可以使用submit提交,如下
72 console.log(this); 141 console.log(this);
@@ -104,7 +173,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -104,7 +173,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
104 if (token) { 173 if (token) {
105 $("input[name='__token__']", form).val(token); 174 $("input[name='__token__']", form).val(token);
106 } 175 }
107 - if(xhr.responseJSON.code == 1){ 176 + if (xhr.responseJSON.code == 1) {
108 //关闭弹窗 177 //关闭弹窗
109 var index = parent.Layer.getFrameIndex(window.name); 178 var index = parent.Layer.getFrameIndex(window.name);
110 var callback = parent.$("#layui-layer" + index).data("callback"); 179 var callback = parent.$("#layui-layer" + index).data("callback");
@@ -134,7 +203,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -134,7 +203,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
134 // 注册商品多规格组件 203 // 注册商品多规格组件
135 var specMany = new GoodsSpec({ 204 var specMany = new GoodsSpec({
136 container: '.goods-spec-many', 205 container: '.goods-spec-many',
137 - OutForm:Form 206 + OutForm: Form
138 }); 207 });
139 208
140 // 切换单/多规格 209 // 切换单/多规格
@@ -153,12 +222,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -153,12 +222,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
153 edit: function () { 222 edit: function () {
154 //Controller.api.bindevent(); 223 //Controller.api.bindevent();
155 224
156 - Form.api.bindevent($("form[role=form]"), function(data, ret){ 225 + Form.api.bindevent($("form[role=form]"), function (data, ret) {
157 //Fast.api.close(data); 226 //Fast.api.close(data);
158 Toastr.success("商品提交成功"); 227 Toastr.success("商品提交成功");
159 - }, function(data, ret){ 228 + }, function (data, ret) {
160 Toastr.success("商品提交失败"); 229 Toastr.success("商品提交失败");
161 - }, function(success, error){ 230 + }, function (success, error) {
162 //注意如果我们需要阻止表单,可以在此使用return false;即可 231 //注意如果我们需要阻止表单,可以在此使用return false;即可
163 //如果我们处理完成需要再次提交表单则可以使用submit提交,如下 232 //如果我们处理完成需要再次提交表单则可以使用submit提交,如下
164 console.log(this); 233 console.log(this);
@@ -196,7 +265,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -196,7 +265,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
196 if (token) { 265 if (token) {
197 $("input[name='__token__']", form).val(token); 266 $("input[name='__token__']", form).val(token);
198 } 267 }
199 - if(xhr.responseJSON.code == 1){ 268 + if (xhr.responseJSON.code == 1) {
200 //关闭弹窗 269 //关闭弹窗
201 var index = parent.Layer.getFrameIndex(window.name); 270 var index = parent.Layer.getFrameIndex(window.name);
202 var callback = parent.$("#layui-layer" + index).data("callback"); 271 var callback = parent.$("#layui-layer" + index).data("callback");
@@ -225,7 +294,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg @@ -225,7 +294,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','litestoreg
225 // 注册商品多规格组件 294 // 注册商品多规格组件
226 var specMany = new GoodsSpec({ 295 var specMany = new GoodsSpec({
227 container: '.goods-spec-many', 296 container: '.goods-spec-many',
228 - OutForm:Form 297 + OutForm: Form
229 }, from_specData); 298 }, from_specData);
230 299
231 // 切换单/多规格 300 // 切换单/多规格