Commit b077cc23 by hcy001

1

parent d9d3a3d3
...@@ -7,3 +7,4 @@ Homestead.json ...@@ -7,3 +7,4 @@ Homestead.json
websit.php websit.php
/public/php_errors.log /public/php_errors.log
/public/pdf
...@@ -228,7 +228,7 @@ class ApiController extends Controller ...@@ -228,7 +228,7 @@ class ApiController extends Controller
//获取客户信息 //获取客户信息
public function ApiGetUser($input, $id) public function ApiGetUser($input, $id)
{ {
(new CommonModel())->getUser($input["k"],$input["types"]); (new CommonModel())->getMyUser($input["user_id"],$input["k"]);
} }
// 统计询价数据 // 统计询价数据
public function ApiInquiryCount($input, $id) public function ApiInquiryCount($input, $id)
......
...@@ -27,6 +27,18 @@ class CommonModel extends Model ...@@ -27,6 +27,18 @@ class CommonModel extends Model
$Redis= \RedisDB::connection(); $Redis= \RedisDB::connection();
return $Redis->hget("erp_rate",$k); return $Redis->hget("erp_rate",$k);
} }
//搜索自己的客户
public function getMyUser($create_uid,$k)
{
$dbspu = DB::connection("rfq");
$brandInfo = $dbspu->select("select id value,user_name name from lie_inquiry_users where create_uid = $create_uid and user_name like '".$k."%' limit 10");
if (count($brandInfo) == 0){
$brandInfo = [["value"=>0,"name"=>$k]];
}
echo json_encode($brandInfo, JSON_UNESCAPED_UNICODE);
exit();
}
//搜索用户或者公司 //搜索用户或者公司
public function getUser($k,$types=1) public function getUser($k,$types=1)
{ {
......
...@@ -15,9 +15,9 @@ use RedisDB; ...@@ -15,9 +15,9 @@ use RedisDB;
//询价 //询价
class InquiryModel extends Model class InquiryModel extends Model
{ {
protected $connection='rfq'; protected $connection = 'rfq';
protected $table='inquiry'; protected $table = 'inquiry';
protected $primaryKey='id'; protected $primaryKey = 'id';
public $timestamps = false; public $timestamps = false;
/** /**
...@@ -32,17 +32,17 @@ class InquiryModel extends Model ...@@ -32,17 +32,17 @@ class InquiryModel extends Model
$rqpConn = DB::connection('rfq'); $rqpConn = DB::connection('rfq');
$list = $rqpConn->table('inquiry as a') $list = $rqpConn->table('inquiry as a')
->join('inquiry_items as b','a.id','=','b.inquiry_id') ->join('inquiry_items as b', 'a.id', '=', 'b.inquiry_id')
->select(DB::Raw("lie_a.inquiry_sn,lie_a.currency,lie_a.status as status_a,lie_a.com_name,lie_a.user_name,lie_a.create_name,lie_a.create_time as inquiry_ctime,lie_b.*")) ->select(DB::Raw("lie_a.inquiry_sn,lie_a.currency,lie_a.status as status_a,lie_a.com_name,lie_a.user_name,lie_a.create_name,lie_a.create_time as inquiry_ctime,lie_b.*"))
->where(function ($query) use ($input) { ->where(function ($query) use ($input) {
foreach ($input as $k => $v){ foreach ($input as $k => $v) {
$v = trim($v); $v = trim($v);
if (empty($v)){ if (empty($v)) {
continue; continue;
} }
switch ($k){ switch ($k) {
case "inquiry_sn": case "inquiry_sn":
$query->where('a.'.$k, '=', $v); $query->where('a.' . $k, '=', $v);
break; break;
case "inquiry_id": case "inquiry_id":
$query->where('a.id', '=', $v); $query->where('a.id', '=', $v);
...@@ -50,79 +50,79 @@ class InquiryModel extends Model ...@@ -50,79 +50,79 @@ class InquiryModel extends Model
case "goods_name": case "goods_name":
case "brand_name": case "brand_name":
case "customer_name": case "customer_name":
$query->whereRaw('(lie_b.com_name like "'.$v.'%" or lie_b.user_name like "'.$v.'%" )'); $query->whereRaw('(lie_b.com_name like "' . $v . '%" or lie_b.user_name like "' . $v . '%" )');
break; break;
case "status": case "status":
$query->where('b.status', '=',$v); $query->where('b.status', '=', $v);
break; break;
case "create_uid": case "create_uid":
$query->where('a.create_uid', '=', $v); $query->where('a.create_uid', '=', $v);
break; break;
case "assign_type": case "assign_type":
$query->where('b.assign_type', '=',$v); $query->where('b.assign_type', '=', $v);
break; break;
case "start_time": case "start_time":
$query->where('a.create_time', '>=', strtotime($v)); $query->where('a.create_time', '>=', strtotime($v));
break; break;
case "end_time": case "end_time":
$query->where('a.create_time', '<=', strtotime($v)+86399); $query->where('a.create_time', '<=', strtotime($v) + 86399);
break; break;
} }
} }
}); });
#不同类别查询 #不同类别查询
switch (@$input["types"]){ switch (@$input["types"]) {
case "1": //我的询价 case "1": //我的询价
$list = $list->where('a.create_uid', $user_id); $list = $list->where('a.create_uid', $user_id);
break; break;
case "2": //我的已关闭询价 case "2": //我的已关闭询价
$list = $list->where('a.create_uid', $user_id)->where("b.status",-1); $list = $list->where('a.create_uid', $user_id)->where("b.status", -1);
case "3": //所有询价 case "3": //所有询价
$perm = new PermController; $perm = new PermController;
$role = $perm->getUserRole($user_id,$user_name); // 用户角色 $role = $perm->getUserRole($user_id, $user_name); // 用户角色
switch ($role) { switch ($role) {
case 2: // 销售查看下级 case 2: // 销售查看下级
$sub_sale_ids = $perm->getSubSaleId($user_id); $sub_sale_ids = $perm->getSubSaleId($user_id);
$list = $list->whereIn('a.create_uid', $sub_sale_ids)->whereIn('a.status', [-1,1]); $list = $list->whereIn('a.create_uid', $sub_sale_ids)->whereIn('a.status', [-1, 1]);
break; break;
case 3: // 销售查看自己 case 3: // 销售查看自己
$list = $list->where('a.create_uid', $user_id)->whereIn('a.status', [-1,1]); $list = $list->where('a.create_uid', $user_id)->whereIn('a.status', [-1, 1]);
break; break;
} }
break; break;
} }
$page = isset($input['p']) ? $input['p'] : $input['page']; $page = isset($input['p']) ? $input['p'] : $input['page'];
$list= $list->orderBy('id','desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray(); $list = $list->orderBy('id', 'desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray();
if (!$list) return [20001, '没有数据']; if (!$list) return [20001, '没有数据'];
$QuoteModel = new QuoteModel(); $QuoteModel = new QuoteModel();
$InquiryItemsUrgeModel = new InquiryItemsUrgeModel; $InquiryItemsUrgeModel = new InquiryItemsUrgeModel;
$Redis= \RedisDB::connection(); $Redis = \RedisDB::connection();
foreach ($list['data'] as $k=>&$v){ foreach ($list['data'] as $k => &$v) {
//报价 //报价
$v['status_val'] = InquiryMap::$status[$v["status"]]; $v['status_val'] = InquiryMap::$status[$v["status"]];
if ($v["status_val"] == "已报价"){ if ($v["status_val"] == "已报价") {
$count = $QuoteModel->whereIn("status",QuoteMap::$status_used)->count(); $count = $QuoteModel->where("inquiry_items_id", $v["id"])->whereIn("status", QuoteMap::$status_used)->count();
$v['status_val'] = $v['status_val']."(".$count.")"; $v['status_val'] = $v['status_val'] . "(" . $count . ")";
} }
$v['create_time'] = timeToDate($v['create_time']); //创建时间 $v['create_time'] = timeToDate($v['create_time']); //创建时间
$v["customer_name"] = $v['com_name'] == "" ? $v['user_name'] : $v['com_name'] ; $v["customer_name"] = $v['com_name'] == "" ? $v['user_name'] : $v['com_name'];
$currency_sign = $v['currency'] == 1 ? '¥' : '$'; $currency_sign = $v['currency'] == 1 ? '¥' : '$';
$v['target_price'] = $currency_sign.$v['target_price']; // 客户目标报价 $v['target_price'] = $currency_sign . $v['target_price']; // 客户目标报价
//查询最低报价 //查询最低报价
if ($v['currency'] == 1){ //人民币 if ($v['currency'] == 1) { //人民币
$quote = $QuoteModel->select("price_rmb as quote_price")->whereIn("status",QuoteMap::$status_used)->orderBy("price_rmb","asc")->first(); $quote = $QuoteModel->select("price_rmb as quote_price")->whereIn("status", QuoteMap::$status_used)->orderBy("price_rmb", "asc")->first();
} else { //美金 } else { //美金
$quote = $QuoteModel->select("price_origin as quote_price")->whereIn("status",QuoteMap::$status_used)->orderBy("price_origin","asc")->first(); $quote = $QuoteModel->select("price_origin as quote_price")->whereIn("status", QuoteMap::$status_used)->orderBy("price_origin", "asc")->first();
} }
$v['quote_price'] = @$quote["quote_price"] > 0 ? $quote["quote_price"] : "------"; //存在报价 $v['quote_price'] = @$quote["quote_price"] > 0 ? $quote["quote_price"] : "------"; //存在报价
...@@ -130,25 +130,27 @@ class InquiryModel extends Model ...@@ -130,25 +130,27 @@ class InquiryModel extends Model
// 在Redis集合中检查是否有新的报价 // 在Redis集合中检查是否有新的报价
$res = $Redis->SISMEMBER('frq_quote_urge', $v['id']); $res = $Redis->SISMEMBER('frq_quote_urge', $v['id']);
if ($res) { if ($res) {
$v['inquiry_sn'] = $v['inquiry_sn']."<span style='color:red;'>&nbsp;*</span>"; $v['inquiry_sn'] = $v['inquiry_sn'] . "<span style='color:red;'>&nbsp;*</span>";
} }
} }
$data = $list['data']; $data = $list['data'];
if (@$input["is_export"] == 1){ #如果是导出 if (@$input["is_export"] == 1) { #如果是导出
$data = $this->clearExport($data); $data = $this->clearExport($data);
} }
return [0, '成功', $data, $list['total']]; return [0, '成功', $data, $list['total']];
} }
/* /*
* 关闭询价 * 关闭询价
*/ */
public function inquiryClose($input){ public function inquiryClose($input)
if (empty(@$input["inquiry_id"])){ {
return [1001,"询价单ID不得为空"]; if (empty(@$input["inquiry_id"])) {
return [1001, "询价单ID不得为空"];
} }
$this->where("id",$input["inquiry_id"])->update(["status"=>-1,"remark"=>@$input["remark"] ? $input["remark"] : "","update_time"=>time()]); $this->where("id", $input["inquiry_id"])->update(["status" => -1, "remark" => @$input["remark"] ? $input["remark"] : "", "update_time" => time()]);
(new InquiryItemsModel())->where("inquiry_id",$input["inquiry_id"])->update(["status"=>-1,"update_time"=>time()]); (new InquiryItemsModel())->where("inquiry_id", $input["inquiry_id"])->update(["status" => -1, "update_time" => time()]);
return [0,"关闭整个询价单成功"]; return [0, "关闭整个询价单成功"];
} }
/** /**
...@@ -156,121 +158,121 @@ class InquiryModel extends Model ...@@ -156,121 +158,121 @@ class InquiryModel extends Model
*/ */
public function getListPool($input = []) public function getListPool($input = [])
{ {
$user_id = @$input["user_id"]; $user_id = @$input["user_id"];
$user_name = @$input["email"]; $user_name = @$input["email"];
$rqpConn = DB::connection('rfq'); $rqpConn = DB::connection('rfq');
// type值存在,1-报价管理询价池,2-已领取的询价,3-指定/领取的当前用户最新询价8条,4-指定/领取的当前用户最新催价8条 // type值存在,1-报价管理询价池,2-已领取的询价,3-指定/领取的当前用户最新询价8条,4-指定/领取的当前用户最新催价8条
$type = isset($input['type']) ? $input['type'] : 0; $type = isset($input['type']) ? $input['type'] : 0;
$list = $rqpConn->table('inquiry as a')->join('inquiry_items as b','a.id','=','b.inquiry_id'); $list = $rqpConn->table('inquiry as a')->join('inquiry_items as b', 'a.id', '=', 'b.inquiry_id');
if ($type == 2) { if ($type == 2) {
$list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id')->where('c.assign_uid', $user_id); $list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id')->where('c.assign_uid', $user_id);
} else if ($type == 3) { } else if ($type == 3) {
$list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id') $list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id')
->where('c.assign_uid', $user_id) ->where('c.assign_uid', $user_id)
->where('b.status', 1); // 待报价 ->where('b.status', 1); // 待报价
} else if ($type == 4) { } else if ($type == 4) {
$list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id') $list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id')
->join('inquiry_items_urge as u', 'b.id', '=', 'u.inquiry_items_id') ->join('inquiry_items_urge as u', 'b.id', '=', 'u.inquiry_items_id')
->where('c.assign_uid', $user_id); ->where('c.assign_uid', $user_id);
} }
$list = $list->select(DB::Raw("lie_a.inquiry_sn,lie_a.currency,lie_a.status as status_a,lie_a.user_name,lie_a.com_name,lie_a.create_name,lie_a.create_time as inquiry_ctime,lie_b.*")) $list = $list->select(DB::Raw("lie_a.inquiry_sn,lie_a.currency,lie_a.status as status_a,lie_a.user_name,lie_a.com_name,lie_a.create_name,lie_a.create_time as inquiry_ctime,lie_b.*"))
->where(function ($query) use ($input, $type) { ->where(function ($query) use ($input, $type) {
foreach ($input as $k => $v){ foreach ($input as $k => $v) {
$v = trim($v); $v = trim($v);
if (empty($v)){ if (empty($v)) {
continue; continue;
} }
switch ($k){ switch ($k) {
case "inquiry_sn": case "inquiry_sn":
$query->where('a.inquiry_sn', '=', $v); $query->where('a.inquiry_sn', '=', $v);
break; break;
case "goods_name": case "goods_name":
case "brand_name": case "brand_name":
$query->whereRaw('lie_b.'.$k.' like "'.$v.'%"'); $query->whereRaw('lie_b.' . $k . ' like "' . $v . '%"');
break; break;
case "status": case "status":
$query->where('b.status', '=',$v); $query->where('b.status', '=', $v);
break; break;
case "create_uid": case "create_uid":
$query->where('a.create_uid', '=', $v); $query->where('a.create_uid', '=', $v);
break; break;
case "assign_type": case "assign_type":
$query->where('b.assign_type', '=',$v); $query->where('b.assign_type', '=', $v);
break; break;
case "start_time": case "start_time":
$query->where('a.create_time', '>=', strtotime($v)); $query->where('a.create_time', '>=', strtotime($v));
break; break;
case "end_time": case "end_time":
$query->where('a.create_time', '<=', strtotime($v)+86399); $query->where('a.create_time', '<=', strtotime($v) + 86399);
break; break;
} }
} }
$query->whereIn('a.status', [-1,1]); $query->whereIn('a.status', [-1, 1]);
if ($type == 1) { if ($type == 1) {
$query->whereNotIn('b.status', [-1, 5])->where('b.assign_type', 0); // 询价池需过滤已关闭、已确认、指定和领取的询价 $query->whereNotIn('b.status', [-1, 5])->where('b.assign_type', 0); // 询价池需过滤已关闭、已确认、指定和领取的询价
$time = time() - 7200; // 待报价的询价两小时后在询价池展示 $time = time() - 7200; // 待报价的询价两小时后在询价池展示
$query->orWhereRaw('(lie_b.assign_type=1 and lie_b.status=1 and lie_b.create_time < '.$time.')'); $query->orWhereRaw('(lie_b.assign_type=1 and lie_b.status=1 and lie_b.create_time < ' . $time . ')');
} }
}); });
if ($type == 4) { // 多条重复催价情况下去重 if ($type == 4) { // 多条重复催价情况下去重
$list = $list->groupBy('b.id'); $list = $list->groupBy('b.id');
} }
// dump($list->getBindings()); // dump($list->getBindings());
// dump($list->toSql()); // dump($list->toSql());
// $tmp = str_replace('?', '"'.'%s'.'"', $list->toSql()); // $tmp = str_replace('?', '"'.'%s'.'"', $list->toSql());
// $tmp = vsprintf($tmp, $list->getBindings()); // $tmp = vsprintf($tmp, $list->getBindings());
// echo $tmp; // echo $tmp;
// exit; // exit;
$page = isset($input['p']) ? $input['p'] : $input['page']; $page = isset($input['p']) ? $input['p'] : $input['page'];
$list= $list->orderBy('b.id','desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray(); $list = $list->orderBy('b.id', 'desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray();
if (!$list) return [20001, '没有数据']; if (!$list) return [20001, '没有数据'];
$QuoteModel = new QuoteModel(); $QuoteModel = new QuoteModel();
$InquiryItemsUrgeModel = new InquiryItemsUrgeModel; $InquiryItemsUrgeModel = new InquiryItemsUrgeModel;
foreach ($list['data'] as $k=>&$v){ foreach ($list['data'] as $k => &$v) {
//报价 //报价
$v['status_val'] = InquiryMap::$status[$v["status"]]; $v['status_val'] = InquiryMap::$status[$v["status"]];
if ($v["status_val"] == "已报价"){ if ($v["status_val"] == "已报价") {
$count = $QuoteModel->whereIn("status",QuoteMap::$status_used)->count(); $count = $QuoteModel->whereIn("status", QuoteMap::$status_used)->count();
$v['status_val'] = $v['status_val']."(".$count.")"; $v['status_val'] = $v['status_val'] . "(" . $count . ")";
} }
$v["customer_name"] = $v['com_name'] == "" ? $v['user_name'] : $v['com_name'] ; $v["customer_name"] = $v['com_name'] == "" ? $v['user_name'] : $v['com_name'];
$v['create_time'] = timeToDate($v['create_time']); //创建时间 $v['create_time'] = timeToDate($v['create_time']); //创建时间
$currency_sign = $v['currency'] == 1 ? '¥' : '$'; $currency_sign = $v['currency'] == 1 ? '¥' : '$';
$v['target_price'] = $currency_sign.$v['target_price']; // 客户目标报价 $v['target_price'] = $currency_sign . $v['target_price']; // 客户目标报价
if ($type == 2) { // 已领取的询价列表 if ($type == 2) { // 已领取的询价列表
$v['assign_type_val'] = $v['assign_type'] == 1 ? '指定' : '领取'; // 指定/领取 $v['assign_type_val'] = $v['assign_type'] == 1 ? '指定' : '领取'; // 指定/领取
$price_field = $v['currency'] == 1 ? 'price_rmb' : 'price_origin'; $price_field = $v['currency'] == 1 ? 'price_rmb' : 'price_origin';
$quote = $QuoteModel->where('create_uid', $user_id)->first(); $quote = $QuoteModel->where('create_uid', $user_id)->first();
// 我的报价 // 我的报价
$v['self_quote'] = $quote ? $currency_sign.$quote[$price_field].'('.array_get(Config('quote.quote_status'), $quote['status'], '').')' : ''; $v['self_quote'] = $quote ? $currency_sign . $quote[$price_field] . '(' . array_get(Config('quote.quote_status'), $quote['status'], '') . ')' : '';
// 在Redis集合中检查用户是否被催报价 // 在Redis集合中检查用户是否被催报价
$res = RedisDB::sIsMember('frq_inquiry_items_urge', $v['id'].'-'.$user_id); $res = RedisDB::sIsMember('frq_inquiry_items_urge', $v['id'] . '-' . $user_id);
if ($res) { if ($res) {
$urge = $InquiryItemsUrgeModel->getLastInfo($v['id']); $urge = $InquiryItemsUrgeModel->getLastInfo($v['id']);
$v['inquiry_sn'] = '<div title="'.$urge['remark'].'">'.$v['inquiry_sn'].'<i style="color:red;">(催)</i></div>'; $v['inquiry_sn'] = '<div title="' . $urge['remark'] . '">' . $v['inquiry_sn'] . '<i style="color:red;">(催)</i></div>';
} }
} }
...@@ -280,78 +282,91 @@ class InquiryModel extends Model ...@@ -280,78 +282,91 @@ class InquiryModel extends Model
} }
//导出数据格式化 //导出数据格式化
public function clearExport($data){ public function clearExport($data)
// $header = ["询价单号","询价型号","询价品牌","询价数量","询价客户","询价时间","客户目标报价","报价","状态"]; {
// $header = ["询价单号","询价型号","询价品牌","询价数量","询价客户","询价时间","客户目标报价","报价","状态"];
$temp = []; $temp = [];
foreach ($data as $k=>$v){ foreach ($data as $k => $v) {
array_push($temp,[ array_push($temp, [
"inquiry_sn"=>$v["inquiry_sn"], "inquiry_sn" => $v["inquiry_sn"],
"goods_name"=>$v["goods_name"], "goods_name" => $v["goods_name"],
"brand_name"=>$v["brand_name"], "brand_name" => $v["brand_name"],
"inquiry_number"=>$v["inquiry_number"], "inquiry_number" => $v["inquiry_number"],
"customer_name"=>$v["customer_name"], "customer_name" => $v["customer_name"],
"create_time"=>$v["create_time"], "create_time" => $v["create_time"],
"target_price"=>$v["target_price"], "target_price" => $v["target_price"],
"quote_price"=>@$v["quote_price"], //报价 "quote_price" => @$v["quote_price"], //报价
"status_val"=>$v["status_val"], "status_val" => $v["status_val"],
]); ]);
} }
return $temp; return $temp;
} }
//生成草稿id //生成草稿id
public function FindInquiryId($user_id='',$user_name =""){ public function FindInquiryId($user_id = '', $user_name = "")
if(empty($user_id)) return false; {
if (empty($user_id)) return false;
$result=$this->where('status','=',0)->where('create_uid','=',$user_id)->select('id','create_time')->first();
if(!$result){ $result = $this->where('status', '=', 0)->where('create_uid', '=', $user_id)->select('id', 'create_time')->first();
$Add['inquiry_sn']=generateSnWithPreStringShort("X"); if (!$result) {
$Add['create_uid']=$user_id; $Add['inquiry_sn'] = generateSnWithPreStringShort("X");
$Add['create_name']=$user_name; $Add['create_uid'] = $user_id;
$Add['create_time']=time(); $Add['create_name'] = $user_name;
$Add['update_time']=time(); $Add['create_time'] = time();
$inqueryId=$this->insertGetId($Add); $Add['update_time'] = time();
$inqueryId = $this->insertGetId($Add);
}else{
$result=$result->toArray(); } else {
$result = $result->toArray();
$inqueryId = $result["id"]; $inqueryId = $result["id"];
} }
return $inqueryId; return $inqueryId;
} }
//生成草稿id //生成草稿id
public function FindInquirySn($inquiry_id=''){ public function FindInquirySn($inquiry_id = '')
$result=$this->where('id','=',$inquiry_id)->select('inquiry_sn')->first(); {
if(!$result){ $result = $this->where('id', '=', $inquiry_id)->select('inquiry_sn')->first();
if (!$result) {
return false; return false;
}else{ } else {
return $result->inquiry_sn; return $result->inquiry_sn;
} }
} }
//从草稿生成正式询价单 //从草稿生成正式询价单
public function editInquiry($input){ public function editInquiry($input)
if (empty($input["inquiry_id"])) return [1001,"缺少询价单号"]; {
if (empty($input["user"])) return [1002,"请选择客户"]; if (empty($input["inquiry_id"])) return [1001, "缺少询价单号"];
if (empty($input["delivery_place"])) return [1002,"请选择交货地"]; if (empty($input["user"])) return [1002, "请选择客户"];
$user = \GuzzleHttp\json_decode($input["user"],true); if (empty($input["delivery_place"])) return [1002, "请选择交货地"];
$data = [ $inquiry_id = $input["inquiry_id"];
"status"=>1, #启用 $hasItems = (new InquiryItemsModel())->where("inquiry_id",$inquiry_id)->count();
"remark"=>$input["remark"], if (!$hasItems ){
"delivery_place"=>$input["delivery_place"], return [1001,"询价明细不得为空!"];
"user_types"=>$input["user_types"], //询价客户类型: 1 个人 2 公司 }
"create_time"=>time(),
"update_time"=>time(), $data = [
]; "status" => 1, #启用
if ($input["user_types"] == 1){ #个人询价 "remark" => $input["remark"],
$data["user_id"] = $user[0]["value"]; "delivery_place" => $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,新建客户
$userId = (new InquiryUsersModel())->insertGetId(["create_uid" => $input["user_id"], "user_name" => $user[0]["name"], "create_time" => time()]);
}
$data["user_id"] = $userId;
$data["user_name"] = $user[0]["name"]; $data["user_name"] = $user[0]["name"];
}else{ } else {
$data["com_id"] = $user[0]["value"]; $data["com_id"] = $user[0]["value"];
$data["com_name"] = $user[0]["name"]; $data["com_name"] = $user[0]["name"];
} }
$check = $inqueryId=$this->where("id",$input["inquiry_id"])->update($data); $check = $inqueryId = $this->where("id", $input["inquiry_id"])->update($data);
return [0,"操作成功"]; return [0, "操作成功"];
} }
// 报价统计 // 报价统计
...@@ -364,30 +379,30 @@ class InquiryModel extends Model ...@@ -364,30 +379,30 @@ class InquiryModel extends Model
case 1: case 1:
for ($i = 0; $i < 24; $i++) { for ($i = 0; $i < 24; $i++) {
$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->inquiryCountRun(1,$input, $start_time,$end_time); $data['today_quote'][] = $this->inquiryCountRun(1, $input, $start_time, $end_time);
$data['today_no_quote'][] = $this->inquiryCountRun(2,$input, $start_time, $end_time); $data['today_no_quote'][] = $this->inquiryCountRun(2, $input, $start_time, $end_time);
$data['x_axis_data'][] = $i.'点'; $data['x_axis_data'][] = $i . '点';
} }
break; break;
case 7: case 7:
for ($i = 7; $i > 0; $i--) { for ($i = 7; $i > 0; $i--) {
$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->inquiryCountRun(1,$input, $start_time,$end_time); $data['today_quote'][] = $this->inquiryCountRun(1, $input, $start_time, $end_time);
$data['today_no_quote'][] = $this->inquiryCountRun(2,$input, $start_time, $end_time); $data['today_no_quote'][] = $this->inquiryCountRun(2, $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);
} }
break; break;
case 30: case 30:
for ($i = 30; $i > 0; $i--) { for ($i = 30; $i > 0; $i--) {
$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->inquiryCountRun(1,$input, $start_time,$end_time); $data['today_quote'][] = $this->inquiryCountRun(1, $input, $start_time, $end_time);
$data['today_no_quote'][] = $this->inquiryCountRun(2,$input, $start_time, $end_time); $data['today_no_quote'][] = $this->inquiryCountRun(2, $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);
} }
break; break;
} }
...@@ -395,14 +410,14 @@ class InquiryModel extends Model ...@@ -395,14 +410,14 @@ class InquiryModel extends Model
} }
// 询价统计 // 询价统计
public function inquiryCountRun($types = 1,$input, $start_time,$end_time) public function inquiryCountRun($types = 1, $input, $start_time, $end_time)
{ {
$con = DB::connection('rfq'); $con = DB::connection('rfq');
if ($types == 1){ #时间段询价总计 if ($types == 1) { #时间段询价总计
$sql1 = "select count(1) count from lie_inquiry WHERE create_time >= $start_time and create_time <= $end_time and create_uid=".$input["user_id"]; $sql1 = "select count(1) count from lie_inquiry WHERE create_time >= $start_time and create_time <= $end_time and create_uid=" . $input["user_id"];
}else{ #时间段选中报价统计 } else { #时间段选中报价统计
$sql1 = "select count(1) count from lie_inquiry a,lie_inquiry_items b WHERE a.id=b.inquiry_id $sql1 = "select count(1) count from lie_inquiry a,lie_inquiry_items b WHERE a.id=b.inquiry_id
and a.create_time >= $start_time and a.create_time <= $end_time and b.status=3 and a.create_uid=".$input["user_id"]; and a.create_time >= $start_time and a.create_time <= $end_time and b.status=3 and a.create_uid=" . $input["user_id"];
} }
$res = $con->select($sql1); $res = $con->select($sql1);
return @$res[0]["count"]; return @$res[0]["count"];
......
<?php
namespace App\Model;
use App\map\InquiryMap;
use App\map\OperationLogMap;
use App\map\QuoteMap;
use Illuminate\Database\Eloquent\Model;
use Request;
use DB;
use App\Http\Controllers\PermController;
use App\Model\InquiryItemsUrgeModel;
use RedisDB;
//询价客户
class InquiryUsersModel extends Model
{
protected $connection='rfq';
protected $table='inquiry_users';
protected $primaryKey='id';
public $timestamps = false;
}
\ No newline at end of file
...@@ -18,7 +18,7 @@ class QuoteMap{ ...@@ -18,7 +18,7 @@ class QuoteMap{
]; ];
//可用报价状态 //可用报价状态
static $status_used = [self::status_ready,self::status_fix,self::status_fix]; static $status_used = [self::status_ready,self::status_fix,self::status_sure];
} }
......
...@@ -75,7 +75,7 @@ layui.config({ ...@@ -75,7 +75,7 @@ layui.config({
{field: 'create_name', title: '报价人'}, {field: 'create_name', title: '报价人'},
{field: 'create_time', title: '报价时间'}, {field: 'create_time', title: '报价时间'},
{field: 'status', title: '状态'}, {field: 'status', title: '状态'},
{title: '操作', toolbar: '#son', width: 130} {field:'son', title: '操作',templet:'#main',width:230,align:'center'}
]] ]]
} }
} }
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
<!--子操作栏--> <!--子操作栏-->
<script type="text/html" id="son"> <script type="text/html" id="son">
<a href="/web/SaveSupplier?supplier_id=@{{ d.supplier_id }}" class="btn btn-xs btn-outline btn-primary"><strong>催报价</strong></a>
@{{# if(d.status_val=='待报价' ){ }} @{{# if(d.status_val=='待报价' ){ }}
<a href="/web/SaveSupplier?supplier_id=@{{ d.supplier_id }}" class="btn btn-xs btn-outline btn-primary"><strong>催报价</strong></a> <a href="/web/SaveSupplier?supplier_id=@{{ d.supplier_id }}" class="btn btn-xs btn-outline btn-primary"><strong>催报价</strong></a>
@{{# }else if(d.status=='-1' ){ }} @{{# }else if(d.status=='-1' ){ }}
......
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