Commit 95630b47 by cwy

多个pdf文件问题

parent e270b40c
<?php
/**
* Create by Administrator
* E-mail: wesley_prc@163.com
* Description: product_library_api
* Date: 2024/9/28 13:14
* Update: 2024/9/28 13:14
*/
namespace app\api\controller;
use app\common\model\redis\RedisModel;
use app\common\model\mysql\EnterpriseInfo as EnterpriseInfoModel;
use app\common\model\mysql\Product as ProductsModel;
use app\common\model\mysql\ProductAllocation as ProductAllocationModel;
use app\common\model\mysql\Admin as AdminModel;
use app\common\model\mysql\EnterpriseAllocation as EnterpriseAllocationModel;
use think\facade\Db;
class EnterpriseAllocation extends AuthBase
{
/**
* 列表
* @return \josn|void
*/
public function list()
{
try{
// 数据接收
$page = input("param.page",0,"intval");
$limit = input("param.limit",10,"intval");
$userId = $this->userId;
$EnterpriseAllocationModel =new EnterpriseAllocationModel();
if($userId!=1){
$result = $EnterpriseAllocationModel->with([
'enterpriseInfo' => function($query){
},
'adminInfo' => function($query){
},
])->where('user_id',$userId)
->paginate([
'list_rows'=>$limit,
'page'=>$page
]);
}else{
$result = $EnterpriseAllocationModel->with([
'enterpriseInfo' => function($query){
},
'adminInfo' => function($query){
},
])->paginate([
'list_rows'=>$limit,
'page'=>$page
]);
}
if($result){
$result = $result->toArray();
foreach ($result['data'] as $key=>$val){
$info = Db::name('product_allocation')->where('enterprise_id',$val['enterprise_id'])->select();
$not_checked = Db::name('product_allocation')->where('enterprise_id',$val['enterprise_id'])->where('status',0)->select();
$checked = Db::name('product_allocation')->where('enterprise_id',$val['enterprise_id'])->where('status',1)->select();
$result['data'][$key]['total'] =count($info);
$result['data'][$key]['not_checked'] =count($not_checked);
$result['data'][$key]['checked'] =count($checked);
}
}
if($result){
return returnResult(config("config.code.success"),config("config.describe.success"),$result);
}else{
return returnResult(config("config.code.success"),config("config.describe.null_data"),$result);
}
}catch (\Exception $e){
exception($e,self::$name.'.list');
}
}
/**
* 可分配的用户组列表
* @return \josn
* @throws \think\db\exception\DbException
*/
public function enterpriseUserGroup()
{
// 数据接收
$page = input("param.page",0,"intval");
$limit = input("param.limit",10,"intval");
$adminGroupModel =new AdminGroupModel();
$result = $adminGroupModel->where('status',1)
->paginate([
'list_rows'=>$limit,
'page'=>$page
]);
if($result){
$result = $result->toArray();
return returnResult(config("config.code.success"),config("config.describe.success"),$result);
}else{
return returnResult(config("config.code.success"),config("config.describe.null_data"),$result);
}
}
public function equalDistributionEnterprise()
{
//人数 条数
$enterpriseInfo = Db::name('enterprise_info')
->where('status',1)
->where('unavailable','可得')
->select();
$userInfo = Db::name('admin')
->where('department_id',4)
->select();
$userCount = count($userInfo); // 可分配的用户总数
$enterpriseInfoCount = count($enterpriseInfo); // 可分配的企业总数
$perCapita = intval($enterpriseInfoCount/$userCount);
$enterpriseList = [];
// 按用户数量分成企业组
for ($i=0;$i<$userCount;$i++){
array_push($enterpriseList,[]);
}
$useri = 0;
//用户对应企业组
foreach ($enterpriseInfo as $value){
if($useri>=$userCount){
$useri=0;
}
array_push($enterpriseList[$useri],$value['id']);
$useri++;
}
foreach ($userInfo as $key=>$val){
foreach ($enterpriseList[$key] as $value){
// 添加企业分配情况
$allocation=[
'user_id'=>$val['id'],
'enterprise_id'=>$value,
'distribute_time'=>date('Y-m-d H:i:s')
];
$tt = Db::name('enterprise_allocation')
->where('user_id',$val['id'])
->where('enterprise_id',$value)
->find();
if(empty($tt)){
Db::name('enterprise_allocation')->insert($allocation);
}
// 添加产品分配情况
$productList = Db::name('product')->where('inspect_status',0)
->where('enterprise_id',$value)
->select();
if($productList){
foreach ($productList as $info){
$arr=[
'user_id'=>$val['id'],
'enterprise_id'=>$value,
'product_id'=>$info['id'],
'distribute_time'=>date('Y-m-d H:i:s')
];
$ss = Db::name('product_allocation')
->where('user_id',$val['id'])
->where('enterprise_id',$value)
->where('product_id',$info['id'])
->find();
if(empty($ss)){
Db::name('product_allocation')->insert($arr);
}
}
}
}
}
}
}
\ No newline at end of file
...@@ -14,9 +14,15 @@ use app\common\model\mysql\Product as ProductModel; ...@@ -14,9 +14,15 @@ use app\common\model\mysql\Product as ProductModel;
use app\common\model\mysql\EnterpriseInfo as EnterpriseInfoModel; use app\common\model\mysql\EnterpriseInfo as EnterpriseInfoModel;
use app\common\model\mysql\ProductAllocation as ProductAllocationModel; use app\common\model\mysql\ProductAllocation as ProductAllocationModel;
use app\common\model\mysql\Admin as AdminModel; use app\common\model\mysql\Admin as AdminModel;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use think\facade\Filesystem;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\facade\Db; use think\facade\Db;
class ProductAllocation extends AuthBase class ProductAllocation extends Base
{ public static $name = 'controller.ProductAllocation'; { public static $name = 'controller.ProductAllocation';
/** /**
...@@ -36,7 +42,7 @@ class ProductAllocation extends AuthBase ...@@ -36,7 +42,7 @@ class ProductAllocation extends AuthBase
'adminInfo' => function($query){ 'adminInfo' => function($query){
$query->where('status',1)->field("id,name"); $query->where('status',1)->field("id,name");
}, },
])->where('user_id',$this->userId) ])->where('user_id',8)
->paginate([ ->paginate([
'list_rows'=>$limit, 'list_rows'=>$limit,
'page'=>$page 'page'=>$page
...@@ -196,4 +202,79 @@ class ProductAllocation extends AuthBase ...@@ -196,4 +202,79 @@ class ProductAllocation extends AuthBase
return returnResult(config("config.code.success"),config("config.describe.null_data"),[]); return returnResult(config("config.code.success"),config("config.describe.null_data"),[]);
} }
} }
public function importProduct()
{
$spreadsheet = IOFactory::load('DUE0930_2000.xlsx');
$objWorksheet = $spreadsheet->getSheet(0); // 只允许读取第一页,多页请分开文档
$data = $objWorksheet->toArray();
$list = [];
foreach ($data as $index=>$value){
if($index>1){
$timestamp = time(); // 当前时间戳
$randomNumber = mt_rand(100000, 999999); // 生成一个六位的随机数
$uniqueIdentifier = $timestamp . $randomNumber; // 时间戳和随机数拼接
$res = Db::name('enterprise_info')->where('enterprise_name',$value[1])->find();
if($res){
$arr = [
'product_id'=>'RS'.$uniqueIdentifier,
'enterprise_id'=>$res['id'],
'page_url'=>$value[4],
'product_categ_name'=>$value[2],
'product_name'=>$value[3],
'product_model'=>$value[5],
'describe'=>$value[6],
'parameter'=>$value[7],
];
$product = Db::name('product')
->where('product_name',$value[3])
->where('page_url',$value[4])
->where('product_categ_name',$value[2])
->where('product_model',$value[5])
->where('describe',$value[6])
->where('parameter',$value[7])
->find();
if(empty($product)){
$product = Db::name('product')->insert($arr);
}
}else{
var_dump($value[1]);
}
}
}
}
public function importEnterpriseInfo()
{
$spreadsheet = IOFactory::load('33.xlsx');
$objWorksheet = $spreadsheet->getSheet(0); // 只允许读取第一页,多页请分开文档
$data = $objWorksheet->toArray();
$list = [];
foreach ($data as $index=>$value){
if($index>1){
//enterprise_name
//enterprise_id
//enterprise_website_official
//unavailable
$timestamp = time(); // 当前时间戳
$randomNumber = mt_rand(100000, 999999); // 生成一个六位的随机数
$uniqueIdentifier = $timestamp . $randomNumber; // 时间戳和随机数拼接
$arr=[
'enterprise_name'=>$value[1],
'enterprise_id'=>$uniqueIdentifier,
'enterprise_website_official'=>$value[2],
'unavailable'=>$value[3],
];
$res = Db::name('enterprise_info')->where('enterprise_name',$value[1])->find();
if(empty($res)){
Db::name('enterprise_info')->insert($arr);
}else{
if($res['unavailable'] !=$value[3]){
Db::name('enterprise_info')->where('id',$res['id'])->update(['unavailable'=>$value[3]]);
}
}
}
}
}
} }
\ No newline at end of file
...@@ -95,6 +95,14 @@ Route::rule("productAllocation/see","productAllocation/see"); ...@@ -95,6 +95,14 @@ Route::rule("productAllocation/see","productAllocation/see");
Route::rule("productAllocation/save","productAllocation/save"); Route::rule("productAllocation/save","productAllocation/save");
Route::rule("productAllocation/abnormal","productAllocation/abnormal"); Route::rule("productAllocation/abnormal","productAllocation/abnormal");
Route::rule("productAllocation/randomAllocation","productAllocation/randomAllocation");
Route::rule("productAllocation/importProduct","productAllocation/importProduct");
Route::rule("enterpriseAllocation/list","EnterpriseAllocation/list");
Route::rule("enterpriseAllocation/equalDistributionEnterprise","EnterpriseAllocation/equalDistributionEnterprise");
Route::rule("task/list","Task/list");
Route::rule("service/product","Service/product"); Route::rule("service/product","Service/product");
Route::rule("service/product1","Service/product1"); Route::rule("service/product1","Service/product1");
......
<?php
/**
*
*/
namespace app\common\model\mysql;
use think\Model;
class EnterpriseAllocation extends Model
{
protected $name = 'enterprise_allocation';
// protected $createTime = 'create_at';
// protected $updateTime = 'update_at';
// // 定义更新的时间戳字段名
//// protected $autoWriteTimestamp = ['update_time'];
/**
* 关联权限组信息
* @return \think\model\relation\HasMany
*/
public function enterpriseInfo()
{
try{
return $this->hasOne('EnterpriseInfo','id','enterprise_id');
}catch (\Exception $e){
exception($e,'mysql.'.$this->name.'.enterpriseInfo');
}
}
/**
* 关联权限组信息
* @return \think\model\relation\HasMany
*/
public function adminInfo()
{
try{
return $this->hasOne('Admin','id','user_id');
}catch (\Exception $e){
exception($e,'mysql.'.$this->name.'.adminInfo');
}
}
}
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