Commit 96c3ef1e by cwy
parents f99fade5 b3bc53fa
...@@ -36,6 +36,7 @@ class EnterpriseAllocation extends AuthBase ...@@ -36,6 +36,7 @@ class EnterpriseAllocation extends AuthBase
} }
$result = $EnterpriseAllocationModel->with([ $result = $EnterpriseAllocationModel->with([
'enterpriseInfo' => function($query){ 'enterpriseInfo' => function($query){
// $query->where('assignable',1);
}, },
'adminInfo' => function($query){ 'adminInfo' => function($query){
}, },
...@@ -78,6 +79,7 @@ class EnterpriseAllocation extends AuthBase ...@@ -78,6 +79,7 @@ class EnterpriseAllocation extends AuthBase
$EnterpriseAllocationModel =new EnterpriseAllocationModel(); $EnterpriseAllocationModel =new EnterpriseAllocationModel();
$result = $EnterpriseAllocationModel->with([ $result = $EnterpriseAllocationModel->with([
'enterpriseInfo' => function($query){ 'enterpriseInfo' => function($query){
// $query->where('assignable',1);
}, },
'adminInfo' => function($query){ 'adminInfo' => function($query){
}, },
...@@ -136,6 +138,7 @@ class EnterpriseAllocation extends AuthBase ...@@ -136,6 +138,7 @@ class EnterpriseAllocation extends AuthBase
$enterpriseInfo = Db::name('enterprise_info') $enterpriseInfo = Db::name('enterprise_info')
->where('status',1) ->where('status',1)
->where('unavailable','可得') ->where('unavailable','可得')
->where('assignable',1)
->select(); ->select();
$userInfo = Db::name('admin') $userInfo = Db::name('admin')
->where('department_id',4) ->where('department_id',4)
......
...@@ -22,9 +22,9 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx; ...@@ -22,9 +22,9 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\facade\Db; use think\facade\Db;
class ProductAllocation extends Base class ProductAllocation extends AuthBase
{ public static $name = 'controller.ProductAllocation'; { public static $name = 'controller.ProductAllocation';
public static $productWhere = [];
/** /**
* 列表 * 列表
* @return \josn|void * @return \josn|void
...@@ -35,18 +35,48 @@ class ProductAllocation extends Base ...@@ -35,18 +35,48 @@ class ProductAllocation extends Base
// 数据接收 // 数据接收
$page = input("param.page",0,"intval"); $page = input("param.page",0,"intval");
$limit = input("param.limit",10,"intval"); $limit = input("param.limit",10,"intval");
$inspect_status = input("inspect_status");
$product_id = input("product_id");
$product_name = input("product_name");
$ProductAllocationModel =new ProductAllocationModel(); $ProductAllocationModel =new ProductAllocationModel();
$result = $ProductAllocationModel->with([ $where = [];
'productInfo' => function($query){ if($this->userId!=1){
}, $where[] = ['t1.user_id', '=',$this->userId];
'adminInfo' => function($query){ }
$query->where('status',1)->field("id,name"); if($product_id){
}, $where[] = ['t2.product_id', '=',$product_id];
])->where('user_id',8) }
if($product_name){
$where[] = ['t2.product_name', '=',$product_name];
}
if($inspect_status!=""){
$where[] = ['t2.inspect_status', '=',$inspect_status];
}
$result = Db::table('product_allocation')
->alias('t1')
->join('product t2','t1.product_id=t2.id')
->join('admin t3','t1.user_id=t3.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.*')
->where($where)
->paginate([ ->paginate([
'list_rows'=>$limit, 'list_rows'=>$limit,
'page'=>$page 'page'=>$page
]); ]);
// $result = $ProductAllocationModel->with([
// 'productInfo' => function($query){
//// $query->where(self::$productWhere);
// },
// 'adminInfo' => function($query){
// $query->where('status',1)->field("id,name");
// },
// ])->where($where)
// ->paginate([
// 'list_rows'=>$limit,
// 'page'=>$page
// ]);
if($result){ if($result){
$result = $result->toArray(); $result = $result->toArray();
return returnResult(config("config.code.success"),config("config.describe.success"),$result); return returnResult(config("config.code.success"),config("config.describe.success"),$result);
...@@ -96,6 +126,9 @@ class ProductAllocation extends Base ...@@ -96,6 +126,9 @@ class ProductAllocation extends Base
$EnterpriseInfoModel =new EnterpriseInfoModel(); $EnterpriseInfoModel =new EnterpriseInfoModel();
$AdminModel =new AdminModel(); $AdminModel =new AdminModel();
$productAllocationInfo = $ProductAllocationModel->where('id',$id)->find(); $productAllocationInfo = $ProductAllocationModel->where('id',$id)->find();
if(empty($productAllocationInfo)){
return returnResult(config("config.code.error"),'未找到相关信息!');
}
$productInfo = $ProductModel->where('id',$productAllocationInfo['product_id'])->find(); $productInfo = $ProductModel->where('id',$productAllocationInfo['product_id'])->find();
$enterpriseInfo = $EnterpriseInfoModel->where('id',$productInfo['enterprise_id'])->find(); $enterpriseInfo = $EnterpriseInfoModel->where('id',$productInfo['enterprise_id'])->find();
$adminInfo = $AdminModel->where('id',$productAllocationInfo['user_id'])->find(); $adminInfo = $AdminModel->where('id',$productAllocationInfo['user_id'])->find();
...@@ -112,7 +145,7 @@ class ProductAllocation extends Base ...@@ -112,7 +145,7 @@ class ProductAllocation extends Base
foreach ($info as $val){ foreach ($info as $val){
array_push($num,$val['id']); array_push($num,$val['id']);
} }
$index = array_search($val['id'], $num); $index = array_search($id, $num);
$front =$index-1; $front =$index-1;
$after = $index+1; $after = $index+1;
if ($front<0) { if ($front<0) {
...@@ -214,32 +247,32 @@ class ProductAllocation extends Base ...@@ -214,32 +247,32 @@ class ProductAllocation extends Base
$timestamp = time(); // 当前时间戳 $timestamp = time(); // 当前时间戳
$randomNumber = mt_rand(100000, 999999); // 生成一个六位的随机数 $randomNumber = mt_rand(100000, 999999); // 生成一个六位的随机数
$uniqueIdentifier = $timestamp . $randomNumber; // 时间戳和随机数拼接 $uniqueIdentifier = $timestamp . $randomNumber; // 时间戳和随机数拼接
$res = Db::name('enterprise_info')->where('enterprise_name',$value[1])->find(); $res = Db::name('enterprise_info')->where('enterprise_name',$value[1])->find();
if($res){ if($res){
$arr = [ $arr = [
'product_id'=>'RS'.$uniqueIdentifier, 'product_id'=>'RS'.$uniqueIdentifier,
'enterprise_id'=>$res['id'], 'enterprise_id'=>$res['id'],
'page_url'=>$value[4], 'page_url'=>$value[4],
'product_categ_name'=>$value[2], 'product_categ_name'=>$value[2],
'product_name'=>$value[3], 'product_name'=>$value[3],
'product_model'=>$value[5], 'product_model'=>$value[5],
'describe'=>$value[6], 'describe'=>$value[6],
'parameter'=>$value[7], 'parameter'=>$value[7],
]; ];
$product = Db::name('product') $product = Db::name('product')
->where('product_name',$value[3]) ->where('product_name',$value[3])
->where('page_url',$value[4]) ->where('page_url',$value[4])
->where('product_categ_name',$value[2]) ->where('product_categ_name',$value[2])
->where('product_model',$value[5]) ->where('product_model',$value[5])
->where('describe',$value[6]) ->where('describe',$value[6])
->where('parameter',$value[7]) ->where('parameter',$value[7])
->find(); ->find();
if(empty($product)){ if(empty($product)){
$product = Db::name('product')->insert($arr); $product = Db::name('product')->insert($arr);
} }
}else{ }else{
var_dump($value[1]); var_dump($value[1]);
} }
} }
} }
...@@ -277,4 +310,6 @@ class ProductAllocation extends Base ...@@ -277,4 +310,6 @@ class ProductAllocation extends Base
} }
} }
} }
} }
\ No newline at end of file
...@@ -142,4 +142,141 @@ class Test ...@@ -142,4 +142,141 @@ class Test
} }
} }
public function cee()
{
// $spreadsheet = IOFactory::load('未审核.xlsx');
// $objWorksheet = $spreadsheet->getSheet(0); // 只允许读取第一页,多页请分开文档
// $data = $objWorksheet->toArray();
// $list = [];
// foreach ($data as $index=>$value) {
// if ($index > 1) {
// if(!in_array($value[0],$list)){
// array_push($list,$value[0]);
// }
// }
// }
// foreach ($list as $val){
// Db::name('enterprise_info')->where('enterprise_name',$val)->update(['assignable'=>1]);
// }
$res = Db::name('enterprise_info')->where('enterprise_name','亿嘉和科技股份有限公司')->select();
dump($res);
}
public function exportData()
{
$result = Db::name('product')->where('status',1)->select();
$spreadsheet = new Spreadsheet();
$writer = new Xlsx($spreadsheet);
$spreadsheet->createSheet();
$spreadsheet->setActiveSheetIndex(0);
$spreadsheet->getActiveSheet(0)->setTitle('产品库');
$sheet = $spreadsheet->getActiveSheet(0);
$num = 0;
$row = 2;
foreach ($result as $index=>$value){
$info = Db::name('enterprise_info')->where('id',$value['enterprise_id'])->find();
$spreadsheet->getDefaultStyle()->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$spreadsheet->getDefaultStyle()->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$spreadsheet->getDefaultStyle()->getAlignment()->setWrapText(true);
$sheet->getDefaultRowDimension()->setRowHeight(50); // 默认行高
$sheet->getDefaultColumnDimension()->setWidth(50); // 默认单元格宽度
$sheet->getStyle('A1:J1')->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('C5D9F1'); // FF后面的六位数是颜色的RGB值
$title = [
'产品ID',
'企业名称',
'产品分类',
'产品名称',
'产品链接',
'产品型号',
'产品功能描述',
'产品规格参数',
'检查备注',
'检查状态',
];
$col = 'A';
$column = ['A'];
for ($coli = 0; $coli < count($title); $coli++) {
$col= \app\api\business\ExcelBus::excelColPlus($col);
array_push($column,$col);
}
// 遍历标题数组,设置每个单元格的值
foreach ($title as $columns => $val) {
// 'A1', 'B1', 'C1', ...
$cell = $column[$columns] . '1';
// 设置单元格的值
$sheet->setCellValue($cell, $val);
// 设置单元格A1的对齐方式为居中
}
$position = 0;
$sheet = $spreadsheet->getActiveSheet();
// 名称
$sheet->setCellValue($column[$num+$position].$row, $value['product_id']);
$position++;
// 名称
$sheet->setCellValue($column[$num+$position].$row, $info['enterprise_name']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['product_categ_name']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['product_name']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['page_url']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['product_model']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['describe']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['parameter']);
$position++;
// 位置
$sheet->setCellValue($column[$num+$position].$row, $value['inspect_remarks']);
$position++;
$inspect_status = $value['inspect_status'];
if($inspect_status == 0){
$inspect_status = '待检查';
}
if($inspect_status == 1){
$inspect_status = '检查完成';
}
if($inspect_status == 2){
$inspect_status = '检查中';
}
if($inspect_status == 3){
$inspect_status = '数据异常';
}
if($inspect_status == 4){
$inspect_status = '检查异常';
}
if($inspect_status == 5){
$inspect_status = '数据废弃';
}
// 位置
$sheet->setCellValue($column[$num+$position].$row, $inspect_status);
$position++;
$row++;
}
$name ='./product_'.date('Y-m-d H:i:s').'.csv';
$writer->save($name);
}
} }
\ No newline at end of file
...@@ -88,11 +88,12 @@ Route::rule("product/save","Product/save"); ...@@ -88,11 +88,12 @@ Route::rule("product/save","Product/save");
Route::rule("product/delete","Product/delete"); Route::rule("product/delete","Product/delete");
Route::rule("product/add","Product/add"); Route::rule("product/add","Product/add");
Route::rule("product/unallocatedProducts","product/unallocatedProducts"); // 未分配的产品列表 Route::rule("product/unallocatedProducts","product/unallocatedProducts");
Route::rule("productAllocation/add","productAllocation/add"); Route::rule("productAllocation/add","productAllocation/add");
Route::rule("productAllocation/list","productAllocation/list"); Route::rule("productAllocation/list","productAllocation/list");
Route::rule("productAllocation/see","productAllocation/see"); 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/randomAllocation","productAllocation/randomAllocation"); Route::rule("productAllocation/randomAllocation","productAllocation/randomAllocation");
Route::rule("productAllocation/importProduct","productAllocation/importProduct"); Route::rule("productAllocation/importProduct","productAllocation/importProduct");
...@@ -102,10 +103,14 @@ Route::rule("task/add","Task/add"); ...@@ -102,10 +103,14 @@ Route::rule("task/add","Task/add");
Route::rule("enterpriseAllocation/list","EnterpriseAllocation/list"); Route::rule("enterpriseAllocation/list","EnterpriseAllocation/list");
Route::rule("enterpriseAllocation/userEnterpriseList","EnterpriseAllocation/userEnterpriseList"); Route::rule("enterpriseAllocation/userEnterpriseList","EnterpriseAllocation/userEnterpriseList");
Route::rule("enterpriseAllocation/equalDistributionEnterprise","EnterpriseAllocation/equalDistributionEnterprise");
//Route::rule("enterpriseAllocation/equalDistributionEnterprise","EnterpriseAllocation/equalDistributionEnterprise");
Route::rule("service/product","Service/product"); Route::rule("service/product","Service/product");
Route::rule("service/product1","Service/product1"); Route::rule("service/product1","Service/product1");
Route::rule("service/enterpriseName","Service/enterpriseName"); Route::rule("service/enterpriseName","Service/enterpriseName");
Route::rule("test","test/product"); Route::rule("test","test/product");
\ No newline at end of file Route::rule("cee","test/cee");
Route::rule("exportData","test/exportData");
File added
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