Commit 3c752037 by hcy001
parents 814339c1 cffeceaa
Showing with 48 additions and 20 deletions
...@@ -7,8 +7,9 @@ use App\map\QuoteMap; ...@@ -7,8 +7,9 @@ use App\map\QuoteMap;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Request; use Request;
use DB; use DB;
use App\Model\OplogModel; use App\Model\OpLogModel;
use App\Model\UserModel; use App\Model\UserModel;
use App\Model\InquiryItemsModel;
use App\Http\Controllers\PermController; use App\Http\Controllers\PermController;
use App\Http\Controllers\ApiController; use App\Http\Controllers\ApiController;
use RedisDB; use RedisDB;
...@@ -182,7 +183,7 @@ class QuoteModel extends Model ...@@ -182,7 +183,7 @@ class QuoteModel extends Model
return $data; return $data;
} }
// 撤销 // 撤销报价
public function cancel($input) public function cancel($input)
{ {
$id = $input['id']; $id = $input['id'];
...@@ -191,10 +192,13 @@ class QuoteModel extends Model ...@@ -191,10 +192,13 @@ class QuoteModel extends Model
if (!$id) return [-1, '参数缺失']; if (!$id) return [-1, '参数缺失'];
try { try {
$res = $this->where('id', $id)->update(['status' => -1, 'cancel_reason'=>$cancel_reason]);
$quote_info = $this->find($id); $quote_info = $this->find($id);
if ($quote_info['status'] == -1) return [1, '该报价已撤销,请刷新页面查看'];
if ($quote_info['status'] > 1) return [1, '当前报价状态不能撤销,请刷新页面查看'];
$res = $this->where('id', $id)->update(['status' => -1, 'cancel_reason'=>$cancel_reason]);
$UserModel = new UserModel; $UserModel = new UserModel;
$data = []; $data = [];
...@@ -205,7 +209,7 @@ class QuoteModel extends Model ...@@ -205,7 +209,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -221,24 +225,36 @@ class QuoteModel extends Model ...@@ -221,24 +225,36 @@ class QuoteModel extends Model
if (!$quote_info) return [1, '报价数据不存在']; if (!$quote_info) return [1, '报价数据不存在'];
try { try {
$res = $this->create($quote_info); // 询价明细单状态
$inquiry_items_status = InquiryItemsModel::where('id', $quote_info['inquiry_items_id'])->value('status');
if ($inquiry_items_status == -1) return [1, '新增报价失败,该询价明细已关闭'];
$UserModel = new UserModel;
$create_name = $UserModel->FinduserInfoName($input['user_id']);
$quote_info['status'] = 1; // 已报价
$quote_info['create_uid'] = $input['user_id'];
$quote_info['create_uid'] = $create_name;
$res = $this->create($quote_info);
if ($res === false) return [2, '新增报价失败']; if ($res === false) return [2, '新增报价失败'];
if ($inquiry_items_status == 1) { // 询价明细为待报价时,更新为已报价
InquiryItemsModel::where('id', $quote_info['inquiry_items_id'])->update(['status' => 2]);
}
// 通知询价人,放入redis // 通知询价人,放入redis
RedisDB::set('frq_quote_urge', $quote_info['inquiry_items_id']); RedisDB::set('frq_quote_urge', $quote_info['inquiry_items_id']);
$UserModel = new UserModel;
$data = []; $data = [];
$data['types'] = 2; $data['types'] = 2;
$data['relation_id'] = $quote_info['inquiry_items_id']; $data['relation_id'] = $quote_info['inquiry_items_id'];
$data['relation_sn'] = ''; $data['relation_sn'] = '';
$data['content'] = '新增报价,报价单号:'.$quote_info['quote_sn']; $data['content'] = '新增报价,报价单号:'.$quote_info['quote_sn'];
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $create_name;
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -249,6 +265,10 @@ class QuoteModel extends Model ...@@ -249,6 +265,10 @@ class QuoteModel extends Model
// 报价导入 // 报价导入
public function import($input) public function import($input)
{ {
// 询价明细单状态
$inquiry_items_status = InquiryItemsModel::where('id', $input['inquiry_items_id'])->value('status');
if ($inquiry_items_status == -1) return [1, '导入报价失败,该询价明细已关闭'];
$file = $_FILES['file']; // $request->file('file') $file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径 $filePath = $file['tmp_name']; // 临时路径
...@@ -300,7 +320,7 @@ class QuoteModel extends Model ...@@ -300,7 +320,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -418,7 +438,7 @@ class QuoteModel extends Model ...@@ -418,7 +438,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -431,6 +451,10 @@ class QuoteModel extends Model ...@@ -431,6 +451,10 @@ class QuoteModel extends Model
{ {
if (!$input['inquiry_items_id']) return [-1, '参数缺失']; if (!$input['inquiry_items_id']) return [-1, '参数缺失'];
// 询价明细单状态
$inquiry_items_status = InquiryItemsModel::where('id', $input['inquiry_items_id'])->value('status');
if ($inquiry_items_status == -1) return [1, '批量提交报价失败,该询价明细已关闭'];
try { try {
$map = []; $map = [];
$map['inquiry_items_id'] = $input['inquiry_items_id']; $map['inquiry_items_id'] = $input['inquiry_items_id'];
...@@ -443,6 +467,10 @@ class QuoteModel extends Model ...@@ -443,6 +467,10 @@ class QuoteModel extends Model
$this->where($map)->update(['status' => 1]); $this->where($map)->update(['status' => 1]);
if ($inquiry_items_status == 1) { // 询价明细为待报价时,更新为已报价
InquiryItemsModel::where('id', $input['inquiry_items_id'])->update(['status' => 2]);
}
// 通知询价人,放入redis // 通知询价人,放入redis
RedisDB::sadd('frq_quote_urge', $input['inquiry_items_id']); RedisDB::sadd('frq_quote_urge', $input['inquiry_items_id']);
...@@ -456,7 +484,7 @@ class QuoteModel extends Model ...@@ -456,7 +484,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -482,7 +510,7 @@ class QuoteModel extends Model ...@@ -482,7 +510,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; return [1, $e->getMessage()];
} }
...@@ -502,7 +530,7 @@ class QuoteModel extends Model ...@@ -502,7 +530,7 @@ class QuoteModel extends Model
$start_time = $curr_zero_time + $i * 3600; $start_time = $curr_zero_time + $i * 3600;
$end_time = $start_time + 3600; $end_time = $start_time + 3600;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time); $data['today_quote'][] = $this->getTodayQoutCount($input, $start_time, $end_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time); $data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = $i.'点'; $data['x_axis_data'][] = $i.'点';
} }
...@@ -513,7 +541,7 @@ class QuoteModel extends Model ...@@ -513,7 +541,7 @@ class QuoteModel extends Model
$start_time = $curr_zero_time - $i * 86400; $start_time = $curr_zero_time - $i * 86400;
$end_time = $start_time + 86399; $end_time = $start_time + 86399;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time); $data['today_quote'][] = $this->getTodayQoutCount($input, $start_time, $end_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time); $data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400); $data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400);
} }
...@@ -524,7 +552,7 @@ class QuoteModel extends Model ...@@ -524,7 +552,7 @@ class QuoteModel extends Model
$start_time = $curr_zero_time - $i * 86400; $start_time = $curr_zero_time - $i * 86400;
$end_time = $start_time + 86399; $end_time = $start_time + 86399;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time); $data['today_quote'][] = $this->getTodayQoutCount($input, $start_time, $end_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time); $data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400); $data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400);
} }
...@@ -536,9 +564,9 @@ class QuoteModel extends Model ...@@ -536,9 +564,9 @@ class QuoteModel extends Model
} }
// 当日报价数 // 当日报价数
public function getTodayQoutCount($input, $start_time) public function getTodayQoutCount($input, $start_time, $end_time)
{ {
return $this->where('create_uid', $input['user_id'])->where('create_time', '>=', $start_time)->count(); return $this->where('create_uid', $input['user_id'])->whereBetween('create_time', [$start_time, $end_time])->count();
} }
// 当日未报价数 // 当日未报价数
...@@ -574,7 +602,7 @@ class QuoteModel extends Model ...@@ -574,7 +602,7 @@ class QuoteModel extends Model
$data['create_uid'] = $input['user_id']; $data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']); $data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data); OpLogModel::log($data);
} catch (Exception $e) { } catch (Exception $e) {
return [1, $e->getMessage()]; 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