作者 何书鹏

经销商导出订单

... ... @@ -111,78 +111,81 @@ class Order extends Base
$list = $this->buildSearchOrder()
->where($where)
->with(['user', 'item'])
->with(['user', 'item' => ['goods_sku_sn']])
->order($sort, $order)
->select();
// 经销商
$dealer = [];
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$dealer = \app\admin\model\dealer\Dealer::where('admin_id',$this->auth->id)->find();
}
$expCellName = [
'order_id' => 'Id',
'order_sn' => '订单号',
// 'type_text' => '订单类型',
'status_text' => '订单状态',
// 'pay_type_text' => '支付类型',
'paytime_text' => '支付时间',
// 'platform_text' => '交易平台',
'user_info' => '用户信息',
'total_amount' => '订单总金额',
'discount_fee' => '优惠金额',
];
// 经销商不显示订单总金额和优惠金额
if(!$dealer){
$expCellName = array_merge($expCellName,[
'total_amount' => '订单总金额',
'discount_fee' => '优惠金额',
]);
}
$expCellName = array_merge($expCellName,[
'pay_fee' => '实际支付金额',
// 'score_fee' => '积分支付数量',
'activity_type_text' => '营销类型',
'goods_title' => '商品名称',
'goods_sku_sn' => '规格编号',
'goods_original_price' => '商品原价',
'goods_price' => '商品价格',
'goods_sku_text' => '商品规格',
'goods_num' => '购买数量',
'dispatch_status_text' => '发货状态',
'dispatch_fee' => '发货费用',
// 'dispatch_type_text' => '发货方式',
// 'aftersale_refund' => '售后/退款',
// 'comment_status_text' => '评价状态',
'refund_fee' => '退款金额',
'refund_msg' => '退款原因',
'express_name' => '快递公司',
'express_code' => '快递编码',
'express_no' => '快递单号',
];
// 经销商
$dealer = [];
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$dealer = \app\admin\model\dealer\Dealer::where('admin_id',$this->auth->id)->find();
}
]);
$newList = [];
foreach ($list as $key => $order) {
$data = [
'order_id' => $order['id'],
'order_sn' => $order['order_sn'],
// 'type_text' => $order['type_text'],
'status_text' => $order['status_text'],
// 'pay_type_text' => $order['pay_type_text'],
'paytime_text' => $order['paytime_text'],
// 'platform_text' => $order['platform_text'],
'user_info' => $order['user'] ? ($order['user']['nickname'] . '-' . $order['user']['mobile']) : '',
'total_amount' => $order['total_amount'],
'discount_fee' => $order['discount_fee'],
'pay_fee' => $order['pay_fee'],
'score_fee' => $order['score_fee'],
];
// 经销商不显示订单总金额和优惠金额
if(!$dealer){
$data = array_merge($data,[
'total_amount' => $order['total_amount'],
'discount_fee' => $order['discount_fee'],
]);
}
$data = array_merge($data,[
'pay_fee' => $order['pay_fee'],
]);
foreach ($order['item'] as $k => $item) {
if(!$dealer || ($dealer && $item['dealer_id'] == $dealer['id'])){
$goods_sku_sn = $item['goods_sku_sn'] ? $item['goods_sku_sn']['sn'] : '';
$itemData = [
'activity_type_text' => $item['activity_type_text'],
'goods_title' => $item['goods_title'],
'goods_sku_sn' => $goods_sku_sn,
'goods_original_price' => $item['goods_original_price'],
'goods_price' => $item['goods_price'],
'goods_sku_text' => $item['goods_sku_text'],
'goods_num' => $item['goods_num'],
'dispatch_status_text' => $item['dispatch_status_text'],
'dispatch_fee' => $item['dispatch_fee'],
// 'dispatch_type_text' => $item['dispatch_type_text'],
// 'aftersale_refund' => $item['aftersale_status_text'] . '/' . $item['refund_status_text'],
// 'comment_status_text' => $item['comment_status_text'],
'refund_fee' => $item['refund_fee'],
'refund_msg' => $item['refund_msg'],
'express_name' => $item['express_name'],
... ... @@ -195,9 +198,10 @@ class Order extends Base
}
}
$total_amount = !$dealer ? ";订单总金额:¥" . array_sum(array_column($list, 'total_amount')) . ";优惠总金额:¥" . array_sum(array_column($list, 'discount_fee')) : '';
// 增加合计
$newList[] = [
'order_id' => "订单总数:" . count($list) . ";订单总金额:¥" . array_sum(array_column($list, 'total_amount')) . ";优惠总金额:¥" . array_sum(array_column($list, 'discount_fee')) . ";实际支付总金额:¥" . array_sum(array_column($list, 'pay_fee'))
'order_id' => "订单总数:" . count($list) . $total_amount . ";实际支付总金额:¥" . array_sum(array_column($list, 'pay_fee'))
];
$export->exportExcel('订单列表-' . date('Y-m-d H:i:s'), $expCellName, $newList);
... ... @@ -899,16 +903,12 @@ class Order extends Base
$fieldArr = [
'Id' => 'order_id',
'订单号' => 'order_sn',
// '订单类型' => 'type_text',
'订单状态' => 'status_text',
// '支付类型' => 'pay_type_text',
'支付时间' => 'paytime_text',
// '交易平台' => 'platform_text',
'用户信息' => 'user_info',
'订单总金额' => 'total_amount',
'优惠金额' => 'discount_fee',
'实际支付金额' => 'pay_fee',
// '积分支付数量' => 'score_fee',
'营销类型' => 'activity_type_text',
'商品名称' => 'goods_title',
'商品原价' => 'goods_original_price',
... ... @@ -917,9 +917,6 @@ class Order extends Base
'购买数量' => 'goods_num',
'发货状态' => 'dispatch_status_text',
'发货费用' => 'dispatch_fee',
// '发货方式' => 'dispatch_type_text',
// '售后/退款' => 'aftersale_refund',
// '评价状态' => 'comment_status_text',
'退款金额' => 'refund_fee',
'退款原因' => 'refund_msg',
'快递公司' => 'express_name',
... ...
... ... @@ -268,4 +268,10 @@ class OrderItem extends Model
{
return $this->belongsTo(\app\admin\model\shopro\store\Store::class, 'store_id');
}
// 规格编号
public function goodsSkuSn()
{
return $this->belongsTo(\app\admin\model\shopro\goods\SkuPrice::class, 'goods_sku_price_id')->field('id,sn');
}
}
... ...