添加JS导出数据处理

This commit is contained in:
Anyon 2020-09-11 18:50:05 +08:00
parent 3ef091db3e
commit e4f330d867
9 changed files with 269 additions and 272 deletions

View File

@ -31,48 +31,36 @@ class ShopOrder extends Controller
public function index() public function index()
{ {
$this->title = '订单数据管理'; $this->title = '订单数据管理';
// 状态数据统计 // 状态数据统计
$this->totals = [0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 'all' => 0]; $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 'ta' => 0];
$this->app->db->name($this->table)->fieldRaw('status,count(1) total')->group('status')->select()->map(function ($vo) { $this->app->db->name($this->table)->fieldRaw('status,count(1) total')->group('status')->select()->map(function ($vo) {
$this->totals[$vo['status']] = $vo['total']; $this->total["t{$vo['status']}"] = $vo['total'];
$this->totals["all"] += $vo['total']; $this->total["ta"] += $vo['total'];
}); });
// 订单列表查询 // 订单列表查询
$query = $this->_query($this->table)->dateBetween('create_at,payment_datetime')->equal('status,payment_status'); $query = $this->_query($this->table);
$query->like('order_no,express_send_no,express_name,express_phone,express_province,express_city,express_area,express_address'); $query->equal('status,payment_type,payment_status');
$query->dateBetween('create_at,pay_datetime')->equal('status,pay_state'); $query->dateBetween('create_at,payment_datetime,cancel_datetime,truck_datetime,truck_send_datetime');
$query->like('order_no,truck_name,truck_phone,truck_province|truck_area|truck_address#address,truck_send_no,truck_send_name');
// 会员搜索查询 // 会员搜索查询
$db = $this->_query('DataMember')->like('phone#member_phone,nickname#member_nickname')->db(); $db = $this->_query('DataMember')->like('phone#member_phone,nickname#member_nickname')->db();
if ($db->getOptions('where')) $query->whereRaw("mid in {$db->fieldRaw('id')->buildSql()}"); if ($db->getOptions('where')) $query->whereRaw("mid in {$db->fieldRaw('id')->buildSql()}");
// 推荐人搜索查询 // 推荐人搜索查询
$db = $this->_query('DataMember')->like('phone#agent_phone,nickname#agent_nickname')->db(); $db = $this->_query('DataMember')->like('phone#from_phone,nickname#from_nickname')->db();
if ($db->getOptions('where')) $query->whereRaw("from in {$db->fieldRaw('id')->buildSql()}"); if ($db->getOptions('where')) $query->whereRaw("from in {$db->fieldRaw('id')->buildSql()}");
// 列表选项卡 // 列表选项卡
if (is_numeric($this->type = input('type', 'all'))) { if (is_numeric($this->type = trim(input('type', 'ta'), 't'))) {
$query->equal('status#type'); $query->where(['status' => $this->type]);
} }
// 分页排序处理 // 分页排序处理
if (defined('_ACTION_') && _ACTION_ === 'export') { if (input('output') === 'json') {
return $query; $result = $query->order('id desc')->page(true, false);
$this->success('获取数据列表成功', $result);
} else { } else {
$query->order('id desc')->page(); $query->order('id desc')->page();
} }
} }
/**
* 导出订单数据
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function export()
{
define('_ACTION_', 'export');
$options = ['serialize' => serialize($this->index()->db()->getOptions())];
$this->_queue('导出订单数据', OrderQueue::class, 0, $options, 0);
}
/** /**
* 订单列表处理 * 订单列表处理
* @param array $data * @param array $data
@ -82,15 +70,19 @@ class ShopOrder extends Controller
*/ */
protected function _index_page_filter(array &$data) protected function _index_page_filter(array &$data)
{ {
$mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from_mid'))); $mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from')));
$members = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id'); $mems = $this->app->db->name('DataMember')->whereIn('id', $mids)->column('*', 'id');
$orderNos = array_unique(array_column($data, 'order_no')); $query = $this->app->db->name('ShopOrderItem')->where(['status' => 1, 'deleted' => 0]);
$goodsList = $this->app->db->name('ShopOrderItem')->whereIn('order_no', $orderNos)->select()->toArray(); $items = $query->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select()->toArray();
foreach ($data as &$vo) { foreach ($data as &$vo) {
[$vo['member'], $vo['from_member'], $vo['list']] = [[], [], []]; $vo['items'] = [];
$vo['member'] = isset($members[$vo['mid']]) ? $members[$vo['mid']] : []; $vo['member'] = $mems[$vo['mid']] ?? [];
$vo['from_member'] = isset($members[$vo['from_mid']]) ? $members[$vo['from_mid']] : []; $vo['fromer'] = $mems[$vo['from']] ?? [];
foreach ($goodsList as $goods) if ($goods['order_no'] === $vo['order_no']) $vo['list'][] = $goods; foreach ($items as $item) {
if ($vo['order_no'] === $item['order_no']) {
$vo['items'][] = $item;
}
}
} }
} }
@ -101,35 +93,14 @@ class ShopOrder extends Controller
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function express() public function truck()
{ {
if ($this->request->isGet()) { if ($this->request->isGet()) {
$where = ['is_deleted' => '0', 'status' => '1']; $map = ['deleted' => 0, 'status' => 1];
$query = $this->app->db->name('ShopExpressCompany')->where($where); $query = $this->app->db->name('ShopTruckCompany')->where($map);
$this->expressList = $query->order('sort desc,id desc')->select()->toArray(); $this->items = $query->order('sort desc,id desc')->select()->toArray();
}
$this->_form($this->table);
}
/**
* 快递追踪查询
* @auth true
*/
public function expressQuery()
{
try {
$data = $this->_vali([
'code.require' => '快递公司不能为空!',
'number.require' => '配送单号不能为空!',
]);
$this->result = OpenCuciService::instance()->track($data['code'], $data['number']);
if (empty($this->result['code'])) $this->error($this->result['info']);
$this->fetch();
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} }
$this->_form($this->table, '', 'order_no');
} }
/** /**
@ -139,18 +110,40 @@ class ShopOrder extends Controller
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
protected function _express_form_filter(&$vo) protected function _truck_form_filter(&$vo)
{ {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$order = $this->app->db->name($this->table)->where(['id' => $vo['id']])->find(); $map = ['order_no' => $vo['order_no']];
$order = $this->app->db->name($this->table)->where($map)->find();
if (empty($order)) $this->error('订单查询异常,请稍候再试!'); if (empty($order)) $this->error('订单查询异常,请稍候再试!');
$map = ['code_1|code_2|code_3' => $vo['express_company_code']]; // 配送快递公司信息填写
$express = $this->app->db->name('ShopExpressCompany')->where($map)->find(); $map = ['code_1|code_2|code_3' => $vo['truck_send_code']];
if (empty($express)) $this->error('配送快递公司异常,请重新选择快递公司!'); $company = $this->app->db->name('ShopTruckCompany')->where($map)->find();
$vo['express_company_title'] = $express['title']; if (empty($company)) $this->error('配送快递公司异常,请重新选择快递公司!');
$vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at']; $vo['status'] = 4;
$vo['express_state'] = '1'; $vo['truck_send_name'] = $company['name'];
$vo['status'] = '4'; $vo['truck_send_datetime'] = $order['truck_send_datetime'] ?: date('Y-m-d H:i:s');
}
}
/**
* 快递追踪查询
* @auth true
*/
public function truckQuery()
{
try {
$data = $this->_vali([
'code.require' => '快递公司不能为空!',
'number.require' => '配送单号不能为空!',
]);
$this->result = OrderService::instance()->tracktruck($data['code'], $data['number']);
if (empty($this->result['code'])) $this->error($this->result['info']);
$this->fetch();
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} }
} }
@ -168,16 +161,16 @@ class ShopOrder extends Controller
if (empty($order)) $this->error('订单查询异常'); if (empty($order)) $this->error('订单查询异常');
if (intval($order['status']) !== 3) $this->error('该订单不能发货!'); if (intval($order['status']) !== 3) $this->error('该订单不能发货!');
[$rules, $data] = [[], ['type' => 3, 'refund_content' => '后台操作取消订单并申请退款', 'refund_images' => '']]; [$rules, $data] = [[], ['type' => 3, 'refund_content' => '后台操作取消订单并申请退款', 'refund_images' => '']];
foreach ($this->app->db->name("{$this->table}List")->where($map)->select()->toArray() as $item) { foreach ($this->app->db->name("{$this->table}Item")->where($map)->select()->toArray() as $item) {
$rules[] = ['goods_id' => $item['goods_id'], 'goods_spec' => $item['goods_spec'], 'refund_number' => $item['number_goods']]; $rules[] = ['goods_code' => $item['goods_code'], 'goods_spec' => $item['goods_spec'], 'refund_number' => $item['stock_sales']];
} }
try { try {
if (OrderService::instance()->refund($order['order_no'], $data, $rules)) { if (OrderService::instance()->refund($order['order_no'], $data, $rules)) {
$this->app->db->name($this->table)->where($map)->update([ $this->app->db->name($this->table)->where($map)->update([
'status' => 0, 'status' => 0,
'cancel_state' => 1, 'cancel_status' => 1,
'cancel_datetime' => date('Y-m-d H:i:s'), 'cancel_remark' => '后台取消并创建退款申请',
'cancel_description' => '后台操作取消并创建退款申请', 'cancel_datetime' => date('Y-m-d H:i:s'),
]); ]);
$this->success('取消订单并创建退款申请成功!'); $this->success('取消订单并创建退款申请成功!');
} }

View File

@ -15,7 +15,7 @@ class ShopOrderSend extends Controller
* 绑定数据表 * 绑定数据表
* @var string * @var string
*/ */
private $table = 'ShopOrderSend'; private $table = 'ShopOrder';
/** /**
* 订单发货管理 * 订单发货管理

View File

@ -4,6 +4,7 @@ namespace app\data\service;
use think\admin\extend\CodeExtend; use think\admin\extend\CodeExtend;
use think\admin\Service; use think\admin\Service;
use think\admin\service\InterfaceService;
/** /**
* 订单数据服务 * 订单数据服务
@ -49,62 +50,19 @@ class OrderService extends Service
} }
/** /**
* 创建申请售后单 * 楚才开放平台快递查询
* @param string $orderNo * @param string $code 快递公司编号
* @param array $data [type,refund_content,refund_images] * @param string $number 快递配送单号
* @param array $rules [[goods_id,goods_spec,refund_number]] * @return array
* @return boolean * @throws \think\admin\Exception
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
public function refund(string $orderNo, array $data, array $rules = []) public function trackExpress($code, $number)
{ {
[$all, $map] = [[], ['order_no' => $orderNo]]; $service = InterfaceService::instance();
$order = $this->app->db->name('StoreOrder')->where($map)->find(); // 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
$olist = $this->app->db->name('StoreOrderList')->where($map)->select()->toArray(); $service->setAuth('6998081316132228', '193fc1d9a2aac78475bc8dbeb9a5feb1');
$rlist = $this->app->db->name('StoreOrderRefund')->where($map)->whereIn('refund_status', [1, 2, 3])->select()->toArray(); return $service->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
$discountRate = $order['pay_price'] / $order['price_discount']; 'type' => 'free', 'express' => $code, 'number' => $number,
if (count($olist) > 0) foreach ($olist as &$vo) { ]);
$vo['discount_unit_amount'] = $vo['discount_amount'] / $vo['number_goods'] * $discountRate;
if (count($rlist) > 0) foreach ($rlist as $rule) {
if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) {
$vo['number_goods'] -= $rule['refund_number'];
}
}
}
// dump($olist);
$data['group_no'] = CodeExtend::uniqidDate(18, "G");
if (count($olist) > 0 && count($rules) > 0) foreach ($olist as &$vo) {
foreach ($rules as $rule) if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) {
if ($vo['number_goods'] - $rule['refund_number'] < 0) {
throw new \think\Exception("订单商品数量异常!");
}
$data['mid'] = $vo['mid'];
$data['order_no'] = $orderNo;
$data['goods_id'] = $vo['goods_id'];
$data['goods_sku'] = $vo['goods_sku'];
$data['goods_title'] = $vo['goods_title'];
$data['goods_logo'] = $vo['goods_logo'];
$data['goods_spec'] = $vo['goods_spec'];
$data['number_goods'] = $vo['number_goods'];
$data['goods_price_total'] = $vo['goods_price_total'];
$data['goods_price_market'] = $vo['goods_price_market'];
$data['refund_no'] = CodeExtend::uniqidDate(18, 'R');
$data['refund_rate'] = $discountRate;
$data['refund_number'] = $rule['refund_number'];
$data['refund_amount'] = $rule['refund_number'] * $vo['discount_unit_amount'];
$data['refund_status'] = 1;
$data['discount_amount'] = $vo['discount_amount'];
// 支付金额处理
if ($order['pay_price'] < $data['refund_amount']) {
$data['refund_amount'] = $order['pay_price'];
}
$all[] = $data;
}
}
if (empty($all)) throw new \think\Exception("没有需要处理的商品!");
return $this->app->db->name('StoreOrderRefund')->strict(false)->insertAll($all) !== false;
} }
} }

View File

@ -6,16 +6,16 @@
<label class="layui-col-xs6 relative block"> <label class="layui-col-xs6 relative block">
<span class="color-green font-w7 label-required-prev">收货人姓名</span> <span class="color-green font-w7 label-required-prev">收货人姓名</span>
<span class="color-desc margin-left-5">Consignee Name</span> <span class="color-desc margin-left-5">Consignee Name</span>
<input class="layui-input" required placeholder="请输入收货姓名" name="express_name" value="{$vo.express_name|default=''}"> <input class="layui-input" required placeholder="请输入收货姓名" name="truck_name" value="{$vo.truck_name|default=''}">
</label> </label>
<label class="layui-col-xs6 relative block"> <label class="layui-col-xs6 relative block">
<span class="color-green font-w7 label-required-prev">收货人手机</span> <span class="color-green font-w7 label-required-prev">收货人手机</span>
<span class="color-desc margin-left-5">Consignee's mobile phone</span> <span class="color-desc margin-left-5">Consignee's mobile phone</span>
<input class="layui-input" required placeholder="请输入收货人手机" name="express_phone" value="{$vo.express_phone|default=''}"> <input class="layui-input" required placeholder="请输入收货人手机" name="truck_phone" value="{$vo.truck_phone|default=''}">
</label> </label>
<div class="layui-col-xs12 relative block"> <div class="layui-col-xs12 relative block">
<span class="color-green font-w7 label-required-prev">收货所在区域</span> <span class="color-green font-w7 label-required-prev">收货所在区域</span>
<span class="color-desc margin-left-5"> {$vo.express_province|default='--'} {$vo.express_city|default=''} {$vo.express_area|default=''} </span> <span class="color-desc margin-left-5">原区域: {$vo.truck_province|default='--'} {$vo.truck_city|default=''} {$vo.truck_area|default=''} </span>
<div class="layui-row layui-col-space10"> <div class="layui-row layui-col-space10">
<label class="layui-col-xs4"><select class="layui-select block full-width" lay-ignore name="form_province"></select></label> <label class="layui-col-xs4"><select class="layui-select block full-width" lay-ignore name="form_province"></select></label>
<label class="layui-col-xs4"><select class="layui-select block full-width" lay-ignore name="form_city"></select></label> <label class="layui-col-xs4"><select class="layui-select block full-width" lay-ignore name="form_city"></select></label>
@ -24,58 +24,54 @@
</div> </div>
<label class="layui-col-xs12 relative block"> <label class="layui-col-xs12 relative block">
<span class="color-green font-w7 label-required-prev">收货详细地址</span> <span class="color-green font-w7 label-required-prev">收货详细地址</span>
<span class="color-desc margin-left-5"> {$vo.express_address|default=""} )</span> <span class="color-desc margin-left-5">原地址: {$vo.truck_address|default=""} )</span>
<input name="express_address" required value='{$vo.express_address|default=""}' placeholder="请输入收货地址" class="layui-input"> <input name="truck_address" required value='{$vo.truck_address|default=""}' placeholder="请输入收货地址" class="layui-input">
</label> </label>
</div> </div>
</fieldset> </fieldset>
<fieldset class="margin-top-20"> <fieldset class="margin-top-20">
<legend><span class="layui-badge layui-bg-cyan">快递信息</span> <a class="margin-left-10 layui-badge layui-bg-blue" data-express-query>快递跟踪</a></legend> <legend><span class="layui-badge layui-bg-cyan">快递信息</span> <a class="margin-left-10 layui-badge layui-bg-blue" data-express-query>快递跟踪</a></legend>
<label class="layui-form-item relative block"> <label class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">快递配送公司</span> <span class="color-green font-w7 label-required-prev">快递配送公司</span>
<span class="color-desc margin-left-5">Express delivery company</span> <span class="color-desc margin-left-5">Express delivery company</span>
<select data-express-code class="layui-select" name="express_company_code" lay-search> <select data-truck-code class="layui-select" name="truck_send_code" lay-search>
{foreach $expressList as $express} {foreach $items as $item}
{if $vo.express_company_code eq $express.code_1} {if $vo.truck_send_code eq $item.code_1}
<option selected value="{$express.code_1}">{$express.title} ( {$express.code_1} )</option> <option selected value="{$item.code_1}">{$item.name} ( {$item.code_1} )</option>
{else} {else}
<option value="{$express.code_1}">{$express.title} ( {$express.code_1} )</option> <option value="{$item.code_1}">{$item.name} ( {$item.code_1} )</option>
{/if} {/if}{/foreach}
{/foreach}
</select> </select>
</label> </label>
<label class="layui-form-item relative block"> <label class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">快递配送单号</span> <span class="color-green font-w7 label-required-prev">快递配送单号</span>
<span class="color-desc margin-left-5">Express delivery number</span> <span class="color-desc margin-left-5">Express delivery number</span>
<input data-express-number name="express_send_no" required value='{$vo.express_send_no|default=""}' placeholder="请输入快递配送单号" class="layui-input"> <input data-truck-number name="truck_send_no" required value='{$vo.truck_send_no|default=""}' placeholder="请输入快递配送单号" class="layui-input">
</label> </label>
<label class="layui-form-item relative block"> <label class="layui-form-item relative block">
<span class="color-green font-w7 label-required-prev">快递配送描述</span> <span class="color-green font-w7">快递配送描述</span>
<span class="color-desc margin-left-5">Express delivery description</span> <span class="color-desc margin-left-5">Express delivery description</span>
<textarea placeholder="请输入快递配送描述" class="layui-textarea" name="express_description">{$vo.express_description|default=""}</textarea> <textarea placeholder="请输入快递配送描述" class="layui-textarea" name="truck_send_remark">{$vo.truck_send_remark|default=""}</textarea>
</label> </label>
</fieldset> </fieldset>
</div> </div>
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
{notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
{notempty name='vo.order_no'}<input type='hidden' value='{$vo.order_no}' name='order_no'>{/notempty} {notempty name='vo.order_no'}<input type='hidden' value='{$vo.order_no}' name='order_no'>{/notempty}
<div class="layui-form-item text-center"> <div class="layui-form-item text-center">
<button class="layui-btn" type='submit'>保存数据</button> <button class="layui-btn" type='submit'>保存数据</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button> <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
</div> </div>
<script>
require(['pcasunzips'], function () {
new PCAS("form_province", "form_city", "form_area", '{$vo.express_province|default=""}', '{$vo.express_city|default=""}', '{$vo.express_area|default=""}');
window.form.render();
});
$('[data-express-query]').on('click', function () {
this.code = $('[data-express-code]').val();
this.number = $('[data-express-number]').val();
$.form.modal('{:url("expressQuery")}', {code: this.code, number: this.number})
});
</script>
</form> </form>
<script>
require(['pcasunzips'], function () {
(function (province, city, area) {
new PCAS("form_province", "form_city", "form_area", province, city, area);
window.form.render();
})('{$vo.truck_province|default=""}', '{$vo.truck_city|default=""}', '{$vo.truck_area|default=""}');
});
$('[data-express-query]').on('click', function () {
(function (code, number) {
$.form.modal('{:url("expressQuery")}', {code: code, number: number}, '快递追踪查询')
})($('[data-truck-code]').val(), $('[data-truck-number]').val());
});
</script>

View File

@ -3,8 +3,8 @@
{block name="content"} {block name="content"}
<div class="layui-tab layui-tab-card"> <div class="layui-tab layui-tab-card">
<ul class="layui-tab-title notselect"> <ul class="layui-tab-title notselect">
{foreach ['all'=>'全部订单','2'=>'待支付的订单','3'=>'待发货的订单','4'=>'待收货的订单','5'=>'已完成的订单','0'=>'已取消的订单'] as $k=>$v} {foreach ['ta'=>'全部订单','t2'=>'待支付的订单','t3'=>'待发货的订单','t4'=>'待收货的订单','t5'=>'已完成的订单','t0'=>'已取消的订单'] as $k=>$v}
{if isset($type) and $type eq $k.''} {if isset($type) and 't'.$type eq $k}
<li data-open="{:url('index')}?type={$k}" class="layui-this">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li> <li data-open="{:url('index')}?type={$k}" class="layui-this">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li>
{else} {else}
<li data-open="{:url('index')}?type={$k}">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li> <li data-open="{:url('index')}?type={$k}">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li>
@ -34,10 +34,10 @@
</td> </td>
<td class="nowrap relative"> <td class="nowrap relative">
<div> <div>
<img data-tips-image style="width:35px;height:35px" src="{$vo.from_member.headimg|default='__ROOT__/static/theme/img/headimg.png'}" class="margin-right-5" alt="img"> <img data-tips-image style="width:35px;height:35px" src="{$vo.fromer.headimg|default='__ROOT__/static/theme/img/headimg.png'}" class="margin-right-5" alt="img">
<div class="inline-block text-middle sub-span-blue"> <div class="inline-block text-middle sub-span-blue">
推荐会员:{$vo.from_member.nickname|default='--'}<br> 推荐会员:{$vo.fromer.nickname|default='--'}<br>
推荐手机:<span>{$vo.from_member.phone|default='--'}</span>{notempty name='vo.from_member.vip_level'} [ <b class="color-red">VIP{$vo.from_member.vip_level}</b> ] <b class="color-red">{$vo.from_member.vip_title}</b>{/notempty}<br> 推荐手机:<span>{$vo.fromer.phone|default='--'}</span>{notempty name='vo.fromer.vip_level'} [ <b class="color-red">VIP{$vo.fromer.vip_level}</b> ] <b class="color-red">{$vo.fromer.vip_title}</b>{/notempty}<br>
</div> </div>
</div> </div>
<div> <div>
@ -50,7 +50,7 @@
</td> </td>
<td class='nowrap'> <td class='nowrap'>
<div class="inline-block margin-right-5 think-badge-middle notselect padding-left-5"> <div class="inline-block margin-right-5 think-badge-middle notselect padding-left-5">
{eq name='vo.status' value='0'}<span class="layui-badge layui-bg-gray" data-tips-text="{$vo.cancel_description}">已取消</span>{/eq} {eq name='vo.status' value='0'}<span class="layui-badge layui-bg-gray" data-tips-text="{$vo.cancel_remark}">已取消</span>{/eq}
{eq name='vo.status' value='1'}<span class="layui-badge layui-bg-red">预订单</span>{/eq} {eq name='vo.status' value='1'}<span class="layui-badge layui-bg-red">预订单</span>{/eq}
{eq name='vo.status' value='2'}<span class="layui-badge layui-bg-orange">待付款</span>{/eq} {eq name='vo.status' value='2'}<span class="layui-badge layui-bg-orange">待付款</span>{/eq}
{eq name='vo.status' value='3'}<span class="layui-badge layui-bg-black">待发货</span>{/eq} {eq name='vo.status' value='3'}<span class="layui-badge layui-bg-black">待发货</span>{/eq}
@ -59,52 +59,40 @@
</div> </div>
<div class="inline-block text-middle"> <div class="inline-block text-middle">
订单单号:<span class="color-blue">{$vo.order_no|default=''}</span><br> 订单单号:<span class="color-blue">{$vo.order_no|default=''}</span><br>
订单金额:<b class="color-blue">{$vo.price_total+0}</b> <span class="color-blue">{if $vo.price_express>0}(含{$vo.price_express+0}元){else}(包邮){/if}</span>已支付 <strong class="color-blue">{$vo.pay_price+0}</strong> <br> 订单金额:<b class="color-blue">{$vo.amount_total+0}</b> <span class="color-blue">{if $vo.amount_express>0}(含{$vo.amount_express+0}元){else}(包邮){/if}</span>已支付 <strong class="color-blue">{$vo.payment_amount+0}</strong> <br>
下单时间:{$vo.create_at|format_datetime}<br> 下单时间:{$vo.create_at|format_datetime}<br>
支付时间:{$vo.pay_datetime|format_datetime}{if $vo.pay_datetime}<span class="color-blue"> ({$vo.pay_type|default='-'})</span>{/if}<br> 支付时间:{$vo.payment_datetime|format_datetime}{if $vo.payment_datetime}<span class="color-blue"> ({$vo.pay_type|default='-'})</span>{/if}<br>
</div> </div>
</td> </td>
<td class="nowrap"> <td class="nowrap">
收货信息:{$vo.express_name|default='--'}<span class="margin-left-5 color-blue">{$vo.express_phone}</span><br> 收货信息:{$vo.truck_name|default='--'}<span class="margin-left-5 color-blue">{$vo.truck_phone}</span><br>
收货地址:{$vo.express_province|default='--'}{$vo.express_city}{$vo.express_area}{$vo.express_address}<br> 收货地址:{$vo.truck_province|default='--'}{$vo.truck_city}{$vo.truck_area}{$vo.truck_address}<br>
发货状态:{eq name='vo.express_state' value='0'} 发货状态:{if empty($vo.truck_send_code)}
<span class="layui-badge layui-bg-black">未发货</span> <span class="layui-badge layui-bg-black">未发货</span>
{else} {else}
<span class="layui-badge layui-bg-blue">{$vo.express_company_title|default='--'}</span> <span class="layui-badge layui-bg-blue">{$vo.truck_send_name|default='--'}</span>
<a data-title="{$vo.express_company_title}{$vo.express_send_no}" data-tips-text="快递追踪查询" <a data-title="{$vo.truck_send_name}{$vo.truck_send_no}" data-tips-text="快递追踪查询"
data-modal="{:url('expressQuery')}?code={$vo.express_company_code}&number={$vo.express_send_no}" data-modal="{:url('expressQuery')}?code={$vo.truck_send_code}&number={$vo.truck_send_no}"
class="layui-badge layui-bg-gray margin-left-5">{$vo.express_send_no|default='--'}</a> class="layui-badge layui-bg-orange margin-left-5">{$vo.truck_send_no|default='--'}</a>
{/eq}
{if $vo.status eq 3}
<a class=" margin-left-5" data-title="填写订单信息" data-modal="{:url('express')}?id={$vo.id}">填写发货</a>
<!--{if auth('store/order/pushJushuitan') && isset($jushuitanType) and $jushuitanType > 0}-->
<a class=" margin-left-5" data-confirm="确认要使用仓库发货吗?" data-load="{:url('pushJushuitan')}?order_no={$vo.order_no}">提交仓库</a>
<!--{/if}-->
<!--{if auth('cancel')}-->
<a class=" margin-left-5" data-confirm="确认要取消并创建退款申请吗?" data-load="{:url('cancel')}?order_no={$vo.order_no}">取消并退款</a>
<!--{/if}-->
{elseif $vo.status eq 4}
<a class=" margin-left-5" data-title="修改发货信息" data-modal="{:url('express')}?id={$vo.id}">修改发货</a>
{/if} {/if}
{if $vo.status eq 3}
<a class="margin-left-5" data-title="填写订单信息" data-modal="{:url('express')}?order_no={$vo.order_no}">填写发货</a>
{elseif $vo.status eq 4}
<a class="margin-left-5" data-title="修改发货信息" data-modal="{:url('express')}?order_no={$vo.order_no}">修改发货</a>
{/if}
<!--{if auth('cancel') and in_array($vo.status, [1,2])}-->
<a class="margin-left-5" data-confirm="确认要取消订单吗?" data-load="{:url('cancel')}?order_no={$vo.order_no}">取消订单</a>
<!--{/if}-->
<br> <br>
发货时间:{$vo.express_send_at|format_datetime}<br> 发货时间:{$vo.truck_send_datetime|format_datetime}<br>
</td> </td>
<td class="nowrap"> <td class="nowrap">
{foreach $vo.list as $g} {foreach $vo.items as $item}
<div> <div>
{if $g.vip_mod > 0 and $g.vip_level > $g.discount_vip} <b class="color-blue">{$item.stock_sales|default=0}</b>
[ <b class="color-red">VIP{$g.discount_vip}</b> <b class="layui-icon font-s10 color-blue">&#xe65b;</b> <b class="color-red">VIP{$g.vip_level}</b> ]
{else}
[ <b class="color-blue">VIP{$g.discount_vip}</b> ]
{/if}
{if $g.discount_rate<100.00}
<b class="color-blue">{$g.discount_rate+0}%折扣</b>
<b class="color-red">x</b> <b class="color-red">x</b>
{/if} <b class="color-blue">{$item.price_market+0} </b>
<b class="color-blue">{$g.number_goods|default=0}</b> {$item.goods_name|default=''} <span class="color-green">( {$item.goods_spec|think_show_goods_spec})</span>
<b class="color-red">x</b>
<b class="color-blue">{$g.goods_price_market+0} </b>
{$g.goods_title|default=''} <span class="color-green">( {$g.goods_spec|show_goods_spec})</span>
</div> </div>
{/foreach} {/foreach}
</td> </td>

View File

@ -16,13 +16,13 @@
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">推荐手机</label> <label class="layui-form-label">推荐手机</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="agent_phone" value="{:input('agent_phone')}" placeholder="请输入会员手机" class="layui-input"> <input name="from_phone" value="{:input('from_phone')}" placeholder="请输入会员手机" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">推荐昵称</label> <label class="layui-form-label">推荐昵称</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="agent_nickname" value="{:input('agent_nickname')}" placeholder="请输入会员昵称" class="layui-input"> <input name="from_nickname" value="{:input('from_nickname')}" placeholder="请输入会员昵称" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
@ -34,7 +34,7 @@
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">发货单号</label> <label class="layui-form-label">发货单号</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="express_send_no" value="{:input('express_send_no')}" placeholder="请输入发货单号" class="layui-input"> <input name="truck_send_no" value="{:input('truck_send_no')}" placeholder="请输入发货单号" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
@ -46,17 +46,16 @@
<option selected value="{$k}">{$v}</option> <option selected value="{$k}">{$v}</option>
{else} {else}
<option value="{$k}">{$v}</option> <option value="{$k}">{$v}</option>
{/if} {/if}{/foreach}
{/foreach}
</select> </select>
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">付款状态</label> <label class="layui-form-label">付款状态</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<select class="layui-select" name="pay_state"> <select class="layui-select" name="payment_status">
{foreach [''=>'- 全部订单 -','0'=>'未支付的订单','1'=>'已支付的订单'] as $k=>$v} {foreach [''=>'- 全部订单 -','0'=>'未支付的订单','1'=>'已支付的订单'] as $k=>$v}
{if input('pay_state') eq $k.''} {if input('payment_status') eq $k.''}
<option selected value="{$k}">{$v}</option> <option selected value="{$k}">{$v}</option>
{else} {else}
<option value="{$k}">{$v}</option> <option value="{$k}">{$v}</option>
@ -74,62 +73,44 @@
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">支付时间</label> <label class="layui-form-label">支付时间</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input data-date-range name="pay_datetime" value="{:input('pay_datetime')}" placeholder="请选择支付时间" class="layui-input"> <input data-date-range name="payment_datetime" value="{:input('payment_datetime')}" placeholder="请选择支付时间" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">收货姓名</label> <label class="layui-form-label">收货姓名</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="express_name" value="{:input('express_name')}" placeholder="请输入收货姓名" class="layui-input"> <input name="truck_name" value="{:input('truck_name')}" placeholder="请输入收货姓名" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">收货手机</label> <label class="layui-form-label">收货手机</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="express_phone" value="{:input('express_phone')}" placeholder="请输入收货手机" class="layui-input"> <input name="truck_phone" value="{:input('truck_phone')}" placeholder="请输入收货手机" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<label class="layui-form-label">收货省份</label> <label class="layui-form-label">收货地址</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="express_province" value="{:input('express_province')}" placeholder="请输入收货省份" class="layui-input"> <input name="address" value="{:input('address')}" placeholder="请输入收货省份" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-inline">
<label class="layui-form-label">收货城市</label>
<div class="layui-input-inline">
<input name="express_city" value="{:input('express_city')}" placeholder="请输入收货城市" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-inline">
<label class="layui-form-label">收货区域</label>
<div class="layui-input-inline">
<input name="express_area" value="{:input('express_area')}" placeholder="请输入收货区域" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-inline">
<label class="layui-form-label">详细地址</label>
<div class="layui-input-inline">
<input name="express_address" value="{:input('express_address')}" placeholder="请输入详细地址" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-inline"> <div class="layui-form-item layui-inline">
<button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button> <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
{if auth('export')}
<button type="button" data-export-list class="layui-btn layui-btn-primary"><i class="layui-icon layui-icon-export"></i> </button> <button type="button" data-form-export="{:url('index')}?type={$type|default=''}&output=json" class="layui-btn layui-btn-primary"><i class="layui-icon layui-icon-export"></i> </button>
{/if}
</div> </div>
</form> </form>
<script> <script>
window.form.render(); window.form.render();
</script> require(['excel'], function (excel) {
{if auth('export')} excel.bind(function (data) {
<script> var rows = [['订单号', '会员编号']];
$('[data-export-list]').on('click', function () { data.forEach(function (item) {
$.form.load('{:url("export")}?type={$type|default=""}', $(this).parents('form').serialize(), 'get', function (ret) { rows.push([item.order_no, item.mid]);
if (ret.code > 0) return $.loadQueue(ret.data), false; });
}) return rows;
});
}); });
</script> </script>
{/if}
</fieldset> </fieldset>

View File

@ -1,17 +1,17 @@
{extend name="../../admin/view/main"} {extend name="../../admin/view/main"}
{block name="content"} {block name="content"}
<div class="layui-tab layui-tab-card think-bg-white"> <div class="layui-tab layui-tab-card">
<ul class="layui-tab-title notselect"> <ul class="layui-tab-title notselect">
{foreach ['all'=>'全部订单','2'=>'待支付的订单','3'=>'待发货的订单','4'=>'待收货的订单','5'=>'已完成的订单','0'=>'已取消的订单'] as $k=>$v} {foreach ['all'=>'全部订单','2'=>'待支付的订单','3'=>'待发货的订单','4'=>'待收货的订单','5'=>'已完成的订单','0'=>'已取消的订单'] as $k=>$v}
{if isset($type) and $type eq $k} {if isset($type) and $type eq $k.''}
<li data-open="{:url('index')}?type={$k}" class="layui-this">{$v} <sup class="layui-badge absolute border-radius">{$totals[$k]??0}</sup></li> <li data-open="{:url('index')}?type={$k}" class="layui-this">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li>
{else} {else}
<li data-open="{:url('index')}?type={$k}">{$v} <sup class="layui-badge absolute border-radius">{$totals[$k]??0}</sup></li> <li data-open="{:url('index')}?type={$k}">{$v} <sup class="layui-badge absolute border-radius">{$total[$k]??0}</sup></li>
{/if}{/foreach} {/if}{/foreach}
</ul> </ul>
<div class="layui-tab-content think-box-shadow"> <div class="layui-tab-content think-box-shadow">
{include file='shop_order_send/index_search'} {include file='shop_order/index_search'}
<table class="layui-table margin-top-10" lay-skin="line"> <table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'} {notempty name='list'}
<thead> <thead>
@ -50,7 +50,7 @@
</td> </td>
<td class='nowrap'> <td class='nowrap'>
<div class="inline-block margin-right-5 think-badge-middle notselect padding-left-5"> <div class="inline-block margin-right-5 think-badge-middle notselect padding-left-5">
{eq name='vo.status' value='0'}<span class="layui-badge layui-bg-gray" data-tips-text="{$vo.cancel_description}">已取消</span>{/eq} {eq name='vo.status' value='0'}<span class="layui-badge layui-bg-gray" data-tips-text="{$vo.cancel_remark}">已取消</span>{/eq}
{eq name='vo.status' value='1'}<span class="layui-badge layui-bg-red">预订单</span>{/eq} {eq name='vo.status' value='1'}<span class="layui-badge layui-bg-red">预订单</span>{/eq}
{eq name='vo.status' value='2'}<span class="layui-badge layui-bg-orange">待付款</span>{/eq} {eq name='vo.status' value='2'}<span class="layui-badge layui-bg-orange">待付款</span>{/eq}
{eq name='vo.status' value='3'}<span class="layui-badge layui-bg-black">待发货</span>{/eq} {eq name='vo.status' value='3'}<span class="layui-badge layui-bg-black">待发货</span>{/eq}
@ -59,27 +59,24 @@
</div> </div>
<div class="inline-block text-middle"> <div class="inline-block text-middle">
订单单号:<span class="color-blue">{$vo.order_no|default=''}</span><br> 订单单号:<span class="color-blue">{$vo.order_no|default=''}</span><br>
订单金额:<b class="color-blue">{$vo.price_total+0}</b> <span class="color-blue">{if $vo.price_express>0}(含{$vo.price_express+0}元){else}(包邮){/if}</span>已支付 <strong class="color-blue">{$vo.pay_price+0}</strong> <br> 订单金额:<b class="color-blue">{$vo.amount_total+0}</b> <span class="color-blue">{if $vo.amount_express>0}(含{$vo.amount_express+0}元){else}(包邮){/if}</span>已支付 <strong class="color-blue">{$vo.payment_amount+0}</strong> <br>
下单时间:{$vo.create_at|format_datetime}<br> 下单时间:{$vo.create_at|format_datetime}<br>
支付时间:{$vo.pay_datetime|format_datetime}{if $vo.pay_datetime}<span class="color-blue"> ({$vo.pay_type|default='-'})</span>{/if}<br> 支付时间:{$vo.payment_datetime|format_datetime}{if $vo.payment_datetime}<span class="color-blue"> ({$vo.pay_type|default='-'})</span>{/if}<br>
</div> </div>
</td> </td>
<td class="nowrap"> <td class="nowrap">
收货信息:{$vo.express_name|default='--'}<span class="margin-left-5 color-blue">{$vo.express_phone}</span><br> 收货信息:{$vo.truck_name|default='--'}<span class="margin-left-5 color-blue">{$vo.truck_phone}</span><br>
收货地址:{$vo.express_province|default='--'}{$vo.express_city}{$vo.express_area}{$vo.express_address}<br> 收货地址:{$vo.truck_province|default='--'}{$vo.truck_city}{$vo.truck_area}{$vo.truck_address}<br>
发货状态:{eq name='vo.express_state' value='0'} 发货状态:{if empty($vo.truck_send_code)}
<span class="layui-badge layui-bg-black">未发货</span> <span class="layui-badge layui-bg-black">未发货</span>
{else} {else}
<span class="layui-badge layui-bg-blue">{$vo.express_company_title|default='--'}</span> <span class="layui-badge layui-bg-blue">{$vo.express_company_title|default='--'}</span>
<a data-title="{$vo.express_company_title}{$vo.express_send_no}" data-tips-text="快递追踪查询" <a data-title="{$vo.express_company_title}{$vo.express_send_no}" data-tips-text="快递追踪查询"
data-modal="{:url('expressQuery')}?code={$vo.express_company_code}&number={$vo.express_send_no}" data-modal="{:url('expressQuery')}?code={$vo.express_company_code}&number={$vo.express_send_no}"
class="layui-badge layui-bg-gray margin-left-5">{$vo.express_send_no|default='--'}</a> class="layui-badge layui-bg-gray margin-left-5">{$vo.express_send_no|default='--'}</a>
{/eq} {/if}
{if $vo.status eq 3} {if $vo.status eq 3}
<a class=" margin-left-5" data-title="填写订单信息" data-modal="{:url('express')}?id={$vo.id}">填写发货</a> <a class=" margin-left-5" data-title="填写订单信息" data-modal="{:url('express')}?id={$vo.id}">填写发货</a>
<!--{if auth('store/order/pushJushuitan') && isset($jushuitanType) and $jushuitanType > 0}-->
<a class=" margin-left-5" data-confirm="确认要使用仓库发货吗?" data-load="{:url('pushJushuitan')}?order_no={$vo.order_no}">提交仓库</a>
<!--{/if}-->
<!--{if auth('cancel')}--> <!--{if auth('cancel')}-->
<a class=" margin-left-5" data-confirm="确认要取消并创建退款申请吗?" data-load="{:url('cancel')}?order_no={$vo.order_no}">取消并退款</a> <a class=" margin-left-5" data-confirm="确认要取消并创建退款申请吗?" data-load="{:url('cancel')}?order_no={$vo.order_no}">取消并退款</a>
<!--{/if}--> <!--{/if}-->
@ -87,24 +84,15 @@
<a class=" margin-left-5" data-title="修改发货信息" data-modal="{:url('express')}?id={$vo.id}">修改发货</a> <a class=" margin-left-5" data-title="修改发货信息" data-modal="{:url('express')}?id={$vo.id}">修改发货</a>
{/if} {/if}
<br> <br>
发货时间:{$vo.express_send_at|format_datetime}<br> 发货时间:{$vo.truck_express_datetime|format_datetime}<br>
</td> </td>
<td class="nowrap"> <td class="nowrap">
{foreach $vo.list as $g} {foreach $vo.list as $g}
<div> <div>
{if $g.vip_mod > 0 and $g.vip_level > $g.discount_vip} <b class="color-blue">{$g.stock_sales|default=0}</b>
[ <b class="color-red">VIP{$g.discount_vip}</b> <b class="layui-icon font-s10 color-blue">&#xe65b;</b> <b class="color-red">VIP{$g.vip_level}</b> ]
{else}
[ <b class="color-blue">VIP{$g.discount_vip}</b> ]
{/if}
{if $g.discount_rate<100.00}
<b class="color-blue">{$g.discount_rate+0}%折扣</b>
<b class="color-red">x</b> <b class="color-red">x</b>
{/if} <b class="color-blue">{$g.price_market+0} </b>
<b class="color-blue">{$g.number_goods|default=0}</b> {$g.goods_name|default=''} <span class="color-green">( {$g.goods_spec|think_show_goods_spec})</span>
<b class="color-red">x</b>
<b class="color-blue">{$g.goods_price_market+0} </b>
{$g.goods_title|default=''} <span class="color-green">( {$g.goods_spec|show_goods_spec})</span>
</div> </div>
{/foreach} {/foreach}
</td> </td>

View File

@ -32,9 +32,10 @@ require.config({
map: {'*': {css: baseRoot + 'plugs/require/css.js'}}, map: {'*': {css: baseRoot + 'plugs/require/css.js'}},
paths: { paths: {
'md5': ['plugs/jquery/md5.min'], 'md5': ['plugs/jquery/md5.min'],
'chat': ['plugs/michat/michat'],
'json': ['plugs/jquery/json.min'], 'json': ['plugs/jquery/json.min'],
'xlsx': ['plugs/jquery/xlsx.min'], 'xlsx': ['plugs/jquery/xlsx.min'],
'michat': ['plugs/michat/michat'], 'excel': ['plugs/jquery/excel.xlsx'],
'base64': ['plugs/jquery/base64.min'], 'base64': ['plugs/jquery/base64.min'],
'upload': [tapiRoot + '/api.upload?.js'], 'upload': [tapiRoot + '/api.upload?.js'],
'angular': ['plugs/angular/angular.min'], 'angular': ['plugs/angular/angular.min'],

View File

@ -0,0 +1,92 @@
define(['xlsx'], function () {
function excel(data, filename, sheetname) {
this.name = sheetname || 'sheet1';
this.sheet = XLSX.utils.aoa_to_sheet(data);
if (filename.substr(-5).toLowerCase() !== '.xlsx') {
filename += '.xlsx';
}
openDownloadDialog(sheet2blob(this.sheet, this.name), filename);
}
excel.bind = function (done, filename) {
$('body').off('click', '[data-form-export]').on('click', '[data-form-export]', function () {
var form = $(this).parents('form');
var method = $(this).attr('data-method') || 'get';
var location = $(this).attr('data-form-export') || form.get(0).action || '';
excel.load(location, form.serialize(), done, filename, method);
})
};
excel.load = function (url, data, done, filename, method) {
var alldata = [];
var loading = $.msg.loading('正在加载 <span data-upload-page></span>,完成<span data-upload-progress>0</span>%');
nextPage(1, 1);
function nextPage(curPage, maxPage) {
if (curPage > maxPage) {
if (typeof done === 'function') {
this.result = done(alldata);
if (this.result !== false) {
excel(this.result, filename || '文件下载.xlsx');
} else {
console.log('格式化函数返回`false`,已终止数据导出操作', alldata, this.result);
}
} else {
console.log('格式化函数未绑定,已终止数据导出操作', alldata);
}
$.msg.close(loading);
} else {
$('[data-upload-page]').html(curPage + '/' + maxPage);
$('[data-upload-progress]').html((curPage / maxPage * 100).toFixed(2));
$.form.load(url + (url.indexOf('?') > -1 ? '&' : '?') + 'output=json&page=' + curPage, data, method || 'get', function (ret) {
if (ret.code) {
alldata = alldata.concat(ret.data.list);
return nextPage((ret.data.page.current || 1) + 1, ret.data.page.pages || 1), false;
}
}, false);
}
}
}
return excel;
/*! Sheet 转下载对象 */
function sheet2blob(sheet, name) {
this.workbook = {SheetNames: [name], Sheets: {}};
this.workbook.Sheets[name] = sheet;
this.content = XLSX.write(this.workbook, {
type: 'binary', bookSST: false, bookType: 'xlsx',
});
return new Blob([toArrayBuffer(this.content)], {
type: "application/octet-stream"
});
}
/*! 字符串转 ArrayBuffer */
function toArrayBuffer(s) {
this.buff = new ArrayBuffer(s.length);
this.view = new Uint8Array(this.buff);
for (this.index = 0; this.index !== s.length; ++this.index) {
this.view[this.index] = s.charCodeAt(this.index) & 0xFF;
}
return this.buff;
}
/*! 通用的打开下载对话框方法 */
function openDownloadDialog(location, filename) {
if (typeof location == 'object' && location instanceof Blob) {
location = URL.createObjectURL(location);
}
this.link = document.createElement('a');
this.link.download = filename || Date.now() + '.xlsx';
this.link.href = location;
if (window.MouseEvent) {
this.event = new MouseEvent('click');
} else {
this.event = document.createEvent('MouseEvents');
this.event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
}
this.link.dispatchEvent(this.event);
}
});