客户生日

This commit is contained in:
meimei
2025-04-16 11:38:20 +08:00
parent 478e257bce
commit adcd9f7847
5 changed files with 96 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ class MessageWechatLogic extends BaseWechatLogic
'toWxid'=>$data['toWxid'], 'toWxid'=>$data['toWxid'],
'content'=>$data['content'], 'content'=>$data['content'],
//@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all' //@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all'
'ats'=>$data['ats'], // 'ats'=>$data['ats'],
]; ];
$res = $this->curl_post_json($url, $post_data); $res = $this->curl_post_json($url, $post_data);
return $res; return $res;

View File

@@ -32,6 +32,12 @@ class Tasktimer extends Controller
Mmodel::catch(function (){ Mmodel::catch(function (){
$this->returnPlan(); $this->returnPlan();
}); });
//生日通知
if (date("H:i:s") == "10:00:00"){
Mmodel::catch(function (){
$this->returnBirthdayPlan();
});
}
} }
/** /**
@@ -153,4 +159,78 @@ class Tasktimer extends Controller
return Tools::set_ok('发送成功'); return Tools::set_ok('发送成功');
} }
/**
* @return string 生日祝福
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
function returnBirthdayPlan(){
// 获取当前月和日
$customer_record = Db::table('fa_firmcustomer')
->where('birthday', date('m-d'))
->select();
if(empty($customer_record)){
Tools::log_to_write_txt(['无人生日,无需发送']);
return '';
}
foreach ($customer_record as $value){
//生日祝福模版
$birthday_record = Db::table('fa_mattertemplatecategorization')
->alias('m')
->join('fa_mattertemplatecategorizedcontent','fa_mattertemplatecategorizedcontent.mattertemplatecategorization_id = m.id')
->where('m.firm_id','in',[$value['firm_id'],0])
->where('m.mattertemplate_id',3)
->order(['m.firm_id'=>'desc','m.id'=>'desc'])
->field('fa_mattertemplatecategorizedcontent.content')
->find();
if(!empty($birthday_record)){
Tools::log_to_write_txt(['客户生日祝福计划,开始:$item'=>$value]);
$ret = $this->postBirthdayText($value,$birthday_record);
Tools::log_to_write_txt(['客户生日祝福计划,结束:$res'=>$ret]);
}
Tools::log_to_write_txt(['无生日祝福,无需发送']);
return '';
}
return '';
}
private function postBirthdayText($customer_record,$birthday_record){
//查询客户所绑定的ai客服
$ai_config = Db::table('fa_aicustomerservice')
->where('id',$customer_record['aicustomerservice_ids'])
->find();
if(empty($ai_config)){
return Tools::set_fail('有回访计划无ai客服服务该客户');
}
$base_url = $ai_config['server_url'];
if(empty($customer_record['rel_group'])){
return Tools::set_fail('客户无绑定群');
}
if(empty($customer_record['wx_nickname'])){
return Tools::set_fail('客户无绑定微信昵称');
}
if(empty($customer_record['rel_wx'])){
return Tools::set_fail('客户无绑定微信');
}
$logic = new MessageWechatLogic();
$logic->setBaseUrl($base_url);
$tokenArr = (new TokenWechatLogic())->getToken();
$data = [
'appId'=>$tokenArr['appId'],
'toWxid'=>$customer_record['rel_group'],//是群则发送群消息,否则发个人私人消息
'content'=>"@".$customer_record['wx_nickname']." ".$birthday_record['content'],
//@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all'
'ats'=>$customer_record['rel_wx'],
];
Tools::log_to_write_txt(['回访微信群客户,开始:$post_data'=>$data]);
$res = $logic->postGroupText($data);
Tools::log_to_write_txt(['回访微信群客户,结束:$res'=>$res]);
return Tools::set_ok('发送成功');
}
} }

View File

@@ -16,7 +16,13 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Age')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Age')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-age" min="0" name="row[age]" type="text" class="form-control datetimepicker" data-date-format="YYYY-MM-DD"> <input id="c-age" min="0" name="row[age]" type="number" class="form-control" >
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">出生月日:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-birthday" name="row[birthday]" type="text" class="form-control datetimepicker" data-date-format="MM-DD">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -16,7 +16,13 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Age')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Age')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-age" min="0" class="form-control" name="row[age]" type="number" value="{$row.age|htmlentities}"> <input id="c-age" class="form-control " name="row[age]" type="number" value="{$row.age|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">出生月日:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-birthday" class="form-control datetimepicker" name="row[birthday]" type="text" value="{$row.birthday|htmlentities}" data-date-format="MM-DD">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -48,7 +48,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{ {
name: 'addFollwup', name: 'addFollwup',
text: __('新增回访'), text: __('新增回访'),
title: __('新增回访new'), title: __('新增回访'),
classname: 'btn btn-xs btn-primary btn-dialog', classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-magic', icon: 'fa fa-magic',
url: 'firmcustomerfollowuprecord/newadd', url: 'firmcustomerfollowuprecord/newadd',