Commit bb9ed0d9 by 朱继来

merge

parents ea8e2f5f d7438df8
......@@ -71,7 +71,7 @@ class ApiController extends Controller
}
//创建询价明细
private function ApiCreateOneItems($input, $id){
Export((new InquiryItemsModel())->addItems(1,[$input]));
Export((new InquiryItemsModel())->addItems($input));
}
//更新询价明细
private function ApiUpdateOneItems($input, $id){
......@@ -165,6 +165,11 @@ class ApiController extends Controller
{
Export((new QuoteModel())->import($input));
}
// 批量导入询价
public function ApiImportInquiry($input, $id)
{
Export((new InquiryItemsModel())->import($input));
}
// 删除报价草稿
public function ApiDeleteQuoteDraft($input, $id)
......
......@@ -10,11 +10,44 @@ use DB;
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");
echo json_encode($brandInfo,JSON_UNESCAPED_UNICODE) ;
exit();
$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) ;
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
......@@ -48,14 +81,6 @@ class CommonModel extends Model
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)
{
......
......@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
use App\Model\OplogModel;
use App\Model\UserModel;
use DB;
use Excel;
class InquiryItemsModel extends Model
{
......@@ -124,7 +125,7 @@ class InquiryItemsModel extends Model
return [0, '领取成功,请及时报价'];
}
//删除列表
//清空列表
public function DeleteInquiryItems($inquiry_id,$create_uid){
$check = (new InquiryModel())->where(["inquiry_id"=>$inquiry_id,"create_uid"=>$create_uid])->first();
if (!$check){
......@@ -173,74 +174,71 @@ class InquiryItemsModel extends Model
}
/*
* 创建询价明细,支持单个批量创建明细
* @param $types 插入类型: 1 单个添加 2 批量添加
* 创建单个批量创建明细
* @param $data 批量
*/
public function addItems($types,$data){
if (count($data) == 0 || $data == ""){
public function addItems($b){
if (count($b) == 0 || $b == ""){
return [1001,"插入数据不得为空"];
}
if (empty($b["inquiry_id"])) throw new Exception("询价单ID不得为空",1002);
if (empty($b["brand_s"])) throw new Exception("请选择型号名称",1002);
if (empty($b["inquiry_number"])) throw new Exception("请输入询价数量",1004);
if (empty($b["batch"])) throw new Exception("请输入批次要求",1005);
if (empty($b["delivery_time"])) throw new Exception("请选择交货日期",1006);
if (empty($b["brand_name"])) throw new Exception("请选择品牌名称",1003);
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);
$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["batch"])) throw new Exception("请输入批次要求",1005);
if (empty($b["delivery_time"])) throw new Exception("请选择交货日期",1006);
if (empty($b["brand_name"])) throw new Exception("请选择品牌名称",1003);
#插入明细
$brandInfo = json_decode($b["brand_s"],true);
$insertArr= [
"inquiry_id"=>$b["inquiry_id"] ,
"goods_name"=>@$b["goods_name"] ? $b["goods_name"] : "" ,
"brand_id"=>@$brandInfo[0]["brand_id"],
"brand_name"=>@$brandInfo[0]["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() ,
];
$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);
$inquiryItemsId = $this->insertGetId($insertArr);
if (count($purArr) > 0){
foreach ($purArr as $b=>$c){
array_push($assignInsert,[
"inquiry_items_id"=>$inquiryItemsId,
"assign_uid"=>$c["uid"],
"assign_name"=>$c["user_name"],
"create_time"=>time(),
]);
}
#插入指定领取人
if ($b["pur_s"] !== "" ){
$purArr = json_decode($b["pur_s"],true);
$assignInsert = []; #指定领取人
foreach ($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);
}
}
if(count($assignInsert) >0){ #插入指定人
(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();
return [0,"添加成功"];
......@@ -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
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;
}
}
......
......@@ -27,7 +27,7 @@ class QuoteModel extends Model
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
return strtotime(parent::fromDateTime($value));
}
//单个明细分页列表
......@@ -97,46 +97,46 @@ class QuoteModel extends Model
$field = ['q.id', 'q.inquiry_id', 'q.inquiry_sn', 'q.inquiry_items_id', 'q.quote_sn', 'q.source', 'q.price_origin', 'q.price_rmb', 'q.price_other', 'q.currency', 'q.goods_name as quote_goods_name', 'q.brand_name as quote_brand_name', 'q.supplier_id', 'q.supplier_name', 'q.quote_number', 'q.status', 'q.create_uid', 'q.create_name', 'q.delivery_time', 'q.batch', 'q.create_time', 'it.goods_name', 'it.brand_name', 'it.inquiry_number'];
$list = $this->from('quote as q')
->join('inquiry_items as it', 'q.inquiry_items_id', '=', 'it.id')
->where(function($query) use ($map) {
if ($map['inquiry_sn']) {
$query->where('q.inquiry_sn', '=', $map['inquiry_sn']);
}
->join('inquiry_items as it', 'q.inquiry_items_id', '=', 'it.id')
->where(function($query) use ($map) {
if ($map['inquiry_sn']) {
$query->where('q.inquiry_sn', '=', $map['inquiry_sn']);
}
if ($map['goods_name']) {
$query->where('it.goods_name', 'like', $map['goods_name'].'%');
}
if ($map['goods_name']) {
$query->where('it.goods_name', 'like', $map['goods_name'].'%');
}
if ($map['brand_name']) {
$query->where('it.brand_name', 'like', $map['brand_name'].'%');
}
if ($map['brand_name']) {
$query->where('it.brand_name', 'like', $map['brand_name'].'%');
}
if ($map['quote_sn']) {
$query->where('q.quote_sn', '=', $map['quote_sn']);
}
if ($map['quote_sn']) {
$query->where('q.quote_sn', '=', $map['quote_sn']);
}
if ($map['status']) {
$query->where('q.status', '=', $map['status']);
}
if ($map['status']) {
$query->where('q.status', '=', $map['status']);
}
// 创建时间
if(!empty($map['start_time']) && !empty($map['end_time'])) {
$query->whereBetween('q.create_time', [$map['start_time'], $map['end_time']]);
} else if(!empty($map['start_time'])) {
$query->where('q.create_time', '>=', $map['start_time']);
} else if(!empty($map['end_time'])) {
$query->where('q.create_time', '<=', $map['end_time']);
}
});
// 创建时间
if(!empty($map['start_time']) && !empty($map['end_time'])) {
$query->whereBetween('q.create_time', [$map['start_time'], $map['end_time']]);
} else if(!empty($map['start_time'])) {
$query->where('q.create_time', '>=', $map['start_time']);
} else if(!empty($map['end_time'])) {
$query->where('q.create_time', '<=', $map['end_time']);
}
});
if ($type == 1) {
$list = $list->where('q.create_uid', $input['user_id']);
$list = $list->where('q.create_uid', $input['user_id']);
} else if ($type == 2) {
$perm = new PermController;
$perm = new PermController;
$role = $perm->getUserRole($input['user_id'], $input['user_name']); // 用户角色
if ($role == 4) { // 采购查看下级
$sub_sale_ids = $perm->getSubSaleId($input['user_id']);
$sub_sale_ids = $perm->getSubSaleId($input['user_id']);
$list = $list->whereIn('q.create_uid', $sub_sale_ids);
}
} else {
......@@ -144,9 +144,9 @@ class QuoteModel extends Model
}
if ($map['create_uid']) { // 制单人
$list = $list->where('q.create_uid', $map['create_uid']);
$list = $list->where('q.create_uid', $map['create_uid']);
}
$list = $list->select($field)->orderBy('id', 'desc');
if ($export) {
......@@ -172,7 +172,7 @@ class QuoteModel extends Model
if (empty($data)) return $data;
foreach ($data as &$v) {
$currency_sign = $v['currency'] == 1 ? '¥' : '$';
$currency_sign = $v['currency'] == 1 ? '¥' : '$';
$v['currency_val'] = $v['currency'] == 1 ? 'RMB' : 'USD';
$v['price'] = $v['currency'] == 1 ? $currency_sign.$v['price_rmb'] : $currency_sign.$v['price_origin'];
......@@ -185,32 +185,32 @@ class QuoteModel extends Model
// 撤销
public function cancel($input)
{
$id = $input['id'];
$id = $input['id'];
$cancel_reason = $input['cancel_reason'];
if (!$id) return [-1, '参数缺失'];
if (!$id) return [-1, '参数缺失'];
try {
$res = $this->where('id', $id)->update(['status' => -1, 'cancel_reason'=>$cancel_reason]);
$res = $this->where('id', $id)->update(['status' => -1, 'cancel_reason'=>$cancel_reason]);
$quote_info = $this->find($id);
$quote_info = $this->find($id);
$UserModel = new UserModel;
$UserModel = new UserModel;
$data = [];
$data['types'] = 2;
$data['relation_id'] = $id;
$data['relation_sn'] = $quote_info['quote_sn'];
$data['content'] = '撤销报价,撤销原因:'.$cancel_reason.',报价单号:'.$quote_info['quote_sn'];
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
$data = [];
$data['types'] = 2;
$data['relation_id'] = $id;
$data['relation_sn'] = $quote_info['quote_sn'];
$data['content'] = '撤销报价,撤销原因:'.$cancel_reason.',报价单号:'.$quote_info['quote_sn'];
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data);
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
return [0, '撤销成功'];
return [0, '撤销成功'];
}
// 新增
......@@ -246,13 +246,13 @@ class QuoteModel extends Model
return [0, '新增报价成功'];
}
// 报价导入
// 报价导入
public function import($input)
{
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
// 获取导入内容
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0);
......@@ -264,7 +264,7 @@ class QuoteModel extends Model
$map = Config('quote.import_quote_map');
if (count($map) != count($excel[0])) return [2, '导入模板错误'];
$excel = $this->handleExcelData($excel, $map); // 处理数据
$excel = $this->handleExcelData($excel, $map); // 处理数据
$valid = $this->excelValid($excel); // 验证excel内容
if ($valid[0] != 0) return $valid;
......@@ -303,7 +303,7 @@ class QuoteModel extends Model
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
}
return [0, '批量导入报价成功'];
}
......@@ -346,9 +346,9 @@ class QuoteModel extends Model
}
if (!preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_origin'])) {
$err[] = '第'.($key+1).'行,单价格式错误';
$err[] = '第'.($key+1).'行,单价格式错误';
return;
}
}
if ($val['price_rmb'] <= 0) {
$err[] = '第'.($key+1).'行,含税价格等于或小于0';
......@@ -356,7 +356,7 @@ class QuoteModel extends Model
}
if (!preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_rmb'])) {
$err[] = '第'.($key+1).'行,含税价格格式错误';
$err[] = '第'.($key+1).'行,含税价格格式错误';
return;
}
......@@ -369,18 +369,18 @@ class QuoteModel extends Model
$err[] = '第'.($key+1).'行,报价数量等于或小于0';
return;
}
foreach ($val as $k=>$v) {
if (in_array($k, $required_keys)) {
if (empty($v)) { // 若必填项值为空,返回提示信息
$err[] = $required[$k].'列,第'.($key+1).'行不能为空';
$err[] = $required[$k].'列,第'.($key+1).'行不能为空';
break;
}
}
}
}
}
}
});
if (!empty($err)) return [1, implode('; ', $err)];
return [0, '验证成功'];
......@@ -403,7 +403,7 @@ class QuoteModel extends Model
$currency_val = 'USD';
$price = ',单价:'.$draft_info['price_origin'];
}
$content = '删除报价草稿,草稿报价型号:'.$draft_info['goods_name'].',品牌:'.$draft_info['brand_name'].',供应商:'.$draft_info['supplier_name'].',币种:'.$currency_val.$price;
$res = $this->where('id', $id)->delete();
......@@ -418,7 +418,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data);
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
......@@ -456,7 +456,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data);
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
......
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