Commit 74687d61 by hcy001
parents fdc05aec fc42f9c6
Showing with 33 additions and 26 deletions
......@@ -332,7 +332,6 @@ class QuoteModel extends Model
$classArr = (new SearchModel())->getClassName(\GuzzleHttp\json_encode($param));
$CommonModel = new CommonModel;
$rate = $CommonModel->getRate();
#拼接批量插入明细
foreach ($input as $k=>&$v){
......@@ -345,19 +344,23 @@ class QuoteModel extends Model
}
}
if ($v['currency'] == 2) {
$v['price_rmb'] = $rate ? number_format($v['price_origin'] * $rate, 6) : 0; // 美元需计算汇率(排序用)
if ($v['currency'] != 1) {
$rate = $CommonModel->getRate($v['currency']);
$v['price_rmb'] = $rate ? number_format($v['price_origin'] * $rate, 6) : 0; // 需计算汇率(排序用)
}
$quote_sn = $this->where(["inquiry_items_id"=>$inquiry_items_id,"raw_goods_sn"=>$v["raw_goods_sn"]])->value("quote_sn");
if ($quote_sn){ #存在更新
$v["create_time"] = time();
$this->where(["inquiry_items_id"=>$inquiry_items_id,"raw_goods_sn"=>$v["raw_goods_sn"]])->update($v) ;
$currency_sign = array_get(Config('quote.currency_sign'), $v['currency'], '¥');
OpLogModel::log([
'types'=>2,
'relation_id'=>$inquiry_items_id,
'relation_sn'=>$quote_sn,
'content'=>'自动报价-更新,价格:'+($v["currency"] == "1" ? "¥".$v["price_rmb"] : "$".$v["price_origin"]),
'content'=>'自动报价-更新,价格:'+($v["currency"] == "1" ? "¥".$v["price_rmb"] : $currency_sign.$v["price_origin"]),
'create_name'=>"系统",
]);
}else{
......@@ -419,8 +422,11 @@ class QuoteModel extends Model
unset($quote_info['brand_s']);
$CommonModel = new CommonModel;
if ($quote_info['currency'] == 2) {
$rate = $CommonModel->getRate();
if ($quote_info['currency'] != 1) {
$currency_val = array_get(Config('quote.currency'), $quote_info['currency'], '美元');
$rate = $CommonModel->getRate($currency_val);
$quote_info['price_rmb'] = $rate ? number_format($quote_info['price_origin'] * $rate, 6) : 0;
}
......@@ -479,11 +485,7 @@ class QuoteModel extends Model
$InquiryModel = new InquiryModel;
$inquiry_uid = $InquiryModel->where('id', $quote_info['inquiry_id'])->value('create_uid'); // 询价人
if ($quote_info['currency'] == 1) {
$price = '¥'.$quote_info['price_rmb'];
} else {
$price = '$'.$quote_info['price_origin'];
}
$price = array_get(Config('quote.currency_sign'), $quote_info['currency'], '¥').$quote_info['price_origin'];
$contents = $input['user_name'].'已报价,请及时查看!报价单号:'.$quote_info['quote_sn'].',型号:'.$quote_info['goods_name'].',单价:'.$price;
$CommonModel->send_msg($inquiry_uid, $contents);
......@@ -527,13 +529,13 @@ class QuoteModel extends Model
$ApiController = new ApiController;
$CommonModel = new CommonModel;
$rate = $CommonModel->getRate(); // 获取汇率
foreach ($excel as &$v) {
if ($v['currency'] == 'RMB') {
if ($v['currency'] == '人民币') {
$v['currency'] = 1;
} else {
$v['currency'] = 2;
$rate = $CommonModel->getRate($v['currency']); // 获取汇率
$v['currency'] = array_search($v['currency'], Config('quote.currency'));
$v['price_rmb'] = $rate ? number_format($v['price_origin'] * $rate, 6) : 0;
}
......@@ -554,7 +556,7 @@ class QuoteModel extends Model
$v['create_time'] = time();
$v['update_time'] = time();
}
dd($excel);
$res = $this->insert($excel); // 批量插入
if ($res === false) return [1, '添加报价草稿失败'];
......@@ -601,27 +603,32 @@ class QuoteModel extends Model
});
$required_keys = array_keys($required); // 必填项keys
$CommonModel = new CommonModel();
$err = []; // 提示信息
array_walk($excel, function($val, $key) use($required, $required_keys, &$err) {
// 跳过第一条
if ($key != 0) {
if ($val['currency'] == 'USD' && $val['price_origin'] <= 0) {
if ($val['goods_name']) { // 判断型号是否存在
}
if ($val['currency'] != '人民币' && $val['price_origin'] <= 0) {
$err[] = '第'.($key+1).'行,单价等于或小于0';
return;
}
if ($val['currency'] == 'USD' && !preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_origin'])) {
if ($val['currency'] != '人民币' && !preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_origin'])) {
$err[] = '第'.($key+1).'行,单价格式错误';
return;
}
if ($val['currency'] == 'RMB' && $val['price_rmb'] <= 0) {
if ($val['currency'] == '人民币' && $val['price_rmb'] <= 0) {
$err[] = '第'.($key+1).'行,含税价格等于或小于0';
return;
}
if ($val['currency'] == 'RMB' && !preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_rmb'])) {
if ($val['currency'] == '人民币' && !preg_match('/^\d{0,9}(\.\d{0,6})?$/', $val['price_rmb'])) {
$err[] = '第'.($key+1).'行,含税价格格式错误';
return;
}
......@@ -797,8 +804,10 @@ class QuoteModel extends Model
$CommonModel = new CommonModel;
if ($quote_info['currency'] == 2) {
$rate = $CommonModel->getRate();
if ($quote_info['currency'] != 1) {
$currency_val = array_get(Config('quote.currency'), $quote_info['currency'], '美元');
$rate = $CommonModel->getRate($currency_val);
$quote_info['price_rmb'] = $rate ? number_format($quote_info['price_origin'] * $rate, 6) : 0;
}
......@@ -828,11 +837,9 @@ class QuoteModel extends Model
$this->where('id', $input['quote_id'])->update($quote_info);
if ($quote_info['currency'] == 1) {
$price = '¥'.$quote_info['price_rmb'];
$price_log = '含税单价:'.$quote_info['price_rmb'];
$price_log = '含税单价:¥'.$quote_info['price_rmb'];
} else {
$price = '$'.$quote_info['price_origin'];
$price_log = '单价:'.$quote_info['price_origin'];
$price_log = '单价:'.array_get(Config('quote.currency_sign'), $quote_info['currency'], '¥').$quote_info['price_origin'];
}
$content = '修改报价,报价单号:'.$input['quote_sn'].',型号:'.$quote_info['goods_name'].','.$price_log.',批次:'.$quote_info['batch'].',货期:'.$quote_info['delivery_time'];
......
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