mirror of
https://gitee.com/ShopeX/OMS
synced 2026-04-20 20:10:28 +08:00
974 lines
37 KiB
PHP
974 lines
37 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
class omeanalysts_mdl_ome_aftersale extends dbeav_model{
|
|
|
|
var $has_export_cnf = true;
|
|
|
|
var $export_name = '退货情况汇总';
|
|
|
|
/**
|
|
* 获取_count
|
|
* @param mixed $filter filter
|
|
* @return mixed 返回结果
|
|
*/
|
|
public function get_count($filter=null){
|
|
|
|
$sql = 'select sum(num) as total_nums,sum(money) as total_apply_money,sum(refunded) as total_refund_money from sdb_sales_aftersale_items AI left join sdb_sales_aftersale A on AI.aftersale_id = A.aftersale_id where '.$this->_filter($filter);
|
|
|
|
$rows = $this->db->select($sql);
|
|
|
|
return $rows[0];
|
|
}
|
|
|
|
/**
|
|
* count
|
|
* @param mixed $filter filter
|
|
* @return mixed 返回值
|
|
*/
|
|
public function count($filter=null){
|
|
|
|
$sql = "select count(*) as _count from sdb_sales_aftersale_items AI left join sdb_sales_aftersale A on AI.aftersale_id = A.aftersale_id where ".$this->_filter($filter);
|
|
$rows = $this->db->select($sql);
|
|
return $rows[0]['_count'];
|
|
}
|
|
|
|
public function getlist($cols='*', $filter=array(), $offset=0, $limit=-1, $orderType=null)
|
|
{
|
|
$basicMaterialSelect = kernel::single('material_basic_select');
|
|
|
|
#商品品牌
|
|
$brandList = array();
|
|
$oBrand = app::get('ome')->model('brand');
|
|
$tempData = $oBrand->getList('brand_id, brand_name', '', 0, -1);
|
|
foreach ($tempData as $key => $val)
|
|
{
|
|
$brandList[$val['brand_id']] = $val['brand_name'];
|
|
}
|
|
|
|
#商品类型
|
|
$goodsTypeList = array();
|
|
$oType = app::get('ome')->model('goods_type');
|
|
$tempData = $oType->getList('type_id, name', '', 0, -1);
|
|
foreach ($tempData as $key => $val)
|
|
{
|
|
$goodsTypeList[$val['type_id']] = stripcslashes($val['name']);
|
|
}
|
|
unset($tempData, $oBrand, $oType);
|
|
|
|
|
|
$sql = "select A.shop_id,A.order_id,A.reship_id,A.return_id,A.aftersale_time,A.return_type,A.problem_name,AI.product_name,
|
|
AI.bn as product_bn,AI.num as aftersale_num,AI.saleprice,AI.price as return_price,AI.money as apply_money,
|
|
AI.refunded as refundmoney,A.return_apply_id as refund_apply_id,A.return_apply_bn,A.refundtime,AI.branch_id,AI.bn
|
|
FROM sdb_sales_aftersale_items AI left join sdb_sales_aftersale A on AI.aftersale_id = A.aftersale_id
|
|
WHERE ".$this->_filter($filter);
|
|
|
|
if($orderType) $sql .= ' order by '.(is_array($orderType) ? implode($orderType, ' ') : $orderType);
|
|
|
|
$rows = $this->db->selectLimit($sql,$limit,$offset);
|
|
|
|
$refundids = $orderids = $reshipids = $bns = array();
|
|
|
|
foreach($rows as $v){
|
|
$bns[] = $v['bn'];
|
|
$orderids[] = $v['order_id'];
|
|
$reshipids[] = $v['reship_id'];
|
|
$refundids[] = $v['refund_apply_id'];
|
|
$returnids[] = $v['return_id'];
|
|
}
|
|
|
|
$get_bns = $basicMaterialSelect->getlist_ext('*', array('material_bn'=>$bns));
|
|
|
|
foreach($get_bns as $v){
|
|
|
|
#基础物料类型
|
|
if($v['cat_id'])
|
|
{
|
|
$v['goods_type'] = $goodsTypeList[$v['cat_id']];
|
|
}
|
|
|
|
#基础物料品牌
|
|
if($v['brand_id'])
|
|
{
|
|
$v['brand_name'] = $brandList[$v['brand_id']];
|
|
}
|
|
|
|
#基础物料规则
|
|
$v['spec_info'] = $v['specifications'];
|
|
|
|
$product_info[$v['bn']] = $v;
|
|
$pro_bns[] = $v['bn'];
|
|
}
|
|
|
|
$Obranch = app::get('ome')->model('branch');
|
|
$oOrder = app::get('ome')->model('orders');
|
|
$oReship = app::get('ome')->model('reship');
|
|
$oRefund = app::get('ome')->model('refunds');
|
|
$oReTurn = app::get('ome')->model('return_process_items');
|
|
$ObjSale = app::get('ome')->model('sales');
|
|
|
|
$branch = $Obranch->getList('branch_id,name');
|
|
|
|
foreach ($branch as $v) {
|
|
$branchs[$v['branch_id']] = $v['name'];
|
|
}
|
|
|
|
$orderbns = $oOrder->getList('order_id,order_bn',array('order_id|in'=>$orderids));
|
|
$sql = 'select
|
|
sale.order_id,iostock.bn,iostock.nums,iostock.unit_cost
|
|
from sdb_ome_iostock iostock
|
|
left join sdb_ome_sales sale on iostock.iostock_bn=sale.iostock_bn where sale.order_id in ("'.implode('","', $orderids).'")';
|
|
#获取单位成本、出入库数量
|
|
$_sale_info = $this->db->select($sql);
|
|
$sale_cost_bn_info = array();
|
|
$sale_cost_info = array();#销售成本信息
|
|
foreach( $_sale_info as $v){
|
|
//$sale_cost_info[$v['order_id']] = $v;
|
|
$sale_cost_bn_info[$v['order_id']][$v['bn']] = $v;
|
|
}
|
|
|
|
foreach ($orderbns as $v) {
|
|
$orders[$v['order_id']] = $v['order_bn'];
|
|
}
|
|
|
|
$reshipbns = $oReship->getList('reship_id,reship_bn',array('reship_id|in'=>$reshipids));
|
|
|
|
foreach ($reshipbns as $v) {
|
|
$reships[$v['reship_id']] = $v['reship_bn'];
|
|
}
|
|
|
|
$reshipbns = $oRefund->getList('refund_bn,refund_id',array('refund_id|in'=>$refundids));
|
|
|
|
foreach ($reshipbns as $v) {
|
|
$refunds[$v['refund_id']] = $v['refund_bn'];
|
|
}
|
|
|
|
$returnBrids = $oReTurn->getList('reship_id,branch_id',array('reship_id|in'=>$reshipids));
|
|
$returnBranchIds = array();
|
|
$returnBranchs = array();
|
|
foreach($returnBrids as $v) {
|
|
if(isset($returnBranchIds[$v['reship_id']]) && in_array($v['branch_id'], $returnBranchIds[$v['reship_id']])) {
|
|
continue;
|
|
}
|
|
$returnBranchIds[$v['reship_id']][] = $v['branch_id'];
|
|
$returnBranchs[$v['reship_id']] .= ($returnBranchs[$v['return_id']] ? '&' : '').$branchs[$v['branch_id']];
|
|
}
|
|
|
|
foreach($rows as $k=>$v){
|
|
$rows[$k]['branch_id'] = $branchs[$v['branch_id']];
|
|
$rows[$k]['branch_return'] = $returnBranchs[$v['reship_id']];
|
|
$rows[$k]['refund_apply_id'] = $v['return_apply_bn'];
|
|
$rows[$k]['order_id'] = $orders[$v['order_id']];
|
|
$order_id = $v['order_id'];
|
|
|
|
$rows[$k]['shop_type'] = kernel::single('omeanalysts_shop')->getShopDetail($v['shop_id']);
|
|
if(array_key_exists($order_id,$sale_cost_bn_info)){
|
|
#计算销售成本,销售成本=出入库数量*单位成本
|
|
$rows[$k]['sale_cost'] = $sale_cost_bn_info[$order_id][$v['bn']]['nums']*$sale_cost_bn_info[$order_id][$v['bn']]['unit_cost'];
|
|
}
|
|
$rows[$k]['reship_id'] = $reships[$v['reship_id']];
|
|
if(in_array($rows[$k]['bn'],$pro_bns)){
|
|
$rows[$k]['goods_type'] = $product_info[$v['bn']]['goods_type'];
|
|
$rows[$k]['brand_name'] = $product_info[$v['bn']]['brand_name'];
|
|
$rows[$k]['goods_specinfo'] = $product_info[$v['bn']]['spec_info'];
|
|
|
|
//$rows[$k]['goods_bn'] = $product_info[$v['bn']]['goods_bn'];
|
|
}else{
|
|
foreach(kernel::servicelist('ome.product') as $name=>$object){
|
|
if(method_exists($object, 'getProductByBn')){
|
|
$pkg_info = $object->getProductByBn($v['bn']);
|
|
if(!empty($product_info)){
|
|
$rows[$k]['goods_specinfo'] = '-';
|
|
$rows[$k]['goods_type'] = '捆绑商品';
|
|
$rows[$k]['brand_name'] = '-';
|
|
|
|
//$rows[$k]['goods_bn'] = '-';
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$pkg_info || empty($pkg_info)){
|
|
$rows[$k]['goods_specinfo'] = '-';
|
|
$rows[$k]['goods_type'] = '系统不存在此货号';
|
|
$rows[$k]['brand_name'] = '-';
|
|
|
|
//$rows[$k]['goods_bn'] = '-';
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return $rows;
|
|
}
|
|
|
|
/**
|
|
* _filter
|
|
* @param mixed $filter filter
|
|
* @param mixed $tableAlias tableAlias
|
|
* @param mixed $baseWhere baseWhere
|
|
* @return mixed 返回值
|
|
*/
|
|
public function _filter($filter, $tableAlias = null, $baseWhere = null){
|
|
|
|
$where = array(' AI.return_type = "return" ');
|
|
|
|
#店铺
|
|
if(isset($filter['shop_id']) && $filter['shop_id']){
|
|
if(is_array($filter['shop_id'])) {
|
|
$shopIds = array_filter($filter['shop_id']);
|
|
if($shopIds){
|
|
// 对数组中每个元素进行 addslashes 转义
|
|
$escapedShopIds = array_map('addslashes', $shopIds);
|
|
$where[] = ' A.shop_id IN (\'' . implode("','", $escapedShopIds) . '\')';
|
|
}
|
|
} else {
|
|
$where[] = ' A.shop_id =\''.addslashes($filter['shop_id']).'\'';
|
|
}
|
|
}
|
|
|
|
if (isset($filter['shop_type']) && $filter['shop_type']){
|
|
$shopList = kernel::single('omeanalysts_shop')->getShopList();
|
|
$shop_ids = $shopList[$filter['shop_type']];
|
|
|
|
if ($shop_ids){
|
|
$where[] = " A.shop_id in ('".implode('\',\'',$shop_ids)."')";
|
|
}
|
|
}
|
|
//$filter['return_type_id'] = intval($filter['return_type_id']);
|
|
if(isset($filter['return_type_id']) && $filter['return_type_id']){
|
|
$where[] = ' A.return_type =\''. $filter['return_type_id'].'\'';
|
|
}
|
|
|
|
if(isset($filter['time_from']) && $filter['time_from']){
|
|
$time_from = ' A.aftersale_time >='.strtotime($filter['time_from']);
|
|
$where[] = $time_from;
|
|
$ftime = $time_from;
|
|
}
|
|
|
|
if(isset($filter['time_to']) && $filter['time_to']){
|
|
|
|
$time_to = ' A.aftersale_time <='.strtotime($filter['time_to'].' 23:59:59');
|
|
$where[] = $time_to;
|
|
$ftime .= ' AND '.$time_to;
|
|
}
|
|
|
|
$filter['problem_id'] = intval($filter['problem_id']);
|
|
if((isset($filter['problem_id'])&& $filter['problem_id'])){
|
|
$Oproblem = app::get('ome')->model('return_product_problem');
|
|
$problem_data = $Oproblem->getList('problem_name',array('problem_id'=>$filter['problem_id']));
|
|
|
|
$where[] = ' problem_name = "'.$problem_data[0]['problem_name'].'"';
|
|
}
|
|
if(isset($filter['org_id']) && $filter['org_id']){
|
|
$where[] = " A.org_id in ('".implode('\',\'',$filter['org_id'])."')";
|
|
}
|
|
|
|
$filter['brand_id'] = intval($filter['brand_id']);
|
|
$filter['goods_type_id'] = intval($filter['goods_type_id']);
|
|
if((isset($filter['brand_id']) && $filter['brand_id'])||(isset($filter['goods_type_id']) && $filter['goods_type_id'])){
|
|
|
|
$sql = "select AI.item_id, ext.brand_id, ext.cat_id AS type_id
|
|
FROM sdb_sales_aftersale_items as AI
|
|
left join sdb_sales_aftersale as A on AI.aftersale_id = A.aftersale_id
|
|
LEFT JOIN sdb_material_basic_material_ext AS ext ON ext.bm_id=AI.product_id
|
|
WHERE ".$ftime;
|
|
|
|
#品牌
|
|
if(isset($filter['brand_id']) && $filter['brand_id']){
|
|
|
|
$sql .= ' AND ext.brand_id ='. $filter['brand_id'];
|
|
unset($filter['brand_id']);
|
|
}
|
|
|
|
|
|
#商品类型
|
|
if(isset($filter['goods_type_id']) && $filter['goods_type_id']){
|
|
$sql .= ' AND ext.cat_id ='. $filter['goods_type_id'];
|
|
unset($filter['goods_type_id']);
|
|
}
|
|
|
|
$query = $this->db->select($sql);
|
|
|
|
if ($query) {
|
|
foreach($query as $qu){
|
|
$saleitem_ids[] = $qu['item_id'];
|
|
}
|
|
$where[] = " AI.item_id IN (".implode(',',$saleitem_ids).")";
|
|
}else{
|
|
$where[] = " 1=0 ";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return implode(' AND ', $where);
|
|
}
|
|
|
|
/**
|
|
* 获取_schema
|
|
* @return mixed 返回结果
|
|
*/
|
|
public function get_schema(){
|
|
|
|
$schema = array (
|
|
'columns' => array (
|
|
'item_id' =>
|
|
array(
|
|
'type' => 'table:aftersale_items@sales',
|
|
),
|
|
'shop_id' =>
|
|
array (
|
|
'type' => 'table:shop@ome',
|
|
'label' => '店铺名称',
|
|
'width' => 120,
|
|
'order' => 1,
|
|
),
|
|
'shop_type'=>array(
|
|
'type' => 'varchar(32)',
|
|
'label' => '店铺类型',
|
|
|
|
'width' => '70'
|
|
),
|
|
'order_id' =>
|
|
array(
|
|
'type' => 'table:orders@ome',
|
|
'label' => '订单号',
|
|
'width' => 120,
|
|
'order' => 2,
|
|
),
|
|
'reship_id' =>
|
|
array(
|
|
'type' => 'table:reship@ome',
|
|
'label' => '退换货单号',
|
|
'width' => 120,
|
|
'order' => 3,
|
|
),
|
|
'aftersale_time' =>
|
|
array(
|
|
'type' => 'time',
|
|
'label' => '售后创建时间',
|
|
'order' => 4,
|
|
'width' => 130,
|
|
),
|
|
'return_type' =>
|
|
array(
|
|
'type' =>
|
|
array(
|
|
'return' => '退货',
|
|
'change' => '换货',
|
|
),
|
|
'label' => '售后类型',
|
|
'width' => 95,
|
|
'order'=>5,
|
|
),
|
|
'problem_name' =>
|
|
array(
|
|
'type' => 'varchar(200)',
|
|
'label' => '售后服务类型',
|
|
'width' => 130,
|
|
'order' => 6,
|
|
),
|
|
'goods_type' =>
|
|
array(
|
|
'type' => 'varchar(100)',
|
|
'label' => '商品类型',
|
|
'width' => 130,
|
|
'order' => 7,
|
|
),
|
|
'brand_name' =>
|
|
array(
|
|
'type' => 'table:brand@ome',
|
|
'label' => '品牌',
|
|
'width' => 130,
|
|
'order' => 8,
|
|
),
|
|
|
|
/***销售物料编号已弃用
|
|
'goods_bn' =>
|
|
array(
|
|
'type' => 'varchar(30)',
|
|
'label' => '商品编码',
|
|
'width' => 130,
|
|
'order' => 9,
|
|
),
|
|
***/
|
|
|
|
'product_name' =>
|
|
array(
|
|
'type' => 'varchar(200)',
|
|
'label' => '退货货品名称',
|
|
'width' => 130,
|
|
'order' => 10,
|
|
),
|
|
'goods_specinfo'=>
|
|
array(
|
|
'type' => 'varchar(200)',
|
|
'label' => '规格',
|
|
'width' => 130,
|
|
'order' => 11,
|
|
),
|
|
'product_bn' =>
|
|
array(
|
|
'type' => 'varchar(30)',
|
|
'label' => '退货货品货号',
|
|
'width' => 130,
|
|
'order' => 12,
|
|
),
|
|
'aftersale_num' =>
|
|
array(
|
|
'type' => 'number',
|
|
'label' => '退货数量',
|
|
'width' => 100,
|
|
'order' => 13,
|
|
),
|
|
'saleprice' =>
|
|
array(
|
|
'type' => 'number',
|
|
'label' => '销售额',
|
|
'width' => 100,
|
|
'order' => 14,
|
|
),
|
|
'return_price' =>
|
|
array(
|
|
'type' => 'number',
|
|
'label' => '退货单价',
|
|
'width' => 100,
|
|
'order' => 15,
|
|
),
|
|
'apply_money' =>
|
|
array(
|
|
'type' => 'money',
|
|
'label' => '申请退款金额',
|
|
'width' => 75,
|
|
'order'=>16,
|
|
),
|
|
'refundmoney' =>
|
|
array(
|
|
'type' => 'money',
|
|
'label' => '实际退款金额',
|
|
'width' => 75,
|
|
'order'=>17,
|
|
),
|
|
'refund_apply_id' =>
|
|
array(
|
|
'type' => 'varchar(32)',
|
|
'label' => '退款单号',
|
|
'width' => 130,
|
|
'order' => 18,
|
|
),
|
|
'refundtime' =>
|
|
array(
|
|
'type' => 'time',
|
|
'label' => '退款时间',
|
|
'order' => 19,
|
|
'width' => 130,
|
|
),
|
|
'branch_id' =>
|
|
array(
|
|
'type' => 'varchar(200)',
|
|
'editable' => false,
|
|
'label'=>'发货仓库',
|
|
'order' => 20,
|
|
),
|
|
'branch_return' =>
|
|
array(
|
|
'type' => 'varchar(200)',
|
|
'editable' => false,
|
|
'label'=>'退货仓库',
|
|
'order' => 20,
|
|
),
|
|
'sale_cost' =>
|
|
array(
|
|
'type' => 'number',
|
|
'label' => '销售成本',
|
|
'width' => 100,
|
|
'order' => 21,
|
|
),
|
|
),
|
|
'idColumn' => 'aftersale_id',
|
|
'in_list' => array(
|
|
0 => 'shop_id',
|
|
1 =>'shop_type',
|
|
1 => 'order_id',
|
|
2 => 'reship_id',
|
|
3 => 'aftersale_time',
|
|
4 => 'return_type',
|
|
5 => 'problem_name',
|
|
6 => 'goods_type',
|
|
7 => 'brand_name',
|
|
|
|
//8 => 'goods_bn',
|
|
|
|
9 => 'product_name',
|
|
10 => 'goods_specinfo',
|
|
11 => 'product_bn',
|
|
12 => 'aftersale_num',
|
|
13 => 'saleprice',
|
|
14 => 'return_price',
|
|
15 => 'apply_money',
|
|
16 => 'refundmoney',
|
|
17 => 'refund_apply_id',
|
|
18 => 'refundtime',
|
|
19 => 'branch_id',
|
|
20 => 'branch_return',
|
|
21 => 'sale_cost',
|
|
|
|
),
|
|
'default_in_list' => array(
|
|
0 => 'shop_id',
|
|
1 => 'shop_type',
|
|
1 => 'order_id',
|
|
2 => 'reship_id',
|
|
3 => 'aftersale_time',
|
|
4 => 'return_type',
|
|
5 => 'problem_name',
|
|
6 => 'goods_type',
|
|
7 => 'brand_name',
|
|
|
|
//8 => 'goods_bn',
|
|
|
|
9 => 'product_name',
|
|
10 => 'goods_specinfo',
|
|
11 => 'product_bn',
|
|
12 => 'aftersale_num',
|
|
13 => 'saleprice',
|
|
14 => 'return_price',
|
|
15 => 'apply_money',
|
|
16 => 'refundmoney',
|
|
17 => 'refund_apply_id',
|
|
18 => 'refundtime',
|
|
19 => 'branch_id',
|
|
20 => 'branch_return',
|
|
21 => 'sale_cost'
|
|
),
|
|
);
|
|
return $schema;
|
|
}
|
|
|
|
|
|
/**
|
|
* io_title
|
|
* @param mixed $ioType ioType
|
|
* @return mixed 返回值
|
|
*/
|
|
public function io_title( $ioType='csv' ){
|
|
|
|
switch( $ioType ){
|
|
case 'csv':
|
|
$this->oSchema['csv']['main'] = array(
|
|
'*:店铺名称' => 'shop_id',
|
|
'*:订单号' => 'order_id',
|
|
'*:退换货单号' =>'reship_id',
|
|
'*:售后创建时间' => 'aftersale_time',
|
|
'*:售后类型' => 'return_type',
|
|
'*:售后服务类型' => 'problem_name',
|
|
'*:商品类型' => 'goods_type',
|
|
'*:品牌' => 'brand_name',
|
|
|
|
//'*:商品编码' => 'goods_bn',//销售物料编号已弃用
|
|
|
|
'*:退货货品名称' => 'product_name',
|
|
'*:规格' => 'goods_specinfo',
|
|
'*:退货货品货号' => 'product_bn',
|
|
'*:退货数量' => 'aftersale_num',
|
|
'*:销售额' => 'saleprice',
|
|
'*:退货单价' => 'return_price',
|
|
'*:申请退款金额' => 'apply_money',
|
|
'*:实际退款金额' => 'refundmoney',
|
|
'*:退款单号' => 'refund_apply_id',
|
|
'*:退款时间' => 'refundtime',
|
|
'*:发货仓库' => 'branch_id',
|
|
'*:退货仓库' => 'branch_return',
|
|
'*:销售成本' => 'sale_cost'
|
|
);
|
|
break;
|
|
}
|
|
$this->ioTitle[$ioType] = array_keys( $this->oSchema[$ioType]['main'] );
|
|
return $this->ioTitle[$ioType];
|
|
}
|
|
|
|
/**
|
|
* export_csv
|
|
* @param mixed $data 数据
|
|
* @return mixed 返回值
|
|
*/
|
|
public function export_csv($data){
|
|
$output = array();
|
|
$output[] = $data['title']['aftersale']."\n".implode("\n",(array)$data['content']['aftersale']);
|
|
echo implode("\n",$output);
|
|
}
|
|
|
|
/**
|
|
* fgetlist_csv
|
|
* @param mixed $data 数据
|
|
* @param mixed $filter filter
|
|
* @param mixed $offset offset
|
|
* @param mixed $exportType exportType
|
|
* @return mixed 返回值
|
|
*/
|
|
public function fgetlist_csv( &$data,$filter,$offset,$exportType = 1 ){
|
|
|
|
@ini_set('memory_limit','64M');
|
|
|
|
if( !$data['title']['aftersale']){
|
|
$title = array();
|
|
foreach( $this->io_title('csv') as $k => $v ){
|
|
$title[] = $v;
|
|
}
|
|
$data['title']['aftersale'] = mb_convert_encoding('"'.implode('","',$title).'"', 'GBK', 'UTF-8');
|
|
}
|
|
|
|
$limit = 100;
|
|
|
|
if( !$list=$this->getlist('*',$filter,$offset*$limit,$limit) ) return false;
|
|
|
|
$aftersaleRow = array();
|
|
|
|
$oShop = app::get('ome')->model('shop');
|
|
|
|
// 所有的店铺信息
|
|
$rs = $oShop->getList('shop_id,shop_bn,name');
|
|
foreach($rs as $v) {
|
|
$shops[$v['shop_id']] = $v['name'];
|
|
}
|
|
|
|
foreach( $list as $aFilter ){
|
|
|
|
$aftersaleRow['*:店铺名称'] = $shops[$aFilter['shop_id']];
|
|
$aftersaleRow['*:订单号'] = "=\"\"".$aFilter['order_id']."\"\"";//$aFilter['order_id']."\t";
|
|
$aftersaleRow['*:退换货单号'] = "=\"\"".$aFilter['reship_id']."\"\"";//$aFilter['reship_id']."\t";
|
|
$aftersaleRow['*:售后创建时间'] = $aFilter['aftersale_time']?date('Y-m-d H:i:s',$aFilter['aftersale_time']):'-';
|
|
$aftersaleRow['*:售后类型'] = ($aFilter['return_type'] == 'return')?'退货':'换货';
|
|
$aftersaleRow['*:售后服务类型'] = $aFilter['problem_name'];
|
|
$aftersaleRow['*:商品类型'] = $aFilter['goods_type'];
|
|
$aftersaleRow['*:品牌'] = $aFilter['brand_name'];
|
|
|
|
//$aftersaleRow['*:商品编码'] = $aFilter['goods_bn'];//销售物料编号已弃用
|
|
|
|
$aftersaleRow['*:退货货品名称'] = $aFilter['product_name'];
|
|
$aftersaleRow['*:规格'] = $aFilter['goods_specinfo'];
|
|
$aftersaleRow['*:退货货品货号'] = $aFilter['product_bn'];
|
|
$aftersaleRow['*:退货数量'] = $aFilter['aftersale_num'];
|
|
$aftersaleRow['*:销售额'] = $aFilter['saleprice'];
|
|
$aftersaleRow['*:退货单价'] = $aFilter['return_price'];
|
|
$aftersaleRow['*:申请退款金额'] = $aFilter['apply_money'];
|
|
$aftersaleRow['*:实际退款金额'] = $aFilter['refundmoney'];
|
|
$aftersaleRow['*:退款单号'] = $aFilter['refund_apply_id']."\t";
|
|
$aftersaleRow['*:退款时间'] = $aFilter['refundtime']?date('Y-m-d H:i:s',$aFilter['refundtime']):'-';
|
|
$aftersaleRow['*:仓库名称'] = $aFilter['branch_id'];
|
|
$aftersaleRow['*:销售成本'] = $aFilter['sale_cost'];
|
|
$aftersaleRow['*:退货仓库'] = $aFilter['branch_return'];
|
|
|
|
$data['content']['aftersale'][] = mb_convert_encoding('"'.implode('","',$aftersaleRow).'"', 'GBK', 'UTF-8');
|
|
}
|
|
|
|
$data['name'] = $this->export_name.date("YmdHis");
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* exportName
|
|
* @param mixed $data 数据
|
|
* @return mixed 返回值
|
|
*/
|
|
public function exportName(&$data){
|
|
$data['name'] = $_POST['time_from'].'到'.$_POST['time_to'].$this->export_name;
|
|
}
|
|
|
|
/**
|
|
* 获得日志类型(non-PHPdoc)
|
|
* @see dbeav_model::getLogType()
|
|
*/
|
|
public function getLogType($logParams) {
|
|
$type = $logParams['type'];
|
|
$logType = 'none';
|
|
if ($type == 'export') {
|
|
$logType = $this->exportLogType($logParams);
|
|
}
|
|
elseif ($type == 'import') {
|
|
$logType = $this->importLogType($logParams);
|
|
}
|
|
return $logType;
|
|
}
|
|
/**
|
|
* 导出日志类型
|
|
* @param Array $logParams 日志参数
|
|
*/
|
|
public function exportLogType($logParams) {
|
|
$params = $logParams['params'];
|
|
$type = 'report';
|
|
if ($logParams['app'] == 'omeanalysts' && $logParams['ctl'] == 'ome_analysis') {
|
|
$type .= '_salesReport_refundAnalysis';
|
|
}
|
|
$type .= '_export';
|
|
return $type;
|
|
}
|
|
/**
|
|
* 导入操作日志类型
|
|
* @param Array $logParams 日志参数
|
|
*/
|
|
public function importLogType($logParams) {
|
|
$params = $logParams['params'];
|
|
$type = 'report';
|
|
if ($logParams['app'] == 'omeanalysts' && $logParams['ctl'] == 'ome_analysis') {
|
|
$type .= '_salesReport_refundAnalysis';
|
|
}
|
|
$type .= '_import';
|
|
return $type;
|
|
}
|
|
|
|
//根据过滤条件获取导出发货单的主键数据数组
|
|
public function getPrimaryIdsByCustom($filter, $op_id){
|
|
$rows = array();
|
|
$sql = "select AI.item_id from sdb_sales_aftersale_items AI left join sdb_sales_aftersale A on AI.aftersale_id = A.aftersale_id where ".$this->_filter($filter);
|
|
|
|
$rows = $this->db->select($sql);
|
|
|
|
$ids = array();
|
|
foreach ($rows as $k => $row){
|
|
$ids[] = $row['item_id'];
|
|
}
|
|
|
|
return $ids;
|
|
}
|
|
|
|
//根据主键id获取导出数据
|
|
/**
|
|
* 获取ExportDataByCustom
|
|
* @param mixed $fields fields
|
|
* @param mixed $filter filter
|
|
* @param mixed $has_detail has_detail
|
|
* @param mixed $curr_sheet curr_sheet
|
|
* @param mixed $start start
|
|
* @param mixed $end end
|
|
* @param mixed $op_id ID
|
|
* @return mixed 返回结果
|
|
*/
|
|
public function getExportDataByCustom($fields, $filter, $has_detail, $curr_sheet, $start, $end, $op_id)
|
|
{
|
|
$basicMaterialSelect = kernel::single('material_basic_select');
|
|
|
|
$ids = $filter['item_id'];
|
|
$sql = "select A.shop_id,A.order_id,A.reship_id,A.aftersale_time,A.return_type,A.problem_name,AI.product_name,AI.bn as product_bn,AI.num as aftersale_num,AI.saleprice,AI.price as return_price,AI.money as apply_money,AI.refunded as refundmoney,A.return_apply_id as refund_apply_id,A.return_apply_bn,A.refundtime,AI.branch_id,AI.bn from sdb_sales_aftersale_items AI left join sdb_sales_aftersale A on AI.aftersale_id = A.aftersale_id where AI.item_id in (".implode(',',$ids).")";
|
|
$rows = $this->db->select($sql);
|
|
$refundids = $orderids = $reshipids = $bns = array();
|
|
foreach($rows as $v){
|
|
$bns[] = $v['bn'];
|
|
$orderids[] = $v['order_id'];
|
|
$reshipids[] = $v['reship_id'];
|
|
$refundids[] = $v['refund_apply_id'];
|
|
}
|
|
|
|
$get_bns = $basicMaterialSelect->getlist_ext('*', array('material_bn'=>$bns));
|
|
|
|
#商品品牌
|
|
$brandList = array();
|
|
$oBrand = app::get('ome')->model('brand');
|
|
$tempData = $oBrand->getList('brand_id, brand_name', '', 0, -1);
|
|
foreach ($tempData as $key => $val)
|
|
{
|
|
$brandList[$val['brand_id']] = $val['brand_name'];
|
|
}
|
|
|
|
#商品类型
|
|
$goodsTypeList = array();
|
|
$oType = app::get('ome')->model('goods_type');
|
|
$tempData = $oType->getList('type_id, name', '', 0, -1);
|
|
foreach ($tempData as $key => $val)
|
|
{
|
|
$goodsTypeList[$val['type_id']] = stripcslashes($val['name']);
|
|
}
|
|
unset($tempData, $oBrand, $oType);
|
|
|
|
foreach($get_bns as $v){
|
|
|
|
#基础物料类型
|
|
if($v['cat_id'])
|
|
{
|
|
$v['goods_type'] = $goodsTypeList[$v['cat_id']];
|
|
}
|
|
|
|
#基础物料品牌
|
|
if($v['brand_id'])
|
|
{
|
|
$v['brand_name'] = $brandList[$v['brand_id']];
|
|
}
|
|
|
|
#基础物料规则
|
|
$v['spec_info'] = $v['specifications'];
|
|
|
|
$product_info[$v['bn']] = $v;
|
|
$pro_bns[] = $v['bn'];
|
|
}
|
|
|
|
$Obranch = app::get('ome')->model('branch');
|
|
$oOrder = app::get('ome')->model('orders');
|
|
$oReship = app::get('ome')->model('reship');
|
|
$oRefund = app::get('ome')->model('refunds');
|
|
$ObjSale = app::get('ome')->model('sales');
|
|
$oReTurn = app::get('ome')->model('return_process_items');
|
|
|
|
$branch = $Obranch->getList('branch_id,name');
|
|
foreach ($branch as $v) {
|
|
$branchs[$v['branch_id']] = $v['name'];
|
|
}
|
|
|
|
$sql = 'select
|
|
sale.order_id,iostock.bn,iostock.nums,iostock.unit_cost
|
|
from sdb_ome_iostock iostock
|
|
left join sdb_ome_sales sale on iostock.iostock_bn=sale.iostock_bn where sale.order_id in ('.implode(',', $orderids).')';
|
|
#获取单位成本、出入库数量
|
|
$_sale_info = $this->db->select($sql);
|
|
$sale_cost_bn_info = array();
|
|
$sale_cost_info = array();#销售成本信息
|
|
foreach( $_sale_info as $v){
|
|
//$sale_cost_info[$v['order_id']] = $v;
|
|
$sale_cost_bn_info[$v['order_id']][$v['bn']] = $v;
|
|
}
|
|
|
|
$orderbns = $oOrder->getList('order_id,order_bn',array('order_id|in'=>$orderids));
|
|
foreach ($orderbns as $v) {
|
|
$orders[$v['order_id']] = $v['order_bn'];
|
|
}
|
|
|
|
$reshipbns = $oReship->getList('reship_id,reship_bn',array('reship_id|in'=>$reshipids));
|
|
foreach ($reshipbns as $v) {
|
|
$reships[$v['reship_id']] = $v['reship_bn'];
|
|
}
|
|
|
|
$reshipbns = $oRefund->getList('refund_bn,refund_id',array('refund_id|in'=>$refundids));
|
|
foreach ($reshipbns as $v) {
|
|
$refunds[$v['refund_id']] = $v['refund_bn'];
|
|
}
|
|
$returnBrids = $oReTurn->getList('reship_id,branch_id',array('reship_id|in'=>$reshipids));
|
|
$returnBranchIds = array();
|
|
$returnBranchs = array();
|
|
foreach($returnBrids as $v) {
|
|
if(isset($returnBranchIds[$v['reship_id']]) && in_array($v['branch_id'], $returnBranchIds[$v['reship_id']])) {
|
|
continue;
|
|
}
|
|
$returnBranchIds[$v['reship_id']][] = $v['branch_id'];
|
|
$returnBranchs[$v['reship_id']] .= ($returnBranchs[$v['reship_id']] ? '&' : '').$branchs[$v['branch_id']];
|
|
}
|
|
foreach($rows as $k=>$v){
|
|
$rows[$k]['branch_id'] = $branchs[$v['branch_id']];
|
|
$rows[$k]['branch_return'] = $returnBranchs[$v['reship_id']];
|
|
$rows[$k]['refund_apply_id'] = $v['return_apply_bn'];
|
|
$rows[$k]['order_id'] = $orders[$v['order_id']];
|
|
$order_id = $v['order_id'];
|
|
if(array_key_exists($order_id,$sale_cost_bn_info)){
|
|
#计算销售成本,销售成本=出入库数量*单位成本
|
|
$rows[$k]['sale_cost'] = $sale_cost_bn_info[$order_id][$v['bn']]['nums']*$sale_cost_bn_info[$order_id][$v['bn']]['unit_cost'];
|
|
}
|
|
$rows[$k]['reship_id'] = $reships[$v['reship_id']];
|
|
if(in_array($rows[$k]['bn'],$pro_bns)){
|
|
$rows[$k]['goods_type'] = $product_info[$v['bn']]['goods_type'];
|
|
$rows[$k]['brand_name'] = $product_info[$v['bn']]['brand_name'];
|
|
$rows[$k]['goods_specinfo'] = $product_info[$v['bn']]['spec_info'];
|
|
|
|
//$rows[$k]['goods_bn'] = $product_info[$v['bn']]['goods_bn'];//销售物料编号已弃用
|
|
|
|
}else{
|
|
foreach(kernel::servicelist('ome.product') as $name=>$object){
|
|
if(method_exists($object, 'getProductByBn')){
|
|
$pkg_info = $object->getProductByBn($v['bn']);
|
|
if(!empty($product_info)){
|
|
$rows[$k]['goods_specinfo'] = '-';
|
|
$rows[$k]['goods_type'] = '捆绑商品';
|
|
$rows[$k]['brand_name'] = '-';
|
|
|
|
//$rows[$k]['goods_bn'] = '-';
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$pkg_info || empty($pkg_info)){
|
|
$rows[$k]['goods_specinfo'] = '-';
|
|
$rows[$k]['goods_type'] = '系统不存在此货号';
|
|
$rows[$k]['brand_name'] = '-';
|
|
|
|
//$rows[$k]['goods_bn'] = '-';
|
|
}
|
|
}
|
|
}
|
|
|
|
//根据选择的字段定义导出的第一行标题
|
|
if($curr_sheet == 1){
|
|
$data['content']['main'][] = $this->getExportTitle($fields);
|
|
}
|
|
|
|
$oShop = app::get('ome')->model('shop');
|
|
$rs = $oShop->getList('shop_id,shop_bn,name');
|
|
foreach($rs as $v) {
|
|
$shops[$v['shop_id']] = $v['name'];
|
|
}
|
|
|
|
$aftersaleRow = array();
|
|
foreach( $rows as $aFilter ){
|
|
$aftersaleRow['shop_id'] = $shops[$aFilter['shop_id']];
|
|
$aftersaleRow['shop_type'] = kernel::single('omeanalysts_shop')->getShopDetail($aFilter['shop_id']);
|
|
$aftersaleRow['order_id'] = $aFilter['order_id'];
|
|
$aftersaleRow['reship_id'] = $aFilter['reship_id'];
|
|
$aftersaleRow['aftersale_time'] = $aFilter['aftersale_time']?date('Y-m-d H:i:s',$aFilter['aftersale_time']):'-';
|
|
$aftersaleRow['return_type'] = ($aFilter['return_type'] == 'return')?'退货':'换货';
|
|
$aftersaleRow['problem_name'] = $aFilter['problem_name'];
|
|
$aftersaleRow['goods_type'] = $aFilter['goods_type'];
|
|
$aftersaleRow['brand_name'] = $aFilter['brand_name'];
|
|
|
|
//$aftersaleRow['goods_bn'] = $aFilter['goods_bn'];//销售物料编号已弃用
|
|
|
|
$aftersaleRow['product_name'] = $aFilter['product_name'];
|
|
$aftersaleRow['goods_specinfo'] = $aFilter['goods_specinfo'];
|
|
$aftersaleRow['product_bn'] = $aFilter['product_bn'];
|
|
$aftersaleRow['aftersale_num'] = $aFilter['aftersale_num'];
|
|
$aftersaleRow['saleprice'] = $aFilter['saleprice'];
|
|
$aftersaleRow['return_price'] = $aFilter['return_price'];
|
|
$aftersaleRow['apply_money'] = $aFilter['apply_money'];
|
|
$aftersaleRow['refundmoney'] = $aFilter['refundmoney'];
|
|
$aftersaleRow['refund_apply_id'] = $aFilter['refund_apply_id']."\t";
|
|
$aftersaleRow['refundtime'] = $aFilter['refundtime']?date('Y-m-d H:i:s',$aFilter['refundtime']):'-';
|
|
$aftersaleRow['branch_id'] = $aFilter['branch_id'];
|
|
$aftersaleRow['sale_cost'] = $aFilter['sale_cost'];
|
|
$aftersaleRow['branch_return'] = $aFilter['branch_return'];
|
|
|
|
$exptmp_data = array();
|
|
foreach (explode(',', $fields) as $key => $col)
|
|
{
|
|
//过滤不需要导出的字段
|
|
if(in_array($col, array('goods_bn'))){
|
|
continue;
|
|
}
|
|
|
|
//导出字段
|
|
if(isset($aftersaleRow[$col])){
|
|
$aftersaleRow[$col] = mb_convert_encoding($aftersaleRow[$col], 'GBK', 'UTF-8');
|
|
$exptmp_data[] = $aftersaleRow[$col];
|
|
}else{
|
|
$exptmp_data[] = '';
|
|
}
|
|
}
|
|
|
|
$data['content']['main'][] = implode(',', $exptmp_data);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
} |