Commit ed7ea574 by 朱继来

添加采购首页

parent b6045ed2
......@@ -203,4 +203,10 @@ class ApiController extends Controller
ExportLayui((new OpLogModel())->getList($input));
}
// 统计报价数据
public function ApiQuoteCount($input, $id)
{
Export((new QuoteModel())->quoteCount($input));
}
}
......@@ -153,11 +153,13 @@ class InquiryModel extends Model
*/
public function getListPool($input = [])
{
$user_id = @$input["user_id"];
$user_id = @$input["user_id"];
$user_name = @$input["email"];
$rqpConn = DB::connection('rfq');
$type = isset($input['type']) ? $input['type'] : 0; // type值存在,1-报价管理询价池,2-已领取的询价
// type值存在,1-报价管理询价池,2-已领取的询价,3-指定/领取的当前用户最新询价8条,4-指定/领取的当前用户最新催价8条
$type = isset($input['type']) ? $input['type'] : 0;
$list = $rqpConn->table('inquiry as a')->join('inquiry_items as b','a.id','=','b.inquiry_id');
......@@ -167,9 +169,13 @@ class InquiryModel extends Model
$list = $list->join('inquiry_items_assign as c', 'b.id', '=', 'c.inquiry_items_id')
->where('c.assign_uid', $user_id)
->where('b.status', 1); // 待报价
} else if ($type == 4) {
$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')
->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.customer_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.create_name,lie_a.create_time as inquiry_ctime,lie_b.*"))
->where(function ($query) use ($input, $type) {
foreach ($input as $k => $v){
$v = trim($v);
......@@ -183,7 +189,6 @@ class InquiryModel extends Model
break;
case "goods_name":
case "brand_name":
case "customer_name":
$query->whereRaw('lie_b.'.$k.' like "'.$v.'%"');
break;
case "status":
......@@ -212,15 +217,21 @@ class InquiryModel extends Model
$time = time() - 7200; // 待报价的询价两小时后在询价池展示
$query->orWhereRaw('(lie_b.assign_type=1 and lie_b.status=1 and lie_b.create_time < '.$time.')');
}
});
});
if ($type == 4) { // 多条重复催价情况下去重
$list = $list->groupBy('b.id');
}
// 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();
$list= $list->orderBy('b.id','desc')->paginate(@$input['limit'] ? $input["limit"] : 10, ['*'], 'p', @$page ? $page : 1)->toArray();
if (!$list) return [20001, '没有数据'];
......
......@@ -490,4 +490,68 @@ class QuoteModel extends Model
return [0, '修改报价成功'];
}
// 报价统计
public function quoteCount($input)
{
$data = [];
$curr_zero_time = strtotime(date('Y-m-d', time())); // 当日0点
switch ($input['time_day']) {
case 1:
for ($i = 0; $i < 24; $i++) {
$start_time = $curr_zero_time + $i * 3600;
$end_time = $start_time + 3600;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = $i.'点';
}
break;
case 7:
for ($i = 7; $i > 0; $i--) {
$start_time = $curr_zero_time - $i * 86400;
$end_time = $start_time + 86399;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400);
}
break;
case 30:
for ($i = 30; $i > 0; $i--) {
$start_time = $curr_zero_time - $i * 86400;
$end_time = $start_time + 86399;
$data['today_quote'][] = $this->getTodayQoutCount($input, $start_time);
$data['today_no_quote'][] = $this->getTodayNoQoutCount($input, $start_time, $end_time);
$data['x_axis_data'][] = date('Y-m-d', $curr_zero_time - $i * 86400);
}
break;
}
return [0, '', $data];
}
// 当日报价数
public function getTodayQoutCount($input, $start_time)
{
return $this->where('create_uid', $input['user_id'])->where('create_time', '>=', $start_time)->count();
}
// 当日未报价数
public function getTodayNoQoutCount($input, $start_time, $end_time)
{
return $this->from('inquiry_items as it')
->join('inquiry_items_assign as ia', 'it.id', '=', 'ia.inquiry_items_id')
->leftJoin('quote as q', 'it.id', '=', 'q.inquiry_items_id')
->where('ia.assign_uid', $input['user_id']) // 指定或领取给当前用户
->whereBetween('ia.create_time', [$start_time, $end_time])
->where('it.status', 1) // 未报价
->orWhereRaw("(lie_it.status in (2, 3, 4) and lie_q.create_uid != {$input['user_id']})") // 已报价且非当前用户
->count();
}
}
\ 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