Commit d7438df8 by hcy001

1

parent 1d20524a
Showing with 61 additions and 66 deletions
......@@ -26,7 +26,7 @@ class QuoteModel extends Model
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
return strtotime(parent::fromDateTime($value));
}
//单个明细分页列表
......@@ -96,46 +96,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 {
......@@ -143,9 +143,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) {
......@@ -171,7 +171,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'];
......@@ -184,32 +184,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, '撤销成功'];
}
// 新增
......@@ -245,14 +245,13 @@ class QuoteModel extends Model
return [0, '新增报价成功'];
}
// 报价导入
// 报价导入
public function import($input)
{
$inquiry_id = @$input["inquiry_id"];
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
// 获取导入内容
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0);
......@@ -261,14 +260,10 @@ class QuoteModel extends Model
if (empty($excel)) return [1, '未获取到模板内容,请检查模板内容数据格式'];
$map = Config('quote.import_quote_map');
if (count($map) != count($excel[0])) return [2, '导入模板错误'];
$excel = $this->handleExcelData($excel, $map); // 处理数据
print_r($excel);
$valid = $this->excelValid($excel); // 验证excel内容
if ($valid[0] != 0) return $valid;
......@@ -303,7 +298,7 @@ class QuoteModel extends Model
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
}
return [0, '批量导入报价成功'];
}
......@@ -346,9 +341,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 +351,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 +364,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 +398,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 +413,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 +451,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