Commit c3de7bd5 authored by clone's avatar clone

1

parent 5330c2e1
......@@ -179,15 +179,16 @@ class LookShopService
/**
* 升级经纪人看铺次数
* @param int $agent_id
* @param bool $if_up 是否可以继续升级
* @return bool
*/
public function setAgentLookNum(int $agent_id): bool
public function setAgentLookNum(int $agent_id,bool $if_up = false): bool
{
if (!$this->redis) {
return false;
}
$agentUpNum = $this->redis->hGet(self::LOOK_UP_NUM . $this->nowTime, $agent_id);
if ($agentUpNum >= 2) {
if ($agentUpNum >= 2 && !$if_up) {
return false;
}
$upLookNum = (int)$agentUpNum + 1;
......
......@@ -13,6 +13,9 @@ namespace app\index\controller;
use app\api_broker\service\LookShopService;
use app\api_broker\service\VerifyService;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\ALookShopWhitelist;
use app\model\SystemConfig;
use app\model\TLookShopModel;
use app\model\TLookShopUser;
use app\model\Users;
......@@ -20,11 +23,12 @@ use app\model\Users;
class LookShop extends Basic
{
protected $tLookShopModel;
protected $lookShopService_;
public function __construct($request = null)
{
parent::__construct($request);
$this->lookShopService_ = new LookShopService();
$this->tLookShopModel = new TLookShopModel();
}
......@@ -93,8 +97,8 @@ class LookShop extends Basic
"page_size" => 15
);*/
if(empty($params["user_id"]) || empty($params["agent_id"])){
return $this->response("101","请求参数错误");
if (empty($params["user_id"]) || empty($params["agent_id"])) {
return $this->response("101", "请求参数错误");
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 25 : $params['page_size'];
......@@ -140,13 +144,149 @@ class LookShop extends Basic
public function getShopLookList()
{
$params = $this->params;
if(empty($params["user_id"])){
return $this->response("101","请求参数错误");
if (empty($params["user_id"])) {
return $this->response("101", "请求参数错误");
}
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$s_look_Shop = new LookShopService();
$result = $s_look_Shop->getShopLookListPc($params['user_id'],$pageNo,$pageSize);
$result = $s_look_Shop->getShopLookListPc($params['user_id'], $pageNo, $pageSize);
return $this->response("200", "success", $result);
}
/**
* 升级经纪人的看铺数量
* @return \think\Response
*/
public function setAgentLookNum()
{
$params = $this->params;
/* $params = array(
"agent_id" => 1,
"submit_agent_id" => 1,
);*/
if (!isset($params["agent_id"]) || !isset($params["submit_agent_id"])) {
return $this->response("101", "请求参数错误");
}
$aLookShopWhitelistModel = new ALookShopWhitelist();
$where["agent_id"] = $params["agent_id"];
$where["is_del"] = 0;
$arr = $aLookShopWhitelistModel->getWhitelistList("id", $where, 1, 20);
if (count($arr) <= 0) {
return $this->response("101", "此经纪人不在白名单");
}
$is_ok = $this->lookShopService_->setAgentLookNum($params["agent_id"], true);
if ($is_ok) {
return $this->response("200", "request success", []);
} else {
return $this->response("101", "升级看铺数量失败");
}
}
/**
* 新增白名单
* @return \think\Response
*/
public function addWhitelist()
{
$params = $this->params;
/* $params = array(
"agent_id" => 1,
);*/
$agent_id = $params["agent_id"];
if (!isset($params["agent_id"])) {
return $this->response("101", "请求参数错误");
}
$aLookShopWhitelistModel = new ALookShopWhitelist();
$where["agent_id"] = $agent_id;
$arr = $aLookShopWhitelistModel->getWhitelistList("id,is_del", $where, 1, 20);
$is_ok = 0;
if (count($arr) <= 0) {
$inset_arr["agent_id"] = $agent_id;
$inset_arr["create_time"] = date("Y-m-d H:i:s", time());
$inset_arr["update_time"] = date("Y-m-d H:i:s", time());
$is_ok = $aLookShopWhitelistModel->addWhitelist($inset_arr);
} else {
if ($arr[0]["is_del"] == 0) {
return $this->response("101", "此经纪人已在白名单,请勿重复添加");
} else {//修改is_del值
$update_where["agent_id"] = $agent_id;
$update_params["is_del"] = 0;
$is_ok = $aLookShopWhitelistModel->updateWhitelist($update_where, $update_params);
}
}
if ($is_ok) {
return $this->response("200", "request success", []);
} else {
return $this->response("101", "添加失败");
}
}
/**
* 获取白名单列表
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getWhitelist()
{
$params = $this->params;
/* $params = array(
"phone" => "112312312",
"name" => "12312",
);*/
$where_ = [];
if (isset($params["name"])) {
$where_["name"] = array("like", "%" . trim($params['name']) . "%");
}
if (isset($params["phone"])) {
$where_["phone"] = array("like", "%" . trim($params['phone']) . "%");
}
$where_["is_del"] = 0;
$aLookShopWhitelistModel = new ALookShopWhitelist();
$field = "id,agent_id,is_del";
$agentList = $aLookShopWhitelistModel->getWhitelistList($field, $where_, 1, 50);
if (count($agentList) <= 0) {
return $this->response("200", "request null");
}
$systemConfigModel = new SystemConfig();
$lookNum = 0;
$data = $systemConfigModel->getSetting(["config_type" => 40], "rule");
if ($data && $data["agent_shop_num"] > 0) {
$lookNum = $data["agent_shop_num"];
}
foreach ($agentList as $key => $item) {
$agentModel = new AAgents();
$agent_where["agent_id"] = $item["agent_id"];
$field = "a.name,a.img,a.phone,b.store_name,c.district_name";
$arr = $agentModel->getAgentsInfoByAgentId($field, $agent_where);
$agentList[$key]["store_name"] = $arr[0]["store_name"];
$agentList[$key]["district_name"] = $arr[0]["district_name"];
$upNum = $this->lookShopService_->getAgentUpNum($item["agent_id"]); //已升级次数
$agentList[$key]["is_upgrade"] = $upNum;
$agentList[$key]["can_look_num"] = $lookNum * $upNum;
$agentList[$key]["name"] = $arr[0]["name"];
$agentList[$key]["phone"] = $arr[0]["phone"];
}
$result["list"] = $agentList;
return $this->response("200", "request success", $result);
}
public function whitelistIndex()
{
return view("/look_shop/whitelist");
}
}
\ No newline at end of file
{layout name="global/frame_two_tpl" /}
<input type="hidden" class="page-load" id="whitelist" />
<!--导航star-->
<!-- Sidebar -->
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container">
<div class="row">
<div class="">
<div class="panel panel-default">
<div class="panel-heading breadcrumb">
<!--<li><a href="#">首页轮播图</a></li>-->
<li class="active">升级铺数</li>
<div class="pull-right">
<ul class="bread_btn">
<li>
<a href="#modal-add-do" data-toggle="modal" id="add_whitelist" class="btn btn-default"><i class="icon-plus"></i>
新增白名单</a>
</li>
</ul>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>所在部门</th>
<th>所在门店</th>
<th>姓名</th>
<th>手机号</th>
<th>当日可看铺数</th>
<th>已升级次数</th>
<th>操作</th>
</tr>
</thead>
<tbody id="whitelist_body">
</tbody>
</table>
</div>
</div>
</div>
<input type="hidden" value="0" id="type" />
</div>
</div>
</div>
</div>
<?php
namespace app\model;
use think\Db;
use think\Model;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/10/10
* Time: 10:49
*/
class ALookShopWhitelist extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'a_look_shop_whitelist';
protected $db_;
public function __construct()
{
$this->db_ = Db($this->table);
}
/**
* @param $field
* @param $params
* @param $page_no
* @param $page_size
* @return mixed
*/
public function getWhitelistList($field, $params, $page_no, $page_size)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if (isset($params["is_del"])) {
$where_["is_del"] = $params["is_del"];
}
return $this->db_
->field($field)
->where($where_)
->order("update_time desc")
->page($page_no)
->limit($page_size)
->select();
}
/**
* @param $params
* @return int
*/
public function addWhitelist($params)
{
Db::startTrans();
try {
$this->db_->insert($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $where
* @param $params
* @return int
*/
public function updateWhitelist($where, $params)
{
Db::startTrans();
try {
$this->where($where)->update($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
}
\ No newline at end of file
......@@ -610,6 +610,11 @@ Route::group('index', [
'clinchMapInfo' => ['index/ClinchMap/clinchMapInfo', ['method' => 'get | post']],
'whitelistIndex' => ['index/LookShop/whitelistIndex', ['method' => 'get']],
'getWhitelist' => ['index/LookShop/getWhitelist', ['method' => 'get']],
'addWhitelist' => ['index/LookShop/addWhitelist', ['method' => 'post']],
'setAgentLookNum' => ['index/LookShop/setAgentLookNum', ['method' => 'get | post']],
]);
......
......@@ -105,7 +105,7 @@ define (['doT', 'text!temp/banner_template_tpl.html', 'ckfinder', 'ckfinderStart
banner.addOrUpdateBanner (params);
});
$ ("#confirm_delete").click (function () {
$ ("#confirm_up").click (function () {
var params = {};
params.id = $ ("#delete_id").val ();
params.is_show = 1;
......
/**
* Created by zw on 2019/10/10.
*/
define(['doT', 'text!temp/whitelist_template_tpl.html', 'css!style/home.css', 'blow-up'], function (doT, template) {
var whitelist = {
datas: "",
imageName: "",
agent_id: 0,
init: function () {
//初始化dot
$("body").append(template);
whitelist.event();
whitelist.getWhitelist();
},
event: function () {
var that = this;
$("#save_whitelist").click(function () {
var params = {};
var vals = $("#agent_id").val();
if (!vals || vals == null) {
alert("请选择经纪人");
return false;
}
params.agent_id = whitelist.agent_id;
whitelist.addWhitelist(params);
});
$("#confirm_up").click(function () {
var params = {};
params.agent_id = $("#up_agent_id").val();
if (!params.agent_id || params.agent_id == null) {
alert("要升级的经纪人id不能为空");
return false;
}
var user_info_obj = JSON.parse(decodeURIComponent(localStorage.getItem('pcUserInfo'))); //读取缓存
params.submit_agent_id = user_info_obj.id;
whitelist.upLookShop(params);
});
$(document).delegate(".up_look_shop", "click", function () {
$("#up_agent_id").val($(this).attr("data-agent_id"));
});
$(document).delegate(".phone_jia", "click", function () {
/*手机检索姓名*/
var ldHtml = $('.phone_list');
var stopstatus = true;
var valueCurrent = '';
var ajaxObj;
$(function () {
$(document).on('input', '.phone_jia', function (e) {
e.preventDefault();
e.stopPropagation();
var _this = $(this);
_this.next().css("display", "block");
valueCurrent = _this.val();
if (valueCurrent != '') {
resetLoad();
loadMain(valueCurrent, _this.next());
} else {
ldHtml.html('');
return false;
}
});
});
function resetLoad() {
if (ajaxObj) {
ajaxObj.abort();
}
ldHtml.html('');
stopstatus = true;
}
function loadMain(phone, obj) {
ajaxObj = $.ajax({
type: "GET",
url: '/index/getBroker_new',
data: {
'phone': phone
},
timeout: 10000,
dataType: "json",
beforeSend: function () {
},
success: function (data) {
if (data.code === 200) {
$("#agents_list").show();
var _html = '';
$.each(data.data, function (i, data) {
_html += '<li class="add_phone"><span class="id">' + data['id']
+ '-</span><span class="phone_name">' + data['name']
+ '</span><span class="phone_span">-</span><span class="phone-phone">'
+ data['phone'] + '</span><span class="hidden store_id">'
+ data['store_id'] + '</span></li>';
});
$("#agents_list").html(_html);
}
},
error: function () {
},
complete: function (xhr, textStatus) {
if (textStatus === "timeout") {
/*处理超时的逻辑*/
alert("请求超时");
}
}
});
}
});
$(document).delegate(".add_phone", "click", function () {
whitelist.addPhone($(this));
});
},
/*获取 list*/
getWhitelist: function () {
var params = {};
$.ajax({
url: '/admin.php/index/getWhitelist',
type: 'get',
async: true,
data: params,
dataType: 'json',
success: function (data) {
var temp = document.getElementById('whitelist_template_tpl').innerHTML;
var doTtmpl = doT.template(temp);
$("#whitelist_body").html(doTtmpl(data.data.list));
}
});
},
addWhitelist: function (params) {
$.ajax({
url: '/admin.php/index/addWhitelist',
type: 'POST',
async: true,
data: params,
dataType: 'json',
success: function (data) {
$("#modal-add-do").modal('hide');
if (data.code == "101") {
alert(data.msg);
return false;
}
whitelist.getWhitelist();
}
});
},
upLookShop: function (params) {
$.ajax({
url: '/admin.php/index/setAgentLookNum',
type: 'POST',
async: true,
data: params,
dataType: 'json',
success: function (data) {
$("#modal-up").modal('hide');
if (data.code == "101") {
alert(data.msg);
return false;
}
whitelist.getWhitelist();
}
});
},
addPhone: function (obj) {
var phone_name = $(obj).find(".phone_name").html();
var phone_phone = $(obj).find(".phone-phone").html();
var phone_span = $(obj).find(".phone_span").html();
var id = $(obj).find(".id").html();
var val = id + phone_name + phone_span + phone_phone;
whitelist.agent_id = id.substring(0, id.length - 1)
$("input[name='agent_id']").val(val);
$(obj).parent().hide();
$("#agents_list").html('');
return;
}
};
return whitelist
});
<script id="whitelist_template_tpl" type="text/template">
[% if( it ) { %]
[% for(var item in it){ %]
<tr>
<td>[%= it[item]["district_name"] %]</td>
<td>[%= it[item]["store_name"] %]</td>
<td>[%= it[item]["name"] %]</td>
<td>[%= it[item]["phone"] %]</td>
<td>[%= it[item]["can_look_num"] %]</td>
<td>[%= it[item]["is_upgrade"] %]</td>
<td>
<a class="btn1 btn-success up_look_shop" href="#modal-up" data-toggle="modal"
data-agent_id="[%= it[item]['agent_id'] %]" >
升级查看铺数
</a>
</td>
</tr>
[% } %]
[% }else{ %]
<tr>
<td colspan="7" style="text-align:center;"> 暂无数据</td>
</tr>
[% } %]
</script>
<!-- /#wrapper -->
<!-- /#删除模态框 -->
<div class="modal fade" id="modal-up" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
&times;
</button>
<h4 class="modal-title">
升级看铺数
</h4>
</div>
<div class="modal-body">
<div class="modal-body">
<input type="hidden" value="" id="up_agent_id"/>
确认升级吗?
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="button" class="btn btn-primary" id="confirm_up">
确认
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
<!-- /#新增编辑 -->
<div class="modal fade" id="modal-add-do" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="editor_modal_title">新增白名单</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">请选择经纪人:</label>
<div class="col-sm-9">
<input type="text" class="form-control btn6 phone_jia" name="agent_id" id="agent_id" placeholder="请输入姓名或手机号">
<div class="col-sm-9">
<ul class="list-unstyled" id="agents_list"></ul>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="save_whitelist">保存修改</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
\ 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 to comment