|
|
@@ -2,6 +2,7 @@
|
|
|
namespace app\adminapi\logic\data_analysis;
|
|
|
|
|
|
use app\common\logic\BaseLogic;
|
|
|
+use app\common\model\goods_category\GoodsCategory;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
|
|
|
@@ -78,4 +79,58 @@ class DataAnalysisLogic extends BaseLogic
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ public static function serviceOrdersTotal(array $params = [])
|
|
|
+ {
|
|
|
+ $res = [
|
|
|
+ 'total_flow' => 0,
|
|
|
+ 'proxy_order_flow' => 0,
|
|
|
+ 'free_class_flow' => 0,
|
|
|
+ 'goods_category_flow' => [],
|
|
|
+ ];
|
|
|
+ list($start_time,$end_time) = $params['start_end_time'];
|
|
|
+ $time = [strtotime($start_time), strtotime($end_time)+86400-1];
|
|
|
+
|
|
|
+ $res['total_flow'] = Db::name('service_work')
|
|
|
+ ->field([Db::raw('SUM(work_total) as work_total')])
|
|
|
+ ->where([['service_status','=',3],['approval','=',1]])
|
|
|
+ ->where([['create_time', 'between', $time]])
|
|
|
+ ->select()->toArray()[0]['work_total'];
|
|
|
+
|
|
|
+ $res['proxy_order_flow'] = Db::name('property_order')->alias('a')
|
|
|
+ ->field([Db::raw('SUM(b.work_total) as work_total')])
|
|
|
+ ->leftJoin('service_work b', 'a.work_id = b.id')
|
|
|
+ ->where([['b.service_status','=',3],['b.approval','=',1]])
|
|
|
+ ->where([['b.create_time', 'between', $time]])
|
|
|
+ ->select()->toArray()[0]['work_total'];
|
|
|
+
|
|
|
+
|
|
|
+ $res['free_class_flow'] = Db::name('master_worker_commission_notice')->alias('n')
|
|
|
+ ->leftJoin('master_worker mw', 'n.master_worker_id = mw.id')
|
|
|
+ ->leftJoin('service_work sw', 'n.master_worker_id = sw.master_worker_id AND sw.create_time >= n.signing_date AND sw.create_time <= n.signing_date_end')
|
|
|
+ ->field([Db::raw("SUM(CASE WHEN sw.service_status = 3 THEN sw.work_total ELSE null END) AS work_total")])
|
|
|
+ ->where([['sw.create_time', 'between', $time]])
|
|
|
+ ->select()->toArray()[0]['work_total'];
|
|
|
+
|
|
|
+
|
|
|
+ $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])->select();
|
|
|
+ $res['goods_category_flow'] = Db::name('service_work')
|
|
|
+ ->field(Db::raw("goods_category_ids,goods_category_id,SUM(work_total) as work_total_flow"))
|
|
|
+ ->where('service_status',3)
|
|
|
+ ->where([['create_time', 'between', $time]])
|
|
|
+ ->group('goods_category_id')
|
|
|
+ ->order('work_total_flow', 'desc')
|
|
|
+ ->select()->toArray();
|
|
|
+ foreach ($res['goods_category_flow'] as &$item) {
|
|
|
+ $item['goods_category_ids'] = array_map("intval",json_decode($item['goods_category_ids'],true));
|
|
|
+ $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|