Commit c6337aa0 by cwy

增加统计功能

parent 96c3ef1e
......@@ -28,12 +28,16 @@ class EnterpriseAllocation extends AuthBase
// 数据接收
$page = input("param.page",0,"intval");
$limit = input("param.limit",10,"intval");
$user_id = input("user_id");
$department_id = input("department_id");
$EnterpriseAllocationModel =new EnterpriseAllocationModel();
$where = [];
if($department_id){
$where[] = ['department_id', '=',$department_id];
}
if($user_id){
$where[] = ['user_id', '=',$user_id];
}
$result = $EnterpriseAllocationModel->with([
'enterpriseInfo' => function($query){
// $query->where('assignable',1);
......@@ -166,7 +170,8 @@ class EnterpriseAllocation extends AuthBase
$allocation=[
'user_id'=>$val['id'],
'enterprise_id'=>$value,
'distribute_time'=>date('Y-m-d H:i:s')
'distribute_time'=>date('Y-m-d H:i:s'),
'department_id'=>$val['department_id'],
];
$tt = Db::name('enterprise_allocation')
->where('user_id',$val['id'])
......@@ -201,4 +206,79 @@ class EnterpriseAllocation extends AuthBase
}
}
}
public function collectStatistics()
{
try{
$department_id = input("department_id");
$userList = Db::name('admin')->where('department_id',$department_id)->select();
$userInfo = [];
if(empty($userList)){
return returnResult(config("config.code.success"),config("config.describe.success"),[]);
}
$userList = $userList->toArray();
$list = [];
foreach ($userList as $value){
array_push($userInfo,$value['id']);
$arr = [
'user_id'=>$value['id'],
'user_name'=>$value['name'],
'enterprise_quantity'=>0, // 企业数量
'enterprise_status'=>'', //完成状态
'product_quantity'=>0, //产品数量
'unfinished_product'=>0, //未完成产品数量
'completed_product'=>0, //已完成产品数量
];
array_push($list,$arr);
}
//总数
$total=[
'enterprise_quantity'=>0, // 总企业数量
'product_quantity'=>0, // 总产品数量
'completed_product'=>0, // 总产品完成数量
'unfinished_product'=>0, // 总产品未完成数量
];
// 企业统计
$enterprise_allocation = Db::name('enterprise_allocation')->where('user_id','in',$userInfo)->select();
foreach ($enterprise_allocation as $value){
$key = array_search($value['user_id'], $userInfo); // 返回 'banana' 的下标,即 2
if($value['department_id']==$department_id){
$list[$key]['enterprise_quantity'] +=1;
$total['enterprise_quantity'] +=1;
}
}
//产品统计
$product_allocation = Db::name('product_allocation')->select();
foreach ($product_allocation as $value){
$key = array_search($value['user_id'], $userInfo); // 返回 'banana' 的下标,即 2
$list[$key]['product_quantity'] +=1;
$total['product_quantity'] +=1;
if($value['status']==1){
$list[$key]['completed_product'] +=1;
$total['completed_product'] +=1;
}else{
$list[$key]['unfinished_product'] +=1;
$total['unfinished_product'] +=1;
}
}
// 是否完成
foreach ($list as $key=> $value){
if($value['product_quantity']==$value['completed_product']){
$list[$key]['enterprise_status'] = '已完成';
}else{
$list[$key]['enterprise_status'] = '未完成';
}
}
$result = [
'data'=>$list,
'total'=>$total
];
return returnResult(config("config.code.success"),config("config.describe.success"),$result);
}catch (\Exception $e){
exception($e,self::$name.'.list');
}
}
}
\ No newline at end of file
......@@ -38,10 +38,18 @@ class ProductAllocation extends AuthBase
$inspect_status = input("inspect_status");
$product_id = input("product_id");
$product_name = input("product_name");
$ProductAllocationModel =new ProductAllocationModel();
$user_id = input("user_id");
$enterprise_id= input("enterprise_id");
$where = [];
if($this->userId!=1){
$where[] = ['t1.user_id', '=',$this->userId];
if(empty($user_id)){
if($this->userId!=1){
$where[] = ['t1.user_id', '=',$this->userId];
}
}else{
$where[] = ['t1.user_id', '=',$user_id];
}
if($enterprise_id){
$where[] = ['t1.enterprise_id', '=',$enterprise_id];
}
if($product_id){
$where[] = ['t2.product_id', '=',$product_id];
......@@ -56,9 +64,11 @@ class ProductAllocation extends AuthBase
->alias('t1')
->join('product t2','t1.product_id=t2.id')
->join('admin t3','t1.user_id=t3.id')
->join('enterprise_info t4','t1.enterprise_id=t4.id')
->field('t1.status as product_allocation_status,t1.id as allocation_id,t1.*')
->field('t2.status as product_status,t2.*')
->field('t3.status as admin_status,t3.*')
->field('t4.enterprise_name as enterprise_name')
->where($where)
->paginate([
'list_rows'=>$limit,
......
......@@ -275,8 +275,9 @@ class Test
$row++;
}
$name ='./product_'.date('Y-m-d H:i:s').'.csv';
$name ='product_'.date('Y-m-d H:i:s').'.csv';
$writer->save($name);
$url = 'http://gcspider.raisound.com:81/product_library_api/public/'.$name;
return returnResult(config("config.code.success"),config("config.describe.success"),$url);
}
}
\ No newline at end of file
......@@ -103,6 +103,7 @@ Route::rule("task/add","Task/add");
Route::rule("enterpriseAllocation/list","EnterpriseAllocation/list");
Route::rule("enterpriseAllocation/userEnterpriseList","EnterpriseAllocation/userEnterpriseList");
Route::rule("enterpriseAllocation/collectStatistics","EnterpriseAllocation/collectStatistics");
//Route::rule("enterpriseAllocation/equalDistributionEnterprise","EnterpriseAllocation/equalDistributionEnterprise");
Route::rule("service/product","Service/product");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment