新增推广公司编辑功能

master
chenzhi 5 years ago
parent 6ea7a581f5
commit 4e28b39999

@ -249,6 +249,8 @@ class PromoteCompanyController extends ThinkController
if (empty($data)) {
$this->error('数据异常', U('lists'));
}
$data['contact_begin']=date("Y-m-d",$data['contact_begin']);
$data['contact_end']=date("Y-m-d",$data['contact_end']);
$this->assign('data', $data);
$this->display();
}
@ -260,80 +262,29 @@ class PromoteCompanyController extends ThinkController
$model = M($this->modelName, 'tab_');
if ($_POST) {
$company_name = I('post.company_name', '');
$status = intval(I('post.status', 1));
$id = intval(I('post.id', 0));
if (empty($company_name)) {
$this->error('请输入推广公司名称');
}
if (empty(I('post.settlement_contact'))) {
$this->error('请输入结算联系人');
}
if (empty(I('post.contact_phone'))) {
$this->error('请输入联系人电话');
}
$pattern = "/^1[3|4|5|6|7|8|9]\\d{9}$/i";//手机号验证修改
if(!preg_match($pattern, I('post.contact_phone'))) {
$this->error("手机号码格式不合法");
return false;
}
if (empty(I('post.address'))) {
$this->error('请输入所在地址');
}
if (empty(I('post.bank_card'))) {
$this->error('请输入银行卡号');
}
$bank_card_pattern = "/^\d{10,19}$/u";
if (!preg_match($bank_card_pattern, I('post.bank_card'))) {
$this->error('卡号格式错误');
return false;
}
if (empty(I('post.bank_cardname'))) {
$this->error('请输入银行卡名');
}
if (empty(I('post.bank_name'))) {
$this->error('请输入收款银行');
}
if (empty(I('post.bank_address'))) {
$this->error('请输入开户网点');
}
if (!in_array($status, [0, 1]) || $id == 0) {
$this->error('参数异常');
}
if (!empty(I('post.content'))) {
$save['content'] = I('post.content');
}
$data = $model->field('id,company_name')->find($id);
if (empty($data)) {
$this->error('数据异常');
}
$map['company_name'] = $company_name;
$res = $model->where($map)->getField('id');
if ($res && $res != $id) {
$this->error('推广公司已存在');
}
$time = time();
$save['id'] = $id;
$save['company_name'] = $company_name;
$save['status'] = $status;
$save = I('post.');//前端已经验证
$save['create_time'] = $time;
$save['last_up_time'] = $time;
$save['settlement_contact'] = I('post.settlement_contact');
$save['contact_phone'] = I('post.contact_phone');
$save['address'] = I('post.address');
$save['bank_card'] = I('post.bank_card');
$save['bank_cardname'] = I('post.bank_cardname');
$save['bank_name'] = I('post.bank_name');
$save['bank_address'] = I('post.bank_address');
$save['contact_begin']=strtotime($save['contact_begin']);
$save['contact_end']=strtotime($save['contact_end']);
if(isset($save['resources'])){
$save['resources'] = json_encode($save['resources'],JSON_UNESCAPED_UNICODE);
}
$res = $model->save($save);
if ($res === false) {
$this->error('保存失败');
if ($res) {
\Think\Log::actionLog('PromoteCompany/edit', 'partner', $res);
$array=array(
"info"=>"修改成功",
"status"=>1
);
$this->ajaxReturn($array);
} else {
\Think\Log::actionLog('PromoteCompany/edit', 'PromoteCompany', $id);
$this->success('保存成功', U('lists'));
$this->ajaxReturn(array(
'status' => 0,
'info' => "修改失败"
));
}
} else {
$id = $_REQUEST['id'] ?: 0;
@ -342,6 +293,9 @@ class PromoteCompanyController extends ThinkController
if (empty($data)) {
$this->error('数据异常', U('lists'));
}
$data['contact_begin']=date("Y-m-d",$data['contact_begin']);
$data['contact_end']=date("Y-m-d",$data['contact_end']);
$this->assign('data', $data);
$this->display();
}
@ -402,15 +356,30 @@ class PromoteCompanyController extends ThinkController
public function delFile()
{
$id = $_REQUEST['id'];
$index = $_REQUEST['index'] ?: false;
$file_path = $_REQUEST['file_path'] ?: false;
unlink("./".$file_path);
if($id == 0){
//未存入数据库,不用管
unlink("./".$file_path);
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}else{
//需要修改
$array = array(
"resources"=>json_encode($_REQUEST['resources'],JSON_UNESCAPED_UNICODE)
);
$res = M($this->modelName, 'tab_')->where("id='{$id}'")->save($array);
if($res === false){
$this->ajaxReturn(array(
'status' => 0,
'info' => "删除保存失败"
));
}else{
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}
}
# code...
}

@ -37,7 +37,7 @@
<!-- 标签页导航 -->
<div class="tab-wrap">
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">{$meta_title}</h3>
<h3 class="page_title">推广公司编辑</h3>
</div>
<div class="tab-content tabcon1711">
@ -63,11 +63,11 @@
<td class="l">合同期限:</td>
<td class="r" >
<div class="input-list" style="margin:0;">
<input type="text" readonly id="contact_begin" name="contact_begin" class="" value="{$data.contact_begin}""
<input type="text" readonly id="contact_begin" name="contact_begin" class="" value="{$data.contact_begin}"
placeholder="合同开始时间" />
&nbsp;-&nbsp;
<div class="input-append date" id="datetimepicker" style="display:inline-block">
<input type="text" readonly id="contact_end" name="contact_end" class="" value="{:I('contact_end')}"
<input type="text" readonly id="contact_end" name="contact_end" class="" value="{$data.contact_end}"
placeholder="合同结束时间" />
<span class="add-on"><i class="icon-th"></i></span>
</div>
@ -77,7 +77,7 @@
<tr>
<td class="l">开票税点:</td>
<td class="r" >
<input type="number" class="txt" name="fax_ratio" value="0" placeholder="请输入开票税点">
<input type="number" class="txt" name="fax_ratio" value="{$data.fax_ratio}" placeholder="请输入开票税点">
<span>%</span>
</td>
</tr>
@ -87,8 +87,10 @@
<div class="input-list input-list-server search_label_rehab" style="margin:0;">
<select id="company_type" name="company_type" class="select_gallery" style="width: 215px;">
<option value="">请选择公司性质</option>
<option value="1">公司</option>
<option value="2">个人</option>
<option value="1" <if condition="$data['company_type'] eq 1">selected
</if>>公司</option>
<option value="2" <if condition="$data.company_type eq 2">selected
</if>>个人</option>
</select>
</div>
</td>
@ -99,8 +101,10 @@
<div class="input-list input-list-server search_label_rehab" style="margin:0;">
<select id="is_sign_contact" name="is_sign_contact" class="select_gallery" style="width: 215px;">
<option value="">请选择是否签署合同</option>
<option value="0"></option>
<option value="1"></option>
<option value="0" <if condition="$data['is_sign_contact'] eq 0">selected
</if>>否</option>
<option value="1" <if condition="$data['is_sign_contact'] eq 1">selected
</if>>是</option>
</select>
</div>
</td>
@ -111,10 +115,14 @@
<div class="input-list input-list-server search_label_rehab" style="margin:0;">
<select id="company_belong" name="company_belong" class="select_gallery" style="width: 215px;">
<option value="">请选择团体归属</option>
<option value="0">内团</option>
<option value="1">外团</option>
<option value="2">外团-分发</option>
<option value="3">其他</option>
<option value="0" <if condition="$data['company_belong'] eq 0">selected
</if>>内团</option>
<option value="1" <if condition="$data['company_belong'] eq 1">selected
</if>>外团</option>
<option value="2" <if condition="$data['company_belong'] eq 2">selected
</if>>外团-分发</option>
<option value="3" <if condition="$data['company_belong'] eq 3">selected
</if>>其他</option>
</select>
</div>
</td>
@ -123,25 +131,25 @@
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>联系结算人:</td>
<td class="r" >
<input type="text" class="txt " name="settlement_contact" value="" placeholder="请输入结算联系人">
<input type="text" class="txt " name="settlement_contact" value="{$data.settlement_contact}" placeholder="请输入结算联系人">
</td>
</tr>
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>联系电话:</td>
<td class="r" >
<input type="text" class="txt " name="contact_phone" value="" placeholder="请输入联系电话">
<input type="text" class="txt " name="contact_phone" value="{$data.contact_phone}" placeholder="请输入联系电话">
</td>
</tr>
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>所在地址:</td>
<td class="r" >
<input type="text" class="txt " name="address" value="" placeholder="请输入所在地址">
<input type="text" class="txt " name="address" value="{$data.address}" placeholder="请输入所在地址">
</td>
</tr>
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>银行卡号:</td>
<td class="r" >
<input type="text" class="txt " name="bank_card" value="" placeholder="请输入银行卡号">
<input type="text" class="txt " name="bank_card" value="{$data.bank_card}" placeholder="请输入银行卡号">
</td>
</tr>
<!-- <tr>
@ -153,19 +161,19 @@
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>收款银行:</td>
<td class="r" >
<input type="text" class="txt " name="bank_name" value="" placeholder="请输入收款银行">
<input type="text" class="txt " name="bank_name" value="{$data.bank_name}" placeholder="请输入收款银行">
</td>
</tr>
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px">*</i>开户网点:</td>
<td class="r" >
<input type="text" class="txt " name="bank_address" value="" placeholder="请输入开户网点">
<input type="text" class="txt " name="bank_address" value="{$data.bank_address}" placeholder="请输入开户网点">
</td>
</tr>
<tr>
<td class="l"><i class="mustmark" style="margin-left:-7px"></i>备注:</td>
<td class="r" >
<input type="text" class="txt " name="content" value="" placeholder="">
<input type="text" class="txt " name="content" value="{$data.content}" placeholder="">
</td>
</tr>
<tr>
@ -173,10 +181,12 @@
<td class="r table_radio">
<span class="form_radio table_btn">
<label>
<input type="radio" class="inp_radio" value="1" name="status" checked> 开启
<input type="radio" class="inp_radio" value="1" name="status" <if condition="$data['status'] eq 1">checked
</if>> 开启
</label>
<label>
<input type="radio" class="inp_radio" value="0" name="status"> 关闭
<input type="radio" class="inp_radio" value="0" name="status" <if condition="$data['status'] eq 0">checked
</if>> 关闭
</label>
</span>
<span class="notice-text"></span>
@ -188,12 +198,15 @@
<div class="coin-detail" data-url="{:U('PromoteCompany/addfile')}" style="margin:0px;background: #fff;color: #333;font-weight: 400;border: 1px solid #777;">
添加
</div>
<span style="margin-left:30px;color: red;">
* 新增加文档需要保存修改后生效,删除文档即时生效(取消保存修改也生效,请慎重删除)
</span>
</td>
</tr>
</tbody>
</table>
<table border="1" style="width: 600px;text-align: center;" cellspacing="0" cellpadding="0" id="docShow">
<table border="1" style="width: 600px;text-align: center;margin:10px 0 0 60px;" cellspacing="0" cellpadding="0" id="docShow">
</table>
</div>
@ -248,9 +261,69 @@
$('#submit').click(function(){
$('#form').submit();
});
var PROMOTE = {
juicerFun(){
var tpl =$("#doctpl").html();
var html = juicer(tpl, {list:doc});
$("#docShow").html(html);
PROMOTE.juicerEvent();
},
juicerEvent(){
$(".filedown,.filedel").off("click");
$(".filedown").on("click",function(){
var url = window.location.protocol+"//"+window.location.host+$(this).data("path");
// window.open(url,"_blank");
var link = document.createElement('a');
link.setAttribute("download", "");
link.href = url;
link.click()
});
$(".filedel").on("click",function(){
layer.confirm('删除将即时生效,并且无法回退。请慎重选择', {icon: 2, title:'删除提示'}, function(index){
var path = $(this).data("path");
var index = $(this).data("index");
var id = {$data.id};
var doccopy = doc.concat();
doccopy.splice(index,1)
$.ajax({
url:"{:U('PromoteCompany/delFile')}",
type:"post",
data:{
"id":id,
"file_path":path,
"resources":doccopy
},
dataType:"json",
success:function(data){
if(data.status == 1){
doc.splice(index,1);
layer.msg(data.info,function(){
PROMOTE.juicerFun();
});
}else{
layer.alert(data.info);
}
},
error:function(e){
}
});
});
})
}
}
</script>
<script>
var doc = [];
var doc = {$data.resources};
if(!doc){
doc = [];
}
var id = {$data.id};
PROMOTE.juicerFun();
function addFile(info) {
doc.push(info);
layer.closeAll();
@ -310,13 +383,14 @@
layer.msg('开始时间必须小于等于结束时间');
return false;
}
//验证通过
if(doc.length > 0){
cres.resources = doc;
}
//资源不需要二次修改
cres.resources = doc;
cres.id = id;
//添加
$.ajax({
url:"{:U('PromoteCompany/add')}",
url:"{:U('PromoteCompany/edit')}",
type:"post",
data:cres,
dataType:"json",
@ -335,51 +409,7 @@
});
})
var PROMOTE = {
juicerFun(){
var tpl =$("#doctpl").html();
var html = juicer(tpl, {list:doc});
$("#docShow").html(html);
PROMOTE.juicerEvent();
},
juicerEvent(){
$(".filedown,.filedel").off("click");
$(".filedown").on("click",function(){
var url = window.location.protocol+"//"+window.location.host+$(this).data("path");
// window.open(url,"_blank");
var link = document.createElement('a');
link.setAttribute("download", "");
link.href = url;
link.click()
});
$(".filedel").on("click",function(){
var path = $(this).data("path");
var index = $(this).data("index");
console.log(index);
var id = 0;
$.ajax({
url:"{:U('PromoteCompany/delFile')}",
type:"post",
data:{
"id":0,
"file_path":path
},
dataType:"json",
success:function(data){
if(data.status == 1){
doc.splice(index,1)
PROMOTE.juicerFun();
}else{
layer.alert(data.info);
}
},
error:function(e){
}
});
})
}
}
</script>
</block>

Loading…
Cancel
Save