|
@@ -1114,24 +1114,34 @@ class SaleReport extends Base
|
|
|
->alias('s')
|
|
|
// ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
|
|
|
->where($where)
|
|
|
- ->group('s.good_code,s.good_name,s.cat_id')//存疑,此处原本是根据csi.itemid分组的
|
|
|
+ ->group('s.good_code')
|
|
|
->count('s.id');
|
|
|
|
|
|
$data = Db::name('sale')
|
|
|
->alias('s')
|
|
|
- ->field('s.good_code,s.good_name,SUM(s.good_num) total_num,SUM(s.total_price) total_price,s.cat_id,s.customer_code')
|
|
|
+// ->field('s.good_code,s.good_name,SUM(s.good_num) total_num,SUM(s.total_price) total_price,s.cat_id,s.customer_code')
|
|
|
+ ->field('s.good_code,SUM(s.good_num) total_num,SUM(s.total_price) total_price')
|
|
|
// ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
|
|
|
->where($where)
|
|
|
- ->group('s.good_code,s.good_name,s.cat_id')//存疑,此处原本是根据csi.itemid分组的
|
|
|
+ ->group('s.good_code')//存疑,此处原本是根据csi.itemid分组的
|
|
|
->page($param['page'], $param['size'])
|
|
|
->order('total_num', 'desc')
|
|
|
- ->cursor();
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $replenish = Db::name('sale')
|
|
|
+ ->where(['is_del' => 0, 'good_code' => array_unique(array_column($data, 'good_code'))])
|
|
|
+ ->column('good_name,cat_id,customer_code', 'good_code');
|
|
|
|
|
|
$userCommon = \app\admin\common\User::getIns();
|
|
|
$list = $customer2_tmp = [];
|
|
|
|
|
|
foreach ($data as $value) {
|
|
|
|
|
|
+ $value['good_name'] = $replenish[$value['good_code']]['good_name'] ?? '';
|
|
|
+ $value['cat_id'] = $replenish[$value['good_code']]['cat_id'] ?? '';
|
|
|
+ $value['customer_code'] = $replenish[$value['good_code']]['customer_code'] ?? '';
|
|
|
+
|
|
|
if (!isset($customer2_tmp[$value['customer_code']])) {
|
|
|
$temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
|
|
|
$customer2_tmp[$value['customer_code']] = [
|
|
@@ -1169,18 +1179,28 @@ class SaleReport extends Base
|
|
|
|
|
|
$data = Db::name('sale')
|
|
|
->alias('s')
|
|
|
- ->field('s.good_code,"" 产品品类,s.good_name 产品名称,SUM(s.good_num) total_num,"" 数量,SUM(s.total_price) 金额,s.cat_id,s.customer_code')
|
|
|
-// ->leftJoin('customer_info csi', 'csi.companyNo=s.customer_code')
|
|
|
+ ->field('s.good_code,"" 产品品类,"" 产品名称,SUM(s.good_num) total_num,"" 数量,SUM(s.total_price) 金额,0 cat_id,"" customer_code,"" 一级企业,"" 二级企业')
|
|
|
->where($where)
|
|
|
- ->group('s.good_code,s.good_name,s.cat_id')//存疑,此处原本是根据csi.itemid分组的
|
|
|
+ ->group('s.good_code')//存疑,此处原本是根据csi.itemid分组的
|
|
|
->order('total_num', 'desc')
|
|
|
->cursor();
|
|
|
|
|
|
+ $replenish = Db::name('sale')
|
|
|
+ ->alias('s')
|
|
|
+ ->where($where)
|
|
|
+ ->column('good_name 产品名称,cat_id,customer_code', 'good_code');
|
|
|
+
|
|
|
$userCommon = \app\admin\common\User::getIns();
|
|
|
$list = $customer2_tmp = [];
|
|
|
|
|
|
foreach ($data as $value) {
|
|
|
|
|
|
+// $tmp=Db::name('sale')
|
|
|
+// ->field('good_name 产品名称,cat_id,customer_code')
|
|
|
+// ->where(['is_del'=>0,'good_code'=>$value['good_code']])
|
|
|
+// ->findOrEmpty();
|
|
|
+ $value = array_merge($value, $replenish[$value['good_code']]);
|
|
|
+
|
|
|
if (!isset($customer2_tmp[$value['customer_code']])) {
|
|
|
$temp = $userCommon->handle('cInfo', ['companyNo' => $value['customer_code']]);
|
|
|
$customer2_tmp[$value['customer_code']] = [
|
|
@@ -1188,11 +1208,12 @@ class SaleReport extends Base
|
|
|
'companyName' => $temp['data']['companyName'],
|
|
|
];
|
|
|
}
|
|
|
+
|
|
|
$value['itemid'] = $customer2_tmp[$value['customer_code']]['itemid'];
|
|
|
// $value['客户名称'] = $customer2_tmp[$value['customer_code']]['companyName'];
|
|
|
|
|
|
if (!empty($value['itemid'])) {
|
|
|
- $customer_org1 = array_column(get_top_customer_org($value['itemid']), 'name', 'level');
|
|
|
+ $customer_org1 = array_column(get_top_customer_org($value['itemid']) ?? [], 'name', 'level');
|
|
|
$value['一级企业'] = isset($customer_org1[1]) ? $customer_org1[1] : '';
|
|
|
$value['二级企业'] = isset($customer_org1[2]) ? $customer_org1[2] : '';
|
|
|
}
|
|
@@ -1263,8 +1284,8 @@ class SaleReport extends Base
|
|
|
if (!isset($customer2_tmp[$value['khNo']])) {
|
|
|
$temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
|
|
|
$customer2_tmp[$value['khNo']] = [
|
|
|
- 'itemid' => $temp['data']['itemid'],
|
|
|
- 'companyName' => $temp['data']['companyName'],
|
|
|
+ 'itemid' => $temp['data']['itemid']??0,
|
|
|
+ 'companyName' => $temp['data']['companyName']??'',
|
|
|
];
|
|
|
}
|
|
|
$value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
|
|
@@ -1324,8 +1345,8 @@ class SaleReport extends Base
|
|
|
if (!isset($customer2_tmp[$value['khNo']])) {
|
|
|
$temp = $userCommon->handle('cInfo', ['companyNo' => $value['khNo']]);
|
|
|
$customer2_tmp[$value['khNo']] = [
|
|
|
- 'itemid' => $temp['data']['itemid'],
|
|
|
- 'companyName' => $temp['data']['companyName'],
|
|
|
+ 'itemid' => $temp['data']['itemid']??0,
|
|
|
+ 'companyName' => $temp['data']['companyName']??'',
|
|
|
];
|
|
|
}
|
|
|
$value['itemid'] = $customer2_tmp[$value['khNo']]['itemid'];
|