| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- /**
- * Created by PhpStorm.
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/3/13
- * Time: 下午2:04
- */
- namespace app\backend\modules\order\services;
- use app\backend\modules\order\services\models\ExcelModel;
- class ExportService
- {
- public $columns;
- public function __construct()
- {
- $this->columns = $this->getColumns();
- }
- public function export($orders)
- {
- foreach ($orders as &$order) {
- $order = $this->getOrder($order);
- }
- unset($order);
- $excel = new ExcelModel($this->columns);
- $excel->export($orders, [
- 'title' => '订单-' . date("Y-m-d-H-i", time()),
- 'columns' => $this->columns
- ]);
- }
- protected function getOrder($order){
- $order['pay_sn'] = $order['has_one_order_pay']['pay_sn'];
- $order['uid'] = $order['belongs_to_member']['uid'];
- $order['nickname'] = $order['belongs_to_member']['nickname'];
- $order['realname'] = $order['address']['realname'];
- $order['mobile'] = $order['address']['mobile'];
- $order['address'] = $order['address']['address'];
- $order += $this->getGoods($order);
- $order += $this->getStatus($order);
- $order += $this->setOrder($order);
- $order['pay_type'] = $order['has_one_pay_type']['name'];
- $order['pay_sn'] = $order['has_one_order_pay']['pay_sn'];
- $order['remark'] = $order['has_one_order_remark']['remark'];
- // $order['note'] = $order['note'];
- $order['express_company_name'] = $order['express']['express_company_name'];
- $order['express_sn'] = $order['express']['express_sn'];
- if (empty(strtotime($order['finish_time']))) {
- $order['finish_time'] = '';
- }
- if (empty(strtotime($order['pay_time']))) {
- $order['pay_time'] = '';
- }
- if (empty(strtotime($order['send_time']))) {
- $order['send_time'] = '';
- }
- return $order;
- }
- protected function setOrder($order)
- {
- return [];
- }
- protected function getStatus($order)
- {
- if ($order['status'] == 0) {
- $order['status'] = '待付款';
- } else if ($order['status'] == 1) {
- $order['status'] = '已支付';
- } else if ($order['status'] == 2) {
- $order['status'] = '待收货';
- } else if ($order['status'] == 3) {
- $order['status'] = '已完成';
- } else if ($order['status'] == -1) {
- $order['status'] = '已关闭';
- }
- return $order;
- }
- protected function getGoods($order)
- {
- $order['goods_title'] = '';
- $order['goods_sn'] = '';
- $order['total'] = '';
- foreach ($order['has_many_order_goods'] as $key => $goods) {
- $goods_title = $goods['title'];
- if ($goods['goods_option_title']) {
- $goods_title .= '['. $goods['goods_option_title'] .']';
- }
- $order['goods_title'] .= '【' . $goods_title . '*' . $goods['total'] . '】';
- $order['goods_sn'] .= $goods['goods']['goods_sn'].'/';
- $order['total'] .= $goods['total'].'/';
- }
- return $order;
- }
- protected function getColumns()
- {
- return [
- [
- "title" => "订单编号",
- "field" => "order_sn",
- "width" => 24
- ] ,
- [
- "title" => "支付单号",
- "field" => "pay_sn",
- "width" => 24
- ] ,
- [
- "title" => "粉丝ID",
- "field" => "uid",
- "width" => 12
- ] ,
- [
- "title" => "粉丝昵称",
- "field" => "nickname",
- "width" => 12
- ] ,
- [
- "title" => "会员姓名",
- "field" => "realname",
- "width" => 12
- ] ,
- [
- "title" => "联系电话",
- "field" => "mobile",
- "width" => 12
- ] ,
- [
- "title" => "收货地址",
- "field" => "address",
- "width" => 30
- ] ,
- [
- "title" => "商品名称",
- "field" => "goods_title",
- "width" => 24
- ] ,
- [
- "title" => "商品编码",
- "field" => "goods_sn",
- "width" => 12
- ] ,
- [
- "title" => "商品数量",
- "field" => "total",
- "width" => 12
- ] ,
- [
- "title" => "支付方式",
- "field" => "pay_type",
- "width" => 12
- ] ,
- [
- "title" => "商品小计",
- "field" => "goods_price",
- "width" => 12
- ] ,
- [
- "title" => "运费",
- "field" => "dispatch_price",
- "width" => 12
- ] ,
- [
- "title" => "应收款",
- "field" => "price",
- "width" => 12
- ] ,
- [
- "title" => "状态",
- "field" => "status_name",
- "width" => 12
- ] ,
- [
- "title" => "下单时间",
- "field" => "create_time",
- "width" => 24
- ] ,
- [
- "title" => "付款时间",
- "field" => "pay_time",
- "width" => 24
- ] ,
- [
- "title" => "发货时间",
- "field" => "send_time",
- "width" => 24
- ] ,
- [
- "title" => "完成时间",
- "field" => "finish_time",
- "width" => 24
- ] ,
- [
- "title" => "快递公司",
- "field" => "express_company_name",
- "width" => 24
- ] ,
- [
- "title" => "快递单号",
- "field" => "express_sn",
- "width" => 24
- ] ,
- [
- "title" => "订单备注",
- "field" => "remark",
- "width" => 36
- ],
- [
- "title" => "用户备注",
- "field" => "note",
- "width" => 36
- ],
- ];
- }
- }
|