|
@@ -32,13 +32,6 @@ class WriteOffController
|
|
return json_fail('暂无数据');
|
|
return json_fail('暂无数据');
|
|
}
|
|
}
|
|
|
|
|
|
-// $rows = Db::table("data_used_{$month} as du")
|
|
|
|
-// ->leftJoin('goods as g','g.goods_id','=',"JSON_EXTRACT(du.join_data_used_object_json,'$.goods_id')")
|
|
|
|
-// ->leftJoin('goods_sku as gs','gs.goods_sku_id','=',"JSON_EXTRACT(du.join_data_used_object_json,'$.goods_sku_id')")
|
|
|
|
-// ->leftJoin('sys_user as wu','wu.user_id','=','du.join_data_used_user_id')
|
|
|
|
-// ->leftJoin('sys_user as su','su.user_id' ,'=', "JSON_EXTRACT(du.join_data_used_object_json,'$.salesman_id')")
|
|
|
|
-// ->orderBy('data_used_addtimes','DESC')
|
|
|
|
-// ->get();
|
|
|
|
$totalSql = "
|
|
$totalSql = "
|
|
select count(*) as total from app_data_used_{$month}";
|
|
select count(*) as total from app_data_used_{$month}";
|
|
$total = Db::select($totalSql);
|
|
$total = Db::select($totalSql);
|
|
@@ -76,9 +69,12 @@ class WriteOffController
|
|
|
|
|
|
$row->sku_title = rtrim($skuTitle,',');
|
|
$row->sku_title = rtrim($skuTitle,',');
|
|
}
|
|
}
|
|
|
|
+ $categoryClassify = 'SERVICE';
|
|
$row->category = '';
|
|
$row->category = '';
|
|
if(!empty($row->join_goods_category_id)){
|
|
if(!empty($row->join_goods_category_id)){
|
|
- $row->category = SysCategory::where('category_id',$row->join_goods_category_id)->value('category_name') ?? '';
|
|
|
|
|
|
+ $category = SysCategory::where('category_id',$row->join_goods_category_id)->select('category_name','category_classify')->first();
|
|
|
|
+ $row->category = $category->category_name ?? '';
|
|
|
|
+ $categoryClassify = $category->category_classify ?? 'SERVICE';
|
|
}
|
|
}
|
|
$row->write_off_premises = trim($row->write_off_premises,"\"");
|
|
$row->write_off_premises = trim($row->write_off_premises,"\"");
|
|
}
|
|
}
|
|
@@ -89,7 +85,68 @@ class WriteOffController
|
|
'total' => $total[0]->total,
|
|
'total' => $total[0]->total,
|
|
'rows' => $rows
|
|
'rows' => $rows
|
|
]);
|
|
]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function statistics(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $days = $request->get('days', ['2024-06-01','2024-06-30']);
|
|
|
|
+ if (!empty($days)) {
|
|
|
|
+ $days[0] = strtotime($days[0]);
|
|
|
|
+ $days[1] = strtotime($days[1]);
|
|
|
|
+ if (date('m', $days[0]) != date('m', $days[1])) {
|
|
|
|
+ return json_fail('暂不支持跨月查询');
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ $month = date('Ym', $days[0]);
|
|
|
|
+ $days[1] = strtotime(date('Y-m-d', $days[1]) . " 23:59:59");
|
|
|
|
+ } else {
|
|
|
|
+ $month = date('Ym');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!Util::schema()->hasTable("data_used_{$month}")){
|
|
|
|
+ return json_fail('暂无数据');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $totalSql = "
|
|
|
|
+ select count(*) as total from app_data_used_{$month}";
|
|
|
|
+ $total = Db::select($totalSql);
|
|
|
|
+ $sql = "select
|
|
|
|
+ COUNT(*) as count,g.join_goods_category_id
|
|
|
|
+ from app_data_used_{$month} as du
|
|
|
|
+ left join app_goods as g on JSON_EXTRACT(du.join_data_used_object_json,'$.goods_id') = g.goods_id
|
|
|
|
+ ";
|
|
|
|
+ $rows = Db::select($sql);
|
|
|
|
+ dump($rows);
|
|
|
|
+
|
|
|
|
+ foreach ($rows as &$row){
|
|
|
|
+ $row->salesman_premises = '';
|
|
|
|
+ if (!empty($row->premises_id) && $row->premises_id != 0){
|
|
|
|
+ $premises = SysDept::where('dept_id',$row->premises_id)
|
|
|
|
+ ->select('dept_id','dept_name')
|
|
|
|
+ ->first();
|
|
|
|
+ $row->salesman_premises = !empty($premises) ? $premises->dept_name : '';
|
|
|
|
+ }
|
|
|
|
+ if(!empty($row->goods_sku_specs_json)){
|
|
|
|
+ $specsJson = json_decode($row->goods_sku_specs_json,true);
|
|
|
|
+ $skuTitle = '';
|
|
|
|
+ foreach($specsJson as $key => $item){
|
|
|
|
+ if(is_array($item)){
|
|
|
|
+ $item = implode('',$item);
|
|
|
|
+ }
|
|
|
|
+ $skuTitle .= $key.':'.$item.',';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $row->sku_title = rtrim($skuTitle,',');
|
|
|
|
+ }
|
|
|
|
+ $categoryClassify = 'SERVICE';
|
|
|
|
+ $row->category = '';
|
|
|
|
+ if(!empty($row->join_goods_category_id)){
|
|
|
|
+ $category = SysCategory::where('category_id',$row->join_goods_category_id)->select('category_name','category_classify')->first();
|
|
|
|
+ $row->category = $category->category_name ?? '';
|
|
|
|
+ $categoryClassify = $category->category_classify ?? 'SERVICE';
|
|
|
|
+ }
|
|
|
|
+ $row->write_off_premises = trim($row->write_off_premises,"\"");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public function records()
|
|
public function records()
|