Commit 31073433 by 连敬荣

代码重构

parent 635a8a59
...@@ -2,9 +2,14 @@ ...@@ -2,9 +2,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Utils\ApiCode;
use App\Model\InquiryItemsAssignModel;
use App\Model\InquiryItemsModel; use App\Model\InquiryItemsModel;
use App\Model\InquiryItemsReportModel;
use App\Model\InquiryModel;
use Dompdf\Exception;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use DB;
use App\Http\Requests; use App\Http\Requests;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
...@@ -13,12 +18,120 @@ class DataController extends Controller ...@@ -13,12 +18,120 @@ class DataController extends Controller
{ {
public function createInquiryItemsDetail(Request $request){ public function createInquiryItemsDetail(Request $request){
$userInfo = $this->user(); $userInfo = $this->user();
$input = $request->input();
$inquiryItemsModel = new InquiryItemsModel(); $inquiryItemsModel = new InquiryItemsModel();
Export($inquiryItemsModel->addItems($request->input(),$userInfo)); if (count($input) == 0 || $input == ""){
Export( [1001,"插入数据不得为空"]);exit();
}
if (empty($input["goods_name"])) {
Export(ApiCode::API_CODE_DATA_EMPTY, "请选择型号名称");
exit();
}
if (empty($input["inquiry_id"])) {
Export (ApiCode::API_CODE_DATA_EMPTY, "询价单ID不得为空");
exit();
}
if (empty($input["brand_s"])) {
Export (ApiCode::API_CODE_DATA_EMPTY, "请选择品牌名称");
exit();
}
if (empty($input["inquiry_number"])) {
Export (ApiCode::API_CODE_DATA_EMPTY, "请输入询价数量");
exit();
}
if (empty($input["batch"])) {
Export (ApiCode::API_CODE_DATA_EMPTY, "请输入批次要求");
exit();
}
if (empty($input["delivery_time"])) {
Export (ApiCode::API_CODE_DATA_EMPTY, "请选择交货日期");
exit();
}
try{
$con = DB::connection('rfq');
$con->beginTransaction();
#插入明细
$brandInfo = json_decode($input["brand_s"],true);
$check = $inquiryItemsModel->where(["inquiry_id"=>$input["inquiry_id"],"goods_name"=>$input["goods_name"],"brand_name"=>$brandInfo[0]["name"]])->count();
if ($check >0){
throw new Exception("已存在重复此型号品牌!");
}
$insertArr= [
"inquiry_id"=>$input["inquiry_id"] ,
"goods_name"=>@$input["goods_name"] ? $input["goods_name"] : "" ,
"brand_id"=>@$brandInfo[0]["value"],
"brand_name"=>@$brandInfo[0]["name"],
"class_id2"=>@$input["class_id2"] ? $input["class_id2"] : 0 ,
"class_id2_name"=>@$input["class_id2_name"] ? $input["class_id2_name"] : "" ,
"inquiry_number"=>@$input["inquiry_number"] ? $input["inquiry_number"] :0 ,
"target_price"=>@$input["target_price"] ? $input["target_price"] : 0,
"delivery_time"=>@$input["delivery_time_unit"] == "天"? $input["delivery_time"] :$input["delivery_time"]*7,
"batch"=>@$input["batch"] ? $input["batch"] : "" ,
"assign_type"=>$input["pur_s"] !== "" ? 1: 2,
"remark"=>@$input["remark"] ? $input["remark"] : "",
"create_time"=>time() ,
"update_time"=>time() ,
];
if (isset($input['is_quote']) && $input['is_quote'] == 'on') { // 无需报价,询价状态变为已确定
$insertArr['is_quote'] = -1;
$insertArr['status'] = 5;
}
$inquiryItemsId = $inquiryItemsModel->insertGetId($insertArr);
#插入销售报价表
$reportArr = [];
$reportArr['inquiry_id'] = $input['inquiry_id'];
$reportArr['inquiry_items_id'] = $inquiryItemsId;
$reportArr['create_time'] = time();
(new InquiryItemsReportModel())->insert($reportArr);
#插入指定领取人
if ($input["pur_s"] !== "" ){
$purArr = json_decode($input["pur_s"],true);
$assignInsert = []; #指定领取人
foreach ($purArr as $f=>$c){
array_push($assignInsert,[
"inquiry_items_id"=>$inquiryItemsId,
"assign_uid"=>$c["uid"],
"assign_name"=>$c["user_name"],
"create_time"=>time(),
]);
}
if(count($assignInsert) >0){ #插入指定人
(new InquiryItemsAssignModel())->insert($assignInsert);
}
$inquiryItemsModel->where('id', $inquiryItemsId)->update(['status' => 4]); // 存在指定采购,则标记状态为已领取
}
#日志
\App\Model\OpLogModel::log([
'types'=>1,
'relation_id'=>$inquiryItemsId, #明细id
'relation_sn'=>(new InquiryModel())->FindInquirySn($input["inquiry_id"]),
'content'=>'单个添加询价',
'create_uid'=>$userInfo['user_id'],
'create_name'=>$userInfo["user_name"],
]);
$con->commit();
Export (ApiCode::API_CODE_SUCCESS,"添加成功");
exit();
}catch (\Exception $e) {
$con->rollBack();
Export(ApiCode::API_CODE_ERROR,"添加失败:".$e->getMessage());
exit();
}
} }
public function deleteInquiryItemsDetail(Request $request){ public function deleteInquiryItemsDetail(Request $request){
$userInfo = $this->user();
$inquiryItemsModel = new InquiryItemsModel(); $inquiryItemsModel = new InquiryItemsModel();
Export($inquiryItemsModel->DeleteInquiryItems($request->input()));
} }
} }
...@@ -5,4 +5,4 @@ Route::Get('/ApiSkuList','SearchController@getSkuList');//新增询价查询sku ...@@ -5,4 +5,4 @@ Route::Get('/ApiSkuList','SearchController@getSkuList');//新增询价查询sku
Route::Get('/ApiBrandList','SearchController@getBrandList');//新增询价查询品牌接口; Route::Get('/ApiBrandList','SearchController@getBrandList');//新增询价查询品牌接口;
Route::Post('/ApiCheckGoods','SearchController@checkUniqueGoods');//检查是否已经存在询价单; Route::Post('/ApiCheckGoods','SearchController@checkUniqueGoods');//检查是否已经存在询价单;
Route::Post('/ApiCreateOneItems','DataController@createInquiryItemsDetail');//创建一条询价明细; Route::Post('/ApiCreateOneItems','DataController@createInquiryItemsDetail');//创建一条询价明细;
//Route::Post('/api/ApiDeleteInquiryItems','DataController@deleteInquiryItemsDetail');//删除一条明细; Route::Post('/api/ApiDeleteInquiryItems','DataController@deleteInquiryItemsDetail');//删除询价明细;
\ No newline at end of file \ No newline at end of file
...@@ -150,6 +150,7 @@ class InquiryItemsModel extends Model ...@@ -150,6 +150,7 @@ class InquiryItemsModel extends Model
//清空列表 //清空列表
public function DeleteInquiryItems($input){ public function DeleteInquiryItems($input){
if (@$input["inquiry_id"]){ if (@$input["inquiry_id"]){
$del = $this->where(["inquiry_id"=>$input["inquiry_id"]])->delete(); $del = $this->where(["inquiry_id"=>$input["inquiry_id"]])->delete();
} }
...@@ -157,7 +158,7 @@ class InquiryItemsModel extends Model ...@@ -157,7 +158,7 @@ class InquiryItemsModel extends Model
$del = $this->where(["id"=>$input["inquiry_items_id"]])->delete(); $del = $this->where(["id"=>$input["inquiry_items_id"]])->delete();
$del = (new InquiryItemsReportModel())->where(["inquiry_items_id"=>$input["inquiry_items_id"]])->delete(); #同步输出报价表 $del = (new InquiryItemsReportModel())->where(["inquiry_items_id"=>$input["inquiry_items_id"]])->delete(); #同步输出报价表
} }
return [0,"删除成功"]; return [ApiCode::API_CODE_SUCCESS,"删除成功"];
} }
/* /*
...@@ -212,7 +213,7 @@ class InquiryItemsModel extends Model ...@@ -212,7 +213,7 @@ class InquiryItemsModel extends Model
* 创建单个创建明细 * 创建单个创建明细
* @param $data 批量 * @param $data 批量
*/ */
public function addItems($b,$userInfo){ public function addItems($b){
if (count($b) == 0 || $b == ""){ if (count($b) == 0 || $b == ""){
return [1001,"插入数据不得为空"]; return [1001,"插入数据不得为空"];
} }
...@@ -291,8 +292,8 @@ class InquiryItemsModel extends Model ...@@ -291,8 +292,8 @@ class InquiryItemsModel extends Model
'relation_id'=>$inquiryItemsId, #明细id 'relation_id'=>$inquiryItemsId, #明细id
'relation_sn'=>(new InquiryModel())->FindInquirySn($b["inquiry_id"]), 'relation_sn'=>(new InquiryModel())->FindInquirySn($b["inquiry_id"]),
'content'=>'单个添加询价', 'content'=>'单个添加询价',
'create_uid'=>$userInfo['user_id'], 'create_uid'=>$b['user_id'],
'create_name'=>$userInfo["user_name"], 'create_name'=>$b["user_name"],
]); ]);
$con->commit(); $con->commit();
......
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