Commit bb9ed0d9 by 朱继来

merge

parents ea8e2f5f d7438df8
...@@ -71,7 +71,7 @@ class ApiController extends Controller ...@@ -71,7 +71,7 @@ class ApiController extends Controller
} }
//创建询价明细 //创建询价明细
private function ApiCreateOneItems($input, $id){ private function ApiCreateOneItems($input, $id){
Export((new InquiryItemsModel())->addItems(1,[$input])); Export((new InquiryItemsModel())->addItems($input));
} }
//更新询价明细 //更新询价明细
private function ApiUpdateOneItems($input, $id){ private function ApiUpdateOneItems($input, $id){
...@@ -165,6 +165,11 @@ class ApiController extends Controller ...@@ -165,6 +165,11 @@ class ApiController extends Controller
{ {
Export((new QuoteModel())->import($input)); Export((new QuoteModel())->import($input));
} }
// 批量导入询价
public function ApiImportInquiry($input, $id)
{
Export((new InquiryItemsModel())->import($input));
}
// 删除报价草稿 // 删除报价草稿
public function ApiDeleteQuoteDraft($input, $id) public function ApiDeleteQuoteDraft($input, $id)
......
...@@ -10,11 +10,44 @@ use DB; ...@@ -10,11 +10,44 @@ use DB;
class CommonModel extends Model class CommonModel extends Model
{ {
//搜索联营品牌 //搜索联营品牌
public function BrandList($k) public function BrandList($k,$types=1)
{ {
$brandInfo = DB::connection("spu")->select("select brand_id as value,brand_name as name from lie_brand where brand_name like '%".$k."%' limit 10"); $dbspu = DB::connection("spu");
if ($types == 1) { #模糊搜索
$brandInfo = $dbspu->select("select brand_id as value,brand_name as name from lie_brand where brand_name like '%".$k."%' limit 10");
echo json_encode($brandInfo,JSON_UNESCAPED_UNICODE) ; echo json_encode($brandInfo,JSON_UNESCAPED_UNICODE) ;
exit(); exit();
}else{
$brandInfo = $dbspu->select("select brand_id as brand_id,brand_name as name from lie_brand where brand_name = '".$k."' limit 1");
if (!$brandInfo){
return false;
}else{
return $brandInfo[0]["brand_id"];
}
}
}
/*
* 查询采购名称
*/
public function UserList($k,$types = 1){
$dbcms = DB::connection();
if ($types == 1) { #模糊搜索
$purInfo = $dbcms->select("select userId as value,name as name from user_info where name like '%".$k."%' limit 10");
echo json_encode($purInfo,JSON_UNESCAPED_UNICODE) ;
exit();
}else{
$k = explode(",",$k);
$str = [];
foreach ($k as $k=>$b){
$purInfo = $dbcms->select("select userId as uid,name as user_name from user_info where name = '".$b."'");
if (!$purInfo){
return false;
}
array_push($str,["uid"=>$purInfo[0]["uid"],"user_name"=>$purInfo[0]["user_name"]]);
}
return $str;
}
} }
//导出pdf //导出pdf
...@@ -48,14 +81,6 @@ class CommonModel extends Model ...@@ -48,14 +81,6 @@ class CommonModel extends Model
echo json_encode($temp,JSON_UNESCAPED_UNICODE) ; echo json_encode($temp,JSON_UNESCAPED_UNICODE) ;
} }
/*
* 查询采购名称
*/
public function UserList($k){
$purInfo = DB::connection()->select("select userId as value,name as name from user_info where name like '%".$k."%' limit 10");
echo json_encode($purInfo,JSON_UNESCAPED_UNICODE) ;
}
// 搜索供应商 // 搜索供应商
public function SupplierList($k) public function SupplierList($k)
{ {
......
...@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model; ...@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
use App\Model\OplogModel; use App\Model\OplogModel;
use App\Model\UserModel; use App\Model\UserModel;
use DB; use DB;
use Excel;
class InquiryItemsModel extends Model class InquiryItemsModel extends Model
{ {
...@@ -124,7 +125,7 @@ class InquiryItemsModel extends Model ...@@ -124,7 +125,7 @@ class InquiryItemsModel extends Model
return [0, '领取成功,请及时报价']; return [0, '领取成功,请及时报价'];
} }
//删除列表 //清空列表
public function DeleteInquiryItems($inquiry_id,$create_uid){ public function DeleteInquiryItems($inquiry_id,$create_uid){
$check = (new InquiryModel())->where(["inquiry_id"=>$inquiry_id,"create_uid"=>$create_uid])->first(); $check = (new InquiryModel())->where(["inquiry_id"=>$inquiry_id,"create_uid"=>$create_uid])->first();
if (!$check){ if (!$check){
...@@ -173,45 +174,31 @@ class InquiryItemsModel extends Model ...@@ -173,45 +174,31 @@ class InquiryItemsModel extends Model
} }
/* /*
* 创建询价明细,支持单个批量创建明细 * 创建单个批量创建明细
* @param $types 插入类型: 1 单个添加 2 批量添加
* @param $data 批量 * @param $data 批量
*/ */
public function addItems($types,$data){ public function addItems($b){
if (count($data) == 0 || $data == ""){ if (count($b) == 0 || $b == ""){
return [1001,"插入数据不得为空"]; return [1001,"插入数据不得为空"];
} }
if (empty($b["inquiry_id"])) throw new Exception("询价单ID不得为空",1002);
try{
$con = DB::connection('rfq');
$con->beginTransaction();
$assignInsert = []; #指定领取人
foreach ($data as $k=>&$b){
if ($b["inquiry_id"] == "" ){
throw new Exception("询价单ID不得为空",10001);
}
if ($types == 1){ #单个添加
if (empty($b["brand_s"])) throw new Exception("请选择型号名称",1002); if (empty($b["brand_s"])) throw new Exception("请选择型号名称",1002);
$brandInfo = json_decode($b["brand_s"],true);
$b["brand_id"] = $brandInfo[0]["brand_id"];
$b["brand_name"] = $brandInfo[0]["brand_name"];
$purArr = json_decode($b["pur_s"],true);
}else{
$purArr = $b["purArr"];
}
if (empty($b["goods_name"])) throw new Exception("请选择型号名称",1002);
if (empty($b["inquiry_number"])) throw new Exception("请输入询价数量",1004); if (empty($b["inquiry_number"])) throw new Exception("请输入询价数量",1004);
if (empty($b["batch"])) throw new Exception("请输入批次要求",1005); if (empty($b["batch"])) throw new Exception("请输入批次要求",1005);
if (empty($b["delivery_time"])) throw new Exception("请选择交货日期",1006); if (empty($b["delivery_time"])) throw new Exception("请选择交货日期",1006);
if (empty($b["brand_name"])) throw new Exception("请选择品牌名称",1003); if (empty($b["brand_name"])) throw new Exception("请选择品牌名称",1003);
try{
$con = DB::connection('rfq');
$con->beginTransaction();
#插入明细
$brandInfo = json_decode($b["brand_s"],true);
$insertArr= [ $insertArr= [
"inquiry_id"=>$b["inquiry_id"] , "inquiry_id"=>$b["inquiry_id"] ,
"goods_name"=>@$b["goods_name"] ? $b["goods_name"] : "" , "goods_name"=>@$b["goods_name"] ? $b["goods_name"] : "" ,
"brand_id"=>@$b["brand_id"] ? $b["brand_id"] : 0, "brand_id"=>@$brandInfo[0]["brand_id"],
"brand_name"=>@$b["brand_name"] ? $b["brand_name"] : "", "brand_name"=>@$brandInfo[0]["brand_name"],
"class_id2"=>@$b["class_id2"] ? $b["class_id2"] : 0 , "class_id2"=>@$b["class_id2"] ? $b["class_id2"] : 0 ,
"class_id2_name"=>@$b["class_id2_name"] ? $b["class_id2_name"] : "" , "class_id2_name"=>@$b["class_id2_name"] ? $b["class_id2_name"] : "" ,
"inquiry_number"=>@$b["inquiry_number"] ? $b["inquiry_number"] :0 , "inquiry_number"=>@$b["inquiry_number"] ? $b["inquiry_number"] :0 ,
...@@ -223,10 +210,13 @@ class InquiryItemsModel extends Model ...@@ -223,10 +210,13 @@ class InquiryItemsModel extends Model
"create_time"=>time() , "create_time"=>time() ,
"update_time"=>time() , "update_time"=>time() ,
]; ];
#插入明细
$inquiryItemsId = $this->insertGetId($insertArr); $inquiryItemsId = $this->insertGetId($insertArr);
if (count($purArr) > 0){ #插入指定领取人
if ($b["pur_s"] !== "" ){
$purArr = json_decode($b["pur_s"],true);
$assignInsert = []; #指定领取人
foreach ($purArr as $b=>$c){ foreach ($purArr as $b=>$c){
array_push($assignInsert,[ array_push($assignInsert,[
"inquiry_items_id"=>$inquiryItemsId, "inquiry_items_id"=>$inquiryItemsId,
...@@ -235,12 +225,20 @@ class InquiryItemsModel extends Model ...@@ -235,12 +225,20 @@ class InquiryItemsModel extends Model
"create_time"=>time(), "create_time"=>time(),
]); ]);
} }
}
}
if(count($assignInsert) >0){ #插入指定人 if(count($assignInsert) >0){ #插入指定人
(new InquiryItemsAssignModel())->insert($assignInsert); (new InquiryItemsAssignModel())->insert($assignInsert);
} }
}
#日志
OplogModel::log([
'types'=>1,
'relation_id'=>$b["inquiry_id"],
'relation_sn'=>(new InquiryModel())->FindInquirySn($b["inquiry_id"]),
'content'=>'批量导入询价',
'create_uid'=>$b['user_id'],
'create_name'=>$b["user_name"],
]);
$con->commit(); $con->commit();
return [0,"添加成功"]; return [0,"添加成功"];
...@@ -315,5 +313,172 @@ class InquiryItemsModel extends Model ...@@ -315,5 +313,172 @@ class InquiryItemsModel extends Model
} }
} }
//处理批量导入
public function import($input)
{
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
$inquiry_id = @$input["inquiry_id"];
$inquiry_sn = @$input["inquiry_sn"];
if (empty($inquiry_id)) return [1, '询价ID不得为空'];
if (empty($inquiry_sn)) return [1, '询价SN不得为空'];
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0);
$excel = $data->toArray();
}, 'GBK');
if (empty($excel)) return [1, '未获取到模板内容,请检查模板内容数据格式'];
$goodsData = $this->excelValid($excel,$inquiry_id); // 验证拼接批量插入excel内容
if ($goodsData[0] != 0) return $goodsData;
try{
$con = DB::connection('rfq');
$con->beginTransaction();
$assignInsert = []; #指定领取人
foreach ($goodsData[1] as $k=>&$b){
$insertArr= [
"inquiry_id"=>$b["inquiry_id"] ,
"goods_name"=>@$b["goods_name"] ? $b["goods_name"] : "" ,
"brand_id"=>@$b["brand_id"] ? $b["brand_id"] : 0,
"brand_name"=>@$b["brand_name"] ? $b["brand_name"] : "",
"class_id2"=>@$b["class_id2"] ? $b["class_id2"] : 0 ,
"class_id2_name"=>@$b["class_id2_name"] ? $b["class_id2_name"] : "" ,
"inquiry_number"=>@$b["inquiry_number"] ? $b["inquiry_number"] :0 ,
"target_price"=>@$b["target_price"] ? $b["target_price"] : 0,
"delivery_time"=>@$b["delivery_time"] ? $b["delivery_time"] : "",
"batch"=>@$b["batch"] ? $b["batch"] : "" ,
"assign_type"=>@$b["assign_type"] ? $b["assign_type"] : 2,
"remark"=>@$b["remark"] ? $b["remark"] : "",
"create_time"=>time() ,
"update_time"=>time() ,
];
#插入明细
$inquiryItemsId = $this->insertGetId($insertArr);
#拼接指定人
if (@$b["purArr"]){
foreach ($b["purArr"] as $b=>$c){
array_push($assignInsert,[
"inquiry_items_id"=>$inquiryItemsId,
"assign_uid"=>$c["uid"],
"assign_name"=>$c["user_name"],
"create_time"=>time(),
]);
}
}
}
if(count($assignInsert) >0){ #插入指定人
(new InquiryItemsAssignModel())->insert($assignInsert);
}
#日志
OplogModel::log([
'types'=>1,
'relation_id'=>$inquiry_id,
'relation_sn'=>$inquiry_sn,
'content'=>'批量导入询价',
'create_uid'=>$input['user_id'],
'create_name'=>$input["user_name"],
]);
$con->commit();
return [0, '批量导入报价成功'];
}catch (\Exception $e) {
$con->rollBack();
return [1001,"添加失败:".$e->getMessage()];
}
}
// 验证导入excel
public function excelValid($excel,$inquiry_id)
{
$filer = [ //指定字段
"goods_name",
"brand_name",
"inquiry_number",
"target_price", //可空
"batch",
"delivery_time",
"assign", //指定采购,可空
];
$filer_need = [ //必填字段
"goods_name",
"brand_name",
"inquiry_number",
"batch",
"delivery_time",
];
#转换字段
$goodsInfo = [];
foreach ($excel as $k=>$v) {
if ($k == 0 ) continue; //排除第一行表头
$temp = [];
$c = 0;
foreach ($v as $a=>$b){
if (empty(trim($b))) $c ++;
$temp[$filer[$a]] = trim($b);
}
if ($c == count($v)) continue;
array_push($goodsInfo,$temp);
}
if (count($goodsInfo) == 1) return [3, '未填写报价信息'];
#验证数据
$CommonModel = new CommonModel();
$err = []; // 提示信息
foreach ($goodsInfo as $a2=>&$b2){
$b2["inquiry_id"] = $inquiry_id;
$hang = $a2+2; #对应excel第几行
foreach ($b2 as $key=>$val) {
$lie = $key+1;
$str_msg = '第'.$hang.'行'.$lie.'列:';
if (in_array($key, $filer_need) && empty($val)) {
$err[] = $str_msg.'数据不得为空';
continue;
}
switch ($key){
case "inquiry_number":
if (!preg_match('/\d/', intval($val))) {
$err[] = $str_msg.'请填写整数';
}
break;
case "target_price":
if ($val > 0 && !preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val)) {
$err[] = $str_msg.'目标单价格式错误';
}
break;
case "brand_name": #验证品牌
$brand_id = $CommonModel->BrandList($val,2);
if ($brand_id === false){
$err[] = $str_msg."系统不存在此品牌";
}
$b2["brand_id"] = $brand_id;
break;
case "assign": #验证指定采购员
if(empty($val)) break;
$userInfo = $CommonModel->UserList($val,2);
if ($userInfo === false){
$err[] = $str_msg."采购名称有误";
}
$b2["purArr"] = $userInfo;
break;
}
}
}
return count($err) == 0 ? [0, $goodsInfo] : [1, implode('; ', $err)];
}
} }
\ No newline at end of file
...@@ -294,6 +294,15 @@ class InquiryModel extends Model ...@@ -294,6 +294,15 @@ class InquiryModel extends Model
return $inqueryId; return $inqueryId;
} }
//生成草稿id
public function FindInquirySn($inquiry_id=''){
$result=$this->where('id','=',$inquiry_id)->select('inquiry_sn')->first();
if(!$result){
return false;
}else{
return $result->inquiry_sn;
}
}
......
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 sign in to comment