Commit 5b05f6ca by hcy001
parents 9a8f688f 9af9fe24
......@@ -46,6 +46,17 @@ class ApiController extends Controller
$this->$id($input, $id);
}
// 生成询报价单号
public function createSn($model, $field, $prefix='', $suffix='')
{
$sn = $prefix.time().rand(10000, 99999).$suffix;
$id = $model->where($field, $sn)->value('id');
if (!empty($id)) {
$sn = $this->createSn($prefix, $suffix);
}
return $sn;
}
//关闭整个询价单
private function ApiInquiryClose($input, $id){
Export((new InquiryModel())->inquiryClose($input));
......@@ -131,21 +142,22 @@ class ApiController extends Controller
}
//报价列表
public function ApiQuoteList($request, $id)
public function ApiQuoteList($input, $id)
{
ExportLayui((new QuoteModel())->lists($request));
ExportLayui((new QuoteModel())->lists($input));
}
// 撤销报价
public function ApiCancelQuote($request, $id)
public function ApiCancelQuote($input, $id)
{
Export((new QuoteModel())->cancel($request));
Export((new QuoteModel())->cancel($input));
}
// 新增报价
public function ApiAddQuote($request, $id)
public function ApiAddQuote($input, $id)
{
Export((new QuoteModel())->add($request));
$input['quote_info']['quote_sn'] = $this->createSn((new QuoteModel()), 'quote_sn', 'B');
Export((new QuoteModel())->add($input));
}
}
......@@ -10,6 +10,7 @@ use Request;
use DB;
use App\Http\Controllers\PermController;
use App\Model\InquiryItemsUrgeModel;
use RedisDB;
//询价
class InquiryModel extends Model
......@@ -165,7 +166,7 @@ class InquiryModel extends Model
if (empty($v)){
continue;
}
$query->whereIn('a.status', [-1,1]);
switch ($k){
case "inquiry_sn":
$query->where('a.inquiry_sn', '=', $v);
......@@ -193,11 +194,21 @@ class InquiryModel extends Model
}
}
$query->whereIn('a.status', [-1,1]);
if ($type == 1) {
$query->whereNotIn('b.status', [-1, 5])->where('b.assign_type', 0); // 询价池需过滤已关闭、已确认、指定和领取的询价
$time = time() - 7200; // 待报价的询价两小时后在询价池展示
$query->orWhereRaw('(lie_b.assign_type=1 and lie_b.status=1 and lie_b.create_time < '.$time.')');
}
});
// dump($list->getBindings());
// dump($list->toSql());
// $tmp = str_replace('?', '"'.'%s'.'"', $list->toSql());
// $tmp = vsprintf($tmp, $list->getBindings());
// echo $tmp;
// exit;
$page = isset($input['p']) ? $input['p'] : $input['page'];
$list= $list->orderBy('id','desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray();
......@@ -229,10 +240,11 @@ class InquiryModel extends Model
// 我的报价
$v['self_quote'] = $quote ? $currency_sign.$quote[$price_field].'('.array_get(Config('quote.quote_status'), $quote['status'], '').')' : '';
// 在Redis集合中检查用户是否被催报价
$res = RedisDB::sIsMember('frq_inquiry_items_urge', $v['id'].'-'.$user_id);
$urge = $InquiryItemsUrgeModel->getLastInfo($v['id']);
if ($urge) {
if ($res) {
$urge = $InquiryItemsUrgeModel->getLastInfo($v['id']);
$v['inquiry_sn'] = '<div title="'.$urge['remark'].'">'.$v['inquiry_sn'].'<i style="color:red;">(催)</i></div>';
}
}
......
......@@ -10,6 +10,7 @@ use DB;
use App\Model\OplogModel;
use App\Model\UserModel;
use App\Http\Controllers\PermController;
use RedisDB;
//报价
class QuoteModel extends Model
......@@ -17,6 +18,7 @@ class QuoteModel extends Model
protected $connection = 'rfq';
protected $table = 'quote';
protected $primaryKey = 'id';
protected $guarded = ['id'];
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
......@@ -75,20 +77,20 @@ class QuoteModel extends Model
}
// 获取报价列表
public function lists($request, $export='')
public function lists($input, $export='')
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$type = $request->input('type', 1); // 1-我的报价,2-所有报价
$map['inquiry_sn'] = $request->input('inquiry_sn', ''); // 询价单号
$map['goods_name'] = $request->input('goods_name', ''); // 型号
$map['brand_name'] = $request->input('brand_name', ''); // 品牌
$map['quote_sn'] = $request->input('quote_sn', ''); // 报价单号
$map['status'] = $request->input('status', ''); // 报价状态
$map['create_uid'] = $request->input('create_uid', ''); // 报价制单人
$map['start_time'] = $request->input('start_time', '') ? strtotime($request->input('start_time')) : '';
$map['end_time'] = $request->input('end_time', '') ? strtotime($request->input('end_time')) + 86399 : '';
$page = $input['page'];
$limit = $input['limit'];
$type = $input['type']; // 1-我的报价,2-所有报价
$map['inquiry_sn'] = isset($input['inquiry_sn']) ? $input['inquiry_sn'] : ''; // 询价单号
$map['goods_name'] = isset($input['goods_name']) ? $input['goods_name'] : ''; // 型号
$map['brand_name'] = isset($input['brand_name']) ? $input['brand_name'] : ''; // 品牌
$map['quote_sn'] = isset($input['quote_sn']) ? $input['quote_sn'] : ''; // 报价单号
$map['status'] = isset($input['status']) ? $input['status'] : ''; // 报价状态
$map['create_uid'] = isset($input['create_uid']) ? $input['create_uid'] : ''; // 报价制单人
$map['start_time'] = isset($input['start_time']) ? strtotime($input['start_time']) : '';
$map['end_time'] = isset($input['end_time']) ? strtotime($input['end_time']) + 86399 : '';
$field = ['q.id', 'q.inquiry_id', 'q.inquiry_sn', 'q.quote_sn', 'q.source', 'q.price_origin', 'q.price_rmb', 'q.price_other', 'q.currency', 'q.supplier_id', 'q.supplier_name', 'q.quote_number', 'q.status', 'q.create_uid', 'q.create_name', 'q.create_time', 'it.goods_name', 'it.brand_name', 'it.inquiry_number'];
......@@ -126,13 +128,13 @@ class QuoteModel extends Model
});
if ($type == 1) {
$list = $list->where('q.create_uid', $request->user->userId);
$list = $list->where('q.create_uid', $input['user_id']);
} else {
$perm = new PermController;
$role = $perm->getUserRole($request->user->userId, $request->user->name); // 用户角色
$role = $perm->getUserRole($input['user_id'], $input['user_name']); // 用户角色
if ($role == 4) { // 采购查看下级
$sub_sale_ids = $perm->getSubSaleId($request->user->userId);
$sub_sale_ids = $perm->getSubSaleId($input['user_id']);
$list = $list->whereIn('q.create_uid', $sub_sale_ids);
}
}
......@@ -175,10 +177,10 @@ class QuoteModel extends Model
}
// 撤销
public function cancel($request)
public function cancel($input)
{
$id = $request->input('id', 0);
$cancel_reason = $request->input('cancel_reason', '');
$id = $input['id'];
$cancel_reason = $input['cancel_reason'];
if (!$id) return [-1, '参数缺失'];
......@@ -193,8 +195,8 @@ class QuoteModel extends Model
$data['relation_id'] = $id;
$data['relation_sn'] = $quote_info['quote_sn'];
$data['content'] = '撤销报价,撤销原因:'.$cancel_reason.',报价单号:'.$quote_info['quote_sn'];
$data['create_uid'] = $request->user->userId;
$data['create_name'] = $UserModel->FinduserInfoName($request->user->userId);
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data);
......@@ -202,15 +204,40 @@ class QuoteModel extends Model
}
// 新增
public function add($request)
public function add($input)
{
$quote_info = $request->input('quote_info', '');
$quote_info = $input['quote_info'];
// 待转发到go接口
if (!$quote_info) return [1, '报价数据不存在'];
try {
$res = $this->create($quote_info);
if ($res === false) return [2, '新增报价失败'];
// 通知询价人,放入redis
RedisDB::set('frq_quote_urge', $quote_info['inquiry_items_id']);
$UserModel = new UserModel;
$data = [];
$data['types'] = 2;
$data['relation_id'] = $quote_info['inquiry_items_id'];
$data['relation_sn'] = '';
$data['content'] = '新增报价,报价单号:'.$quote_info['quote_sn'];
$data['create_uid'] = $input['user_id'];
$data['create_name'] = $UserModel->FinduserInfoName($input['user_id']);
OplogModel::log($data);
} catch (Exception $e) {
return [1, $e->getMessage()];
}
return [0, '新增报价成功'];
}
}
\ No newline at end of file
......@@ -141,11 +141,10 @@ return [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'prefix' =>env('PREFIX','Activity_')
],
],
......
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