Commit fd2d929c authored by hujun's avatar hujun

系统设置

系统设置优化
parent 751fae8f
......@@ -13,10 +13,18 @@ use app\api_broker\service\LookShopService;
use app\extra\RedisExt;
use app\index\extend\Basic;
use app\model\SystemConfig;
use think\Cache;
use think\Request;
class Setting extends Basic
{
private $m_config;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->m_config = new SystemConfig();
}
/**
* 显示视图,新增和编辑设置数据
*
......@@ -29,11 +37,10 @@ class Setting extends Basic
if ($this->request->isAjax()) {
$data = [];
$config = new SystemConfig();
if ($this->request->isGet()) {
//获取数据
$data = $config->getSetting();
$data = $this->m_config->getSetting();
} else {
//新增或编辑数据
$data['is_privacy'] = (int)$this->params['is_privacy'];
......@@ -76,7 +83,7 @@ class Setting extends Basic
$config_data[3]['rule'] = json_encode(['agent_shop_num'=>$agent_shop_num]);
$config_data[3]['agent_id'] = $this->userId;
$config->insertSetting($config_data, true);
$this->m_config->insertSetting($config_data, true);
$look = new LookShopService();
$look->setLookNum($agent_shop_num);
......@@ -111,30 +118,97 @@ class Setting extends Basic
$data = [];
$msg = "";
try {
$config = new SystemConfig();
if ($this->request->isGet()) {
//获取数据
$data = $config->getSettingV2();
} else {
$config_name_arr = json_decode($this->params['config_name'], true);
foreach ($config_name_arr as $k =>$v) {
if (empty($v['id'])) {
$save_data[$k]['id'] = $v['id'];
//获取数据
$data = $this->m_config->getSettingV2();
if ($this->request->isPost()) {
foreach ($data as $k=>$v) {
if (empty($v['rule'])) {
continue;
}
$save_data[$k]['config_name'] = $v['name'];
$save_data[$k]['rule'] = json_encode(['rule']);
$save_data[$k]['config_type'] = $v['config_type'];
$save_data[$k]['agent_id'] = $v['agent_id'];
}
$rule = json_decode($v['rule'], true);
if (empty($rule)) {
continue;
}
foreach ($rule as $k2=>$v2) {
if (isset($this->params[$k2])) {
$rule[$k2] = $this->params[$k2];
}
}
$save_data[$k]['id'] = $v['id'];
$save_data[$k]['rule'] = json_encode($rule);
$save_data[$k]['agent_id'] = $this->userId;
}
if (!empty($save_data)) {
$config->saveAll($save_data);
$this->m_config->saveDataAll($save_data);
}
$this->configRedis($this->params);
}
} catch (\Exception $e) {
$msg = '内部错误:'.$e->getMessage();
}
return $this->response(200, $msg, $data);
}
/**
* @param $data
*/
private function configRedis($data) {
$new_client_hours = empty($data['new_client_hours']) ? 12 : $data['new_client_hours'];
$agent_shop_num = empty($this->params['agent_shop_num']) ? 5 : $this->params['agent_shop_num'];
$redis = RedisExt::getRedis();
$redis->set('s_down_time', $data['down_time']); //商铺自动下架天数
$redis->set('s_is_privacy', $data['is_privacy']); //是否使用隐号系统
$redis->set('s_day_num', $data['day_num']); //客户隐号绑定有效期(天数):
$redis->set('s_landlord_phone_day', $data['landlord_phone_day']); //房东隐号绑定有效期(天数):
$redis->set('s_new_client_hours', $new_client_hours); //新客户保护期有效小时数
$redis->set('s_lookNum', $agent_shop_num); //业务员最多可查看的商铺数量
$redis->set('s_agent_call_day', $data['agent_call_day']); //业务员多少天可以打多少电话
$redis->set('s_agent_call_number', $data['agent_call_number']); //业务员多少天可以打多少电话
return ;
}
/**
* 周竞赛搜索时间存储
*
* @return \think\Response
*/
public function configWeek() {
if (empty($this->params['site_id']) || empty($this->params['total_date_start']) || empty($this->params['total_date_end']) ||
empty($this->params['sort_date_start']) || empty($this->params['sort_date_end'])) {
return $this->response(101, '参数错误');
}
try {
$code = 200;
$msg = '';
$where['params'] = 'week_competition_'.$this->params['site_id'];
$id = $this->m_config->getSettingV2($where, 'id');
$rule['total_date_start'] = $this->params['total_date_start'];
$rule['total_date_end'] = $this->params['total_date_end'];
$rule['sort_date_start'] = $this->params['sort_date_start'];
$rule['sort_date_end'] = $this->params['sort_date_end'];
$save_data[0] = [
'rule' => json_encode($rule),
'params' => $where['params']
];
if (empty($id[0])) {
$this->m_config->insertSetting($save_data);
} else {
$save_data[0]['id'] = $id[0]['id'];
$this->m_config->saveDataAll($save_data);
}
} catch (\Exception $e) {
$msg = '内部错误:'.$e->getMessage();
$code = 101;
}
return $this->response($code, $msg);
}
}
\ No newline at end of file
......@@ -22,6 +22,15 @@ class SystemConfig extends BaseModel
return $this->insertAll($data, $replace);
}
/**
* @param array $data
* @return array|false
* @throws \Exception
*/
public function saveDataAll(array $data) {
return $this->saveAll($data);
}
/**
* 获取参数设置
*
......@@ -59,7 +68,7 @@ class SystemConfig extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getSettingV2( $where = [], $field = 'id,config_name,config_type,rule') {
public function getSettingV2( $where = [], $field = 'id,config_name,config_type,rule,params') {
return $this->field($field)
->where($where)
->select();
......
......@@ -215,6 +215,7 @@ Route::group('index', [
'select_by_phone' => ['index/remark/select_by_phone', ['method' => 'get|post']], //后台客户详情--客方搜索
'getSetting' => ['index/Setting/getSettingV2', ['method' => 'get|post']], //新增和修改全局参数设置
'configWeek' => ['index/Setting/configWeek', ['method' => 'post']], //周竞赛时间存储
'getMenu' => ['index/Auth/getMenu', ['method' => 'get|post']], //新增和修改全局参数设置
'reportListOne/:check_status' => ['index/Finance/reportList', ['method' => 'get'], ['check_status' => 1]], //财务 成交报告-未结单-第一级审核
'reportListTwo/:check_status' => ['index/Finance/reportList', ['method' => 'get'], ['check_status' => 2]], //财务 成交报告-未结单-第二级审核
......
......@@ -32,17 +32,24 @@ define (['doT', 'text!temp/setting_template_tpl.html', 'css!style/home.css'], fu
},
//提交数据
saveSetting : function () {
var param = {};
param.is_privacy = $("input[type='radio']:checked").val();
param.day_num = $("input[name='day_num']").val();
// param.day_num2 = $("input[name='day_num2']").val();
param.down_time = $("input[name='shop_day_num']").val();
param.new_client_hours = $("input[name='new_client_hours']").val();
param.agent_shop_num = $("input[name='agent_shop_num']").val();
param.landlord_phone_day = $("input[name='landlord_phone_day']").val();
param.agent_call_day = $("input[name='agent_call_day']").val();
param.agent_call_number = $("input[name='agent_call_number']").val();
var param = {};
var t = $('form').serializeArray();
$.each(t, function() {
param[this.name] = this.value;
});
// console.log(param);
//alert(JSON.stringify(d));
// var param = {};
// param.is_privacy = $("input[type='radio']:checked").val();
// param.day_num = $("input[name='day_num']").val();
// param.down_time = $("input[name='down_time']").val();
// param.new_client_hours = $("input[name='new_client_hours']").val();
// param.agent_shop_num = $("input[name='agent_shop_num']").val();
// param.landlord_phone_day = $("input[name='landlord_phone_day']").val();
// param.agent_call_day = $("input[name='agent_call_day']").val();
// param.agent_call_number = $("input[name='agent_call_number']").val();
//
$.ajax ({
url: '/admin.php/index/getSetting',
type: 'POST',
......
<script id="setting_list_tpl" type="text/template">
<div class="form-group">
[% for(var item in it){ %]
[% if (it[item]['config_type'] == 10) { %]
[% if (it[item]['params'] == 'down_time') { %]
<label class="col-sm-4 control-label" style="text-align: right">商铺自动下架天数:</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="shop_day_num" placeholder="商铺自动下架天数" value="[%= JSON.parse(it[item]['rule']).down_time %]">
<input type="number" class="form-control btn5" name="down_time" placeholder="商铺自动下架天数" value="[%= JSON.parse(it[item]['rule']).down_time %]">
</div>
[% } else if (it[item]['config_type'] == 20) { %]
[% } else if (it[item]['params'] == 'privacy_number') { %]
<label class="col-sm-4 control-label" style="text-align: right">是否使用隐号系统:</label>
<div class="col-sm-8">
<div class="radio" style="display: inline-block">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="0"
[% if(it.is_privacy == 0) { %] checked [% } %]>关闭
<input type="radio" name="is_privacy" id="optionsRadios1" value="0"
[% if(JSON.parse(it[item]['rule']).is_privacy == 0) { %] checked [% } %]>关闭
</label>
</div>
<div class="radio" style="display: inline-block">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="1" [% if(it.is_privacy == 1) { %] checked [% } %]>阿里云
<input type="radio" name="is_privacy" id="optionsRadios2" value="1" [% if(JSON.parse(it[item]['rule']).is_privacy == 1) { %] checked [% } %]>阿里云
</label>
</div>
<div class="radio" style="display: inline-block">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios3" value="2" [% if(it.is_privacy == 2) { %] checked [% } %]>容联云
<input type="radio" name="is_privacy" id="optionsRadios3" value="2" [% if(JSON.parse(it[item]['rule']).is_privacy == 2) { %] checked [% } %]>容联云
</label>
</div>
</div>
<label class="col-sm-4 control-label" style="text-align: right">客户隐号绑定有效期(天数):</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="day_num" placeholder="隐号绑定天数" value="[%= it['day_num'] %]">
<input type="number" class="form-control btn5" name="day_num" placeholder="隐号绑定天数" value="[%= JSON.parse(it[item]['rule']).day_num %]">
</div>
<!--房东隐号绑定有效期-->
<label class="col-sm-4 control-label" style="text-align: right">房东隐号绑定有效期(天数):</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="landlord_phone_day" placeholder="隐号绑定天数" value="[%= it['landlord_phone_day'] %]">
<input type="number" class="form-control btn5" name="landlord_phone_day" placeholder="隐号绑定天数" value="[%= JSON.parse(it[item]['rule']).landlord_phone_day %]">
</div>
<label class="col-sm-4 control-label" style="text-align: right">业务员拨打电话限制:</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="agent_call_day" placeholder="天数" value="[%= it['agent_call_day'] %]">
<input type="number" class="form-control btn5" name="agent_call_number" placeholder="次数" value="[%= it['agent_call_number'] %]">
<input type="number" class="form-control btn5" name="agent_call_day" placeholder="天数" value="[%= JSON.parse(it[item]['rule']).agent_call_day %]">
<input type="number" class="form-control btn5" name="agent_call_number" placeholder="次数" value="[%= JSON.parse(it[item]['rule']).agent_call_number %]">
</div>
[% } else if (it[item]['config_type'] == 30) { %]
[% } else if (it[item]['params'] == 'new_client_hours') { %]
<label class="col-sm-4 control-label" style="text-align: right">新客户保护期有效小时数:</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="new_client_hours" placeholder="新客户保护期有效小时数" value="[%= it['new_client_hours'] %]">
<input type="number" class="form-control btn5" name="new_client_hours" placeholder="新客户保护期有效小时数" value="[%= JSON.parse(it[item]['rule']).new_client_hours %]">
</div>
[% } else if (it[item]['config_type'] == 40) { %]
[% } else if (it[item]['params'] == 'agent_shop_num') { %]
<label class="col-sm-4 control-label" style="text-align: right">业务员最多可查看的商铺数量:</label>
<div class="col-sm-8">
<input type="number" class="form-control btn5" name="agent_shop_num" placeholder="业务员最多可查看的商铺数量" value="[%= it['agent_shop_num'] %]">
<input type="number" class="form-control btn5" name="agent_shop_num" placeholder="业务员最多可查看的商铺数量" value="[%= JSON.parse(it[item]['rule']).agent_shop_num %]">
</div>
[% } %]
[% } %]
......
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