Commit 20ce6f1a by 朱继来

新增报价

parent 794a7c13
......@@ -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($request, $id){
Export((new InquiryModel())->inquiryClose($request->input('inquiry_id')));
......@@ -135,9 +146,10 @@ class ApiController extends Controller
}
// 新增报价
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 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';
......@@ -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
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