Commit 261ac9f2 by 连敬荣

代码重构

parent 7d2761e2
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Queue\RabbitQueueModel;
use App\Http\Utils\ApiCode; use App\Http\Utils\ApiCode;
use App\Model\CommonModel;
use App\Model\InquiryItemsAssignModel; use App\Model\InquiryItemsAssignModel;
use App\Model\InquiryItemsModel; use App\Model\InquiryItemsModel;
use App\Model\InquiryItemsReportModel; use App\Model\InquiryItemsReportModel;
use App\Model\InquiryModel; use App\Model\InquiryModel;
use App\Model\InquiryUsersModel;
use Dompdf\Exception; use Dompdf\Exception;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use DB; use DB;
...@@ -17,6 +20,7 @@ use App\Http\Controllers\Controller; ...@@ -17,6 +20,7 @@ use App\Http\Controllers\Controller;
class DataController extends Controller class DataController extends Controller
{ {
private $STATUS_CLOSED = 4; private $STATUS_CLOSED = 4;
private $STATUS_ASSIGNED = 4;
public function createInquiryItemsDetail(Request $request){ public function createInquiryItemsDetail(Request $request){
$userInfo = $this->user(); $userInfo = $this->user();
$input = $request->input(); $input = $request->input();
...@@ -132,8 +136,215 @@ class DataController extends Controller ...@@ -132,8 +136,215 @@ class DataController extends Controller
} }
} }
public function deleteInquiryItemsDetail(Request $request){ public function deleteInquiryItemsDetail(Request $request){//删除询价明细
$inquiryItemsModel = new InquiryItemsModel(); $inquiryItemsModel = new InquiryItemsModel();
Export($inquiryItemsModel->DeleteInquiryItems($request->input())); Export($inquiryItemsModel->DeleteInquiryItems($request->input()));
} }
public function creatInquiry(Request $request){//从草稿正式生成询价单
$inquiryModel = new InquiryModel();
$input= $request->input();
$inquiryItemsModel = new InquiryItemsModel();
$inquiryUserModel = new InquiryUsersModel();
$inquiryItemsReportModel = new InquiryItemsReportModel();
if (empty($input["inquiry_id"])) {
Export(1001, "缺少询价单号");
exit();
}
if (empty($input["user"])) {
Export (1002, "请选择客户");
exit();
}
if (empty($input["delivery_place"])) {
Export (1002, "请选择交货地");
exit();
}
$inquiry_id = $input["inquiry_id"];
// $hasItems = (new InquiryItemsModel())->where("inquiry_id",$inquiry_id)->count();
$hasItems = $inquiryItemsModel->hasItems($inquiry_id);
if (!$hasItems ){
return [1001,"询价明细不得为空!"];
}
$data = [
"status" => 1, #启用
"remark" => $input["remark"],
"delivery_place" => $input["delivery_place"],
"currency" => $input["delivery_place"],
"user_types" => $input["user_types"], //询价客户类型: 1 个人 2 公司
"create_time" => time(),
"update_time" => time(),
];
$user = \GuzzleHttp\json_decode($input["user"], true);
if ($input["user_types"] == 1) { #个人询价
if ($user[0]["value"] == 0) { #客户id是0
// $userInfo= (new InquiryUsersModel())->where(["create_uid" => $input["user_id"], "user_name" => $user[0]["name"]])->first();
$userInfo = $inquiryUserModel->getUserInfo($input,$user);
if ($userInfo){
$userId = $userInfo->id;
}else{
// $userId = $inquiryUserModel->insertGetId(["create_uid" => $input["user_id"], "user_name" => $user[0]["name"], "create_time" => time()]);
$userId = $inquiryUserModel->getUserId($input,$user);
}
}else{
$userId = $user[0]["value"];
}
$data["user_id"] = $userId;
$data["user_name"] = $user[0]["name"];
} else {
$data["com_id"] = $user[0]["value"];
$data["com_name"] = $user[0]["name"];
}
$check = $inqueryId = $this->where("id", $input["inquiry_id"])->update($data);
// 检查询价明细是否需要报价,若无需报价则更新询价明细报价表
// $inquiry_items = (new InquiryItemsModel())->where("inquiry_id",$inquiry_id)->get()->toArray();
$inquiry_items = $inquiryItemsModel->getInquiryItems($inquiry_id);
foreach ($inquiry_items as $item) {
if ($item['is_quote'] == 1) continue;
$reportArr = [];
$reportArr['goods_name'] = $item['goods_name'];
$reportArr['goods_name_pro'] = $item['goods_name'];
$reportArr['brand_id'] = $item['brand_id'];
$reportArr['brand_name'] = $item['brand_name'];
$reportArr['supplier_name'] = '猎芯联营';
$reportArr['inquiry_number'] = $item['inquiry_number'];
$reportArr['currency'] = $input["delivery_place"];
if ($input["delivery_place"] == 1) {
$reportArr['price_rmb'] = $item['target_price'];
} else {
$reportArr['price_origin'] = $item['target_price'];
}
$reportArr['delivery_time'] = $item['delivery_time'];
$reportArr['class_id2'] = $item['class_id2'];
$reportArr['class_id2_name'] = $item['class_id2_name'];
$reportArr['batch'] = $item['batch'];
// (new InquiryItemsReportModel())->where("inquiry_items_id", $item['id'])->update($reportArr);
$inquiryItemsReportModel->updateIquiryItemsReport($item,$reportArr);
}
// 加入队列, 后续会把询价单分发到云芯的供应商
$RabbitQueueModel = new RabbitQueueModel();
$RabbitQueueModel->push("frq_add_inquiry", $input["inquiry_id"]);
Export (ApiCode::API_CODE_SUCCESS, "操作成功");
exit();
}
public function editInquiryItemDetail(Request $request){//修改单挑询价明细
$inquiryItemsModel = new InquiryItemsModel();
$inquiry_items_id = @$request["inquiry_items_id"] ? $request["inquiry_items_id"] : "" ;
if (!$inquiry_items_id){
return [ApiCode::API_CODE_DATA_INVALID,"修改明细ID不得为空"];
}
if (empty($request["goods_name"])) return [ApiCode::API_CODE_DATA_EMPTY, "请选择型号名称"];
if (empty($request["brand_s"])) return [ApiCode::API_CODE_DATA_EMPTY, "请选择品牌名称"];
if (empty($request["inquiry_number"])) return [ApiCode::API_CODE_DATA_EMPTY, "请输入询价数量"];
if (empty($request["batch"])) return [ApiCode::API_CODE_DATA_EMPTY, "请输入批次要求"];
if (empty($request["delivery_time"])) return [ApiCode::API_CODE_DATA_EMPTY, "请选择交货日期"];
try{
$con = DB::connection('rfq');
$con->beginTransaction();
$InquiryItemsAssignModel = (new InquiryItemsAssignModel());
#更新明细
$requestrandInfo = json_decode($request["brand_s"],true);
$request["brand_id"] = $requestrandInfo[0]["value"];
$request["brand_name"] = $requestrandInfo[0]["name"];
$updateArr= [
"goods_name"=>@$request["goods_name"] ? $request["goods_name"] : "" ,
"brand_id"=>@$request["brand_id"] ? $request["brand_id"] : 0,
"brand_name"=>@$request["brand_name"] ? $request["brand_name"] : "",
"class_id2"=>@$request["class_id2"] ? $request["class_id2"] : 0 ,
"class_id2_name"=>@$request["class_id2_name"] ? $request["class_id2_name"] : "" ,
"inquiry_number"=>@$request["inquiry_number"] ? $request["inquiry_number"] :0 ,
"target_price"=>@$request["target_price"] ? $request["target_price"] : 0,
"delivery_time"=>@$request["delivery_time"] ? $request["delivery_time"] : "",
"batch"=>@$request["batch"] ? $request["batch"] : "" ,
"assign_type"=>@$request["pur_s"] != "" ? 1: 2,
"remark"=>@$request["remark"] ? $request["remark"] : "",
"flag"=>0, #重新自动报价
"create_time"=>time() ,
"update_time"=>time() ,
];
// 无需报价没勾选,则默认为待报价
if (isset($request['is_quote']) && $request['is_quote'] == 'on') {
$updateArr['is_quote'] = -1;
$updateArr['status'] = 5;
} else {
$updateArr['is_quote'] = 1;
$updateArr['status'] = 1;
}
// $inquiryItemsModel->where("id",$inquiry_items_id)->update($updateArr);
$inquiryItemsModel->updateInquiryItemsDetail($inquiry_items_id,$updateArr);
#清空指定人
// $InquiryItemsAssignModel->where("inquiry_items_id",$inquiry_items_id)->delete();
$InquiryItemsAssignModel->clearOutAssign($inquiry_items_id);
#插入采购
if (@$request["pur_s"] != ""){
$purArr = json_decode($request["pur_s"],true); #指定采购
$assignInsert = []; #指定领取人
foreach ($purArr as $f=>$c){
array_push($assignInsert,[
"inquiry_items_id"=>$inquiry_items_id,
"assign_uid"=>$c["uid"],
"assign_name"=>$c["user_name"],
"create_time"=>time(),
]);
}
if(count($assignInsert) >0){ #插入指定人
// $InquiryItemsAssignModel->insert($assignInsert);
$InquiryItemsAssignModel->insertAssign($assignInsert);
}
// $inquiryItemsModel->where('id', $inquiry_items_id)->update(['status' => 4]); // 存在指定采购,则标记状态为已领取
$inquiryItemsModel->updateInquiryItemsStatus($inquiry_items_id,$this->STATUS_ASSIGNED);
}
#发送消息
$itemArr = $inquiryItemsModel->getItemArr($inquiry_items_id);//where("id",$inquiry_items_id)->first()->toArray(); #明细
$mainArr = (new InquiryModel())->getMainArr($itemArr);//where("id",$itemArr["inquiry_id"])->first()->toArray(); #主单状态
if ($mainArr["status"] == 1){ # 启动
#发送修改询价信息
$CommonModel = new CommonModel();
$assignInfo = (new InquiryItemsAssignModel())->getAssignInfo($inquiry_items_id);//select("assign_uid")->where("inquiry_items_id",$inquiry_items_id)->get();
if ($assignInfo){
$assignInfoArr = $assignInfo->toArray();
$msg = $request["user_name"].'已修改询价,询价单号:'.$mainArr["inquiry_sn"].',内容改动后:型号:'.$updateArr["goods_name"]
.',品牌:'.$updateArr["brand_name"].',批次要求:'.$updateArr["batch"].',交货日期:'.($updateArr["delivery_time"] > 6 ? ($updateArr["delivery_time"]/7)."周":$updateArr["delivery_time"]."天").',询价数量:'.$updateArr["inquiry_number"];
foreach ($assignInfoArr as $k=>$v){
$CommonModel->send_msg($v["assign_uid"],$msg);
}
}
}
#修改询价日志
\App\Model\OpLogModel::log([
'types'=>1,
'relation_id'=>$inquiry_items_id, #明细id
'relation_sn'=>$mainArr["inquiry_sn"],
'content'=>'修改询价,型号:'.$updateArr["goods_name"]." 品牌名称:".$updateArr["brand_name"]
." 货期:".$updateArr["delivery_time"]." 询价数量:".$updateArr["inquiry_number"] ." 批次:".$updateArr["batch"]
." 目标价:".$updateArr["target_price"],
'create_uid'=>$request['user_id'],
'create_name'=>$request["user_name"],
]);
$con->commit();
Export (ApiCode::API_CODE_SUCCESS,"修改成功");
exit();
}catch (\Exception $e) {
$con->rollBack();
Export (1001,"修改失败".$e->getMessage());
exit();
}
}
} }
...@@ -6,4 +6,5 @@ Route::Get('/ApiBrandList','SearchController@getBrandList');//新增询价查询 ...@@ -6,4 +6,5 @@ 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');//删除询价明细;
//Route::Post('/api/ApiEditInquiry','DataController@ApiEditInquiry');//新增询价; Route::Post('/api/ApiEditInquiry','DataController@creatInquiry');//新增询价;
\ No newline at end of file Route::Post('/ApiUpdateOneItems','DataController@editInquiryItemDetail');//修改单条明细记录;
\ No newline at end of file
...@@ -68,6 +68,15 @@ class InquiryItemsAssignModel extends Model ...@@ -68,6 +68,15 @@ class InquiryItemsAssignModel extends Model
return $this->where($map)->delete(); return $this->where($map)->delete();
} }
public function clearOutAssign($inquiry_items_id){//清空指定人
$this->where("inquiry_items_id",$inquiry_items_id)->delete();
}
public function insertAssign($assignInsert){//插入指定人
$this->insert($assignInsert);
}
public function getAssignInfo($inquiry_items_id){
$assignInfo = $this->select("assign_uid")->where("inquiry_items_id",$inquiry_items_id)->get();
return $assignInfo;
}
} }
\ No newline at end of file
...@@ -665,4 +665,20 @@ class InquiryItemsModel extends Model ...@@ -665,4 +665,20 @@ class InquiryItemsModel extends Model
public function updateInquiryItemsStatus($inquiryItemsId,$status){ public function updateInquiryItemsStatus($inquiryItemsId,$status){
$this->where('id', $inquiryItemsId)->update(['status' => $status]); // 存在指定采购,则标记状态为已领取 $this->where('id', $inquiryItemsId)->update(['status' => $status]); // 存在指定采购,则标记状态为已领取
} }
public function hasItems($inquiry_id){//判断是否存在明细
$hasItems = $this->where("inquiry_id",$inquiry_id)->count();
return $hasItems;
}
public function getInquiryItems($inquiry_id){
$inquiry_items = (new InquiryItemsModel())->where("inquiry_id",$inquiry_id)->get()->toArray();
return $inquiry_items;
}
public function updateInquiryItemsDetail($inquiry_items_id,$updateArr){
$this->where("id",$inquiry_items_id)->update($updateArr);
}
public function getItemArr($inquiry_items_id){
$itemArr = $this->where("id",$inquiry_items_id)->first()->toArray(); #明细
return $itemArr;
}
} }
\ No newline at end of file
...@@ -236,5 +236,8 @@ class InquiryItemsReportModel extends Model ...@@ -236,5 +236,8 @@ class InquiryItemsReportModel extends Model
return $check != count($itemsIdArr) ? [1001,$types == 1 ? "存在没选中的询价单!":"存在没确定的询价单!"] : [0,"通过"]; return $check != count($itemsIdArr) ? [1001,$types == 1 ? "存在没选中的询价单!":"存在没确定的询价单!"] : [0,"通过"];
} }
public function updateIquiryItemsReport($item,$reportArr){
$this->where("inquiry_items_id", $item['id'])->update($reportArr);
}
} }
\ No newline at end of file
...@@ -571,6 +571,9 @@ class InquiryModel extends Model ...@@ -571,6 +571,9 @@ class InquiryModel extends Model
$res = $con->select($sql1); $res = $con->select($sql1);
return @$res[0]["count"]; return @$res[0]["count"];
} }
public function getMainArr($itemArr){//获取主表单状态
$mainArr = $this->where("id",$itemArr["inquiry_id"])->first()->toArray();
return $mainArr;
}
} }
\ No newline at end of file
...@@ -20,5 +20,13 @@ class InquiryUsersModel extends Model ...@@ -20,5 +20,13 @@ class InquiryUsersModel extends Model
protected $primaryKey='id'; protected $primaryKey='id';
public $timestamps = false; public $timestamps = false;
public function getUserInfo($input,$user){
$userInfo= (new InquiryUsersModel())->where(["create_uid" => $input["user_id"], "user_name" => $user[0]["name"]])->first();
return $userInfo;
}
public function getUserId($input,$user){
$userId = $this->insertGetId(["create_uid" => $input["user_id"], "user_name" => $user[0]["name"], "create_time" => time()]);
return $userId;
}
} }
\ 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