|
@@ -488,35 +488,38 @@ class Report extends Base
|
|
|
if ($param['start_date'] != '' && $param['end_date'] != '') $where[] = ['addtime', 'between', [$param['start_date'] . ' 00:00:00', $param['end_date'] . ' 23:59:59']];
|
|
|
|
|
|
//先组织子查询
|
|
|
- $children_query = Db::name('purchease_order')
|
|
|
- ->field('id,DATE_FORMAT(addtime, "%Y-%m-%d") addtime,cgder_id,cgder,total_fee,status,good_num')
|
|
|
+ $rs = Db::name('purchease_order')
|
|
|
+ ->field('id,DATE_FORMAT(addtime, "%Y-%m-%d") addtime,cgder_id,cgder,total_fee,status,good_num,supplierNo,0 wait_total_fee,0 wait_good_num,0 count_num')
|
|
|
->where($where)
|
|
|
- ->buildSql();
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+// ->buildSql();
|
|
|
|
|
|
// $count = Db::table($children_query)
|
|
|
// ->alias('a')
|
|
|
// ->group('addtime,cgder_id,cgder')
|
|
|
// ->count();
|
|
|
|
|
|
- $rs = Db::table($children_query)
|
|
|
- ->alias('a')
|
|
|
- ->field('a.addtime,a.cgder_id,a.cgder,SUM(a.total_fee) total_fee,SUM(a.good_num) good_num,COUNT(a.id) count_num,a.status,0 wait_total_fee,0 wait_good_num')
|
|
|
- ->group('a.addtime,a.cgder_id,a.cgder,a.status')
|
|
|
- ->order('a.addtime desc,a.cgder_id')
|
|
|
+// $rs = Db::table($children_query)
|
|
|
+// ->alias('a')
|
|
|
+// ->field('a.addtime,a.cgder_id,a.cgder,SUM(a.total_fee) total_fee,SUM(a.good_num) good_num,COUNT(a.id) count_num,a.status,0 wait_total_fee,0 wait_good_num,supplierNo')
|
|
|
+// ->group('a.addtime,a.cgder_id,a.cgder,a.status')
|
|
|
+// ->order('a.addtime desc,a.cgder_id')
|
|
|
// ->page($param['page'], $param['size'])
|
|
|
- ->cursor();
|
|
|
+// ->cursor();
|
|
|
+
|
|
|
+ $all_supplier = array_column($rs, 'supplierNo');
|
|
|
+ $has_account = checkHasAccountBySupplierNos($all_supplier);//检查供应商是否开通账号
|
|
|
+ $supplier = Db::name('supplier')->whereIn('code',array_keys($has_account))->column('name','code');
|
|
|
|
|
|
$data = [];
|
|
|
foreach ($rs as $value) {
|
|
|
|
|
|
- //判断采购员是否公司内部
|
|
|
- $temp = Db::name('depart_user')->field('id')->where(['uid' => $value['cgder_id'], 'nickname' => $value['cgder']])->findOrEmpty();
|
|
|
-
|
|
|
if (!isset($data[$value['addtime']][$value['cgder_id']])) {
|
|
|
$data[$value['addtime']][$value['cgder_id']] = [
|
|
|
'addtime' => $value['addtime'],
|
|
|
- 'cgder' => $value['cgder'],
|
|
|
- 'name' => $temp ? get_company_name_by_uid($value['cgder_id']) : '供应商',
|
|
|
+ 'cgder' => isset($has_account[$value['supplierNo']]) ? $supplier[$value['supplierNo']] ?? '' : $value['cgder'],
|
|
|
+ 'name' => isset($has_account[$value['supplierNo']]) ? '供应商' : get_company_name_by_uid($value['cgder_id']),
|
|
|
'count_num' => '0',
|
|
|
'total_fee' => '0',
|
|
|
'good_num' => '0',
|
|
@@ -533,7 +536,7 @@ class Report extends Base
|
|
|
$data[$value['addtime']][$value['cgder_id']]['good_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['good_num'], $value['good_num']);
|
|
|
}
|
|
|
|
|
|
- $data[$value['addtime']][$value['cgder_id']]['count_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['count_num'], $value['count_num']);
|
|
|
+ $data[$value['addtime']][$value['cgder_id']]['count_num'] = bcadd($data[$value['addtime']][$value['cgder_id']]['count_num'], 1);
|
|
|
}
|
|
|
|
|
|
$da = [];
|