This commit is contained in:
2025-03-27 21:24:55 +08:00
parent 04cb00948d
commit 2e6ffc2a25
8 changed files with 164 additions and 7 deletions

View File

@@ -0,0 +1,23 @@
<?php
/*
* description
* authorwh
* email
* createTime{2025/3/27} {19:49}
*/
namespace app\admin\controller;
use app\api\logic\MessageLogic;
use app\api\logic\TokenLogic;
use think\Controller;
use think\Db;
use wanghua\general_utility_tools_php\tool\Tools;
class Wxmessage extends Controller
{
///message/postText
}

View File

@@ -1,7 +1,7 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Firmcustomerfollowuprecord_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('回访客户')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-firmcustomerfollowuprecord_id" min="0" data-rule="required"
disabled
@@ -18,7 +18,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Followup_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-followup_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[followup_time]" type="text" value="{:date('Y-m-d H:i:s')}">
<input id="c-followup_time" class="form-control datetimepicker" data-date-format="HH:mm:ss" data-use-current="true" name="row[followup_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group layer-footer">

View File

@@ -1,7 +1,7 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Firmcustomerfollowuprecord_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('回访客户')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-firmcustomerfollowuprecord_id" min="0" data-rule="required" data-source="firmcustomerfollowuprecord/index" class="form-control selectpage" name="row[firmcustomerfollowuprecord_id]" type="text" value="{$row.firmcustomerfollowuprecord_id|htmlentities}">
</div>
@@ -15,7 +15,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Followup_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-followup_time" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[followup_time]" type="text" value="{:$row.followup_time?datetime($row.followup_time):''}">
<input id="c-followup_time" class="form-control datetimepicker" data-date-format="HH:mm:ss" data-use-current="true" name="row[followup_time]" type="text" value="{:$row.followup_time?datetime($row.followup_time):''}">
</div>
</div>
<div class="form-group layer-footer">

View File

@@ -0,0 +1,34 @@
<?php
/*
* description
* authorwh
* email
* createTime{2025/3/27} {19:50}
*/
namespace app\api\logic;
use wanghua\general_utility_tools_php\tool\Tools;
class MessageLogic extends BaseLogic
{
///message/postText
public function postText($data)
{
$url = '/message/postText';
$post_data = [
'appId'=>$data['appId'],
'toWxid'=>$data['toWxid'],
'content'=>$data['content'],
//@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all'
'ats'=>$data['ats'],
];
Tools::log_to_write_txt(['发送文字消息,入参:$post_data'=>$post_data]);
$res = $this->curl_post_json($url, $post_data);
Tools::log_to_write_txt(['发送文字消息,出参:$res'=>$res]);
return $res;
}
}

View File

@@ -9,8 +9,12 @@
namespace app\index\controller;
use app\api\logic\MessageLogic;
use app\api\logic\TokenLogic;
use think\Controller;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
//定时任务
class Tasktimer extends Controller
@@ -19,8 +23,102 @@ class Tasktimer extends Controller
//按分钟执行
function runMinutes(){
//客户回访计划
Mmodel::catchJson(function (){
//回访记录
$return_record = Db::table('fa_firmcustomerfollowuprecord')
->where('status','no')
->select();
if(empty($return_record)){
Tools::log_to_write_txt(['无回访记录计划,无需回访']);
return '';
}
foreach ($return_record as $k=>$item){
Tools::log_to_write_txt(['客户回访计划,开始:$item'=>$item]);
$ret = $this->postText($item);
dump($ret);
Tools::log_to_write_txt(['客户回访计划,结束:$res'=>$ret]);
}
//Tools::log_to_write_txt(['runMinutes出参$res'=>$ret]);
//dump($ret);
return '';
});
}
/**
* desc发送文字消息
* authorwh
* @return array
*/
private function postText($return_record){
//$firmcustomerfollowuprecord_id = input('firmcustomerfollowuprecord_id',1);
//查询客户
$cust = Db::table('fa_firmcustomer')
->where('id',$return_record['firmcustomer_id'])
->find();
if(empty($cust)){
return Tools::set_fail('有回访计划,客户不存在');
}
//查询客户所绑定的ai客服
$ai_config = Db::table('fa_aicustomerservice')
->where('id',$cust['aicustomerservice_ids'])
->find();
if(empty($ai_config)){
return Tools::set_fail('有回访计划无ai客服服务该客户');
}
$base_url = $ai_config['server_url'];
//查询回访计划
$plan = Db::table('fa_firmcustomerfollowuptimelist')
->where('firmcustomerfollowuprecord_id',$return_record['id'])
->order('followup_time asc')
->find();
if(empty($plan)){
return Tools::set_fail('该客户没有回访计划');
}
//记录创建时间
$create_time = $return_record['create_time'];
$day = (int)$plan['day'];
//在记录创建后的N天N点执行
$day_time = strtotime($create_time) + ($day * 86400);//N天后
if($day_time > time()){
return Tools::set_fail('未到回访时间');
}
$date = date('Y-m-d ',$day_time).$plan['followup_time'];
$exc_time = strtotime($date);//最终的执行时间
//校验时间是否达到执行计划时间
if($exc_time > time()){
return Tools::set_fail('未到计划回访时间');
}
$logic = new MessageLogic();
$logic->setBaseUrl($base_url);
$tokenArr = (new TokenLogic())->getToken();
$data = [
'appId'=>$tokenArr['appId'],
'toWxid'=>$cust['rel_wx'],
'content'=>$return_record['visit_msg'],
//@的好友,多个英文逗号分隔。群主或管理员@全部的人,则填写'notify@all'
'ats'=>$cust['rel_wx'],
];
Tools::log_to_write_txt(['回访客户,开始:$post_data'=>$data]);
$res = $logic->postText($data);
Tools::log_to_write_txt(['回访客户,结束:$res'=>$res]);
//修改回访记录回访状态
Db::table('fa_firmcustomerfollowuprecord')
->where('id',$return_record['id'])
->update([
'status'=>'yes',
'send_time'=>Tools::get_now_date(),
]);
return Tools::set_ok('发送成功');
}
}

View File

@@ -134,9 +134,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
let txt = $('#c-hui-fang-yao-dian').val();
// console.log(wx_id);
// console.log(e);
// let load_index = layer.load(1);
let load_index = layer.load(1);
$.post('ai/talk_skill',{txt:txt},function (res) {
// layer.close(load_index);
layer.close(load_index);
//回显
$('#c-visit_msg').val(res.data);
},'json');

View File

@@ -34,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id'), operate:false},
{field: 'day', title: __('Day'), operate:false},
{field: 'followup_time', title: __('Followup_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'followup_time', title: __('Followup_time'), operate:false},
{field: 'firmcustomerfollowuprecord.name', title: __('Firmcustomerfollowuprecord.name'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]

View File

@@ -77,7 +77,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
add: function () {
$('.shi_li_huashu').on('click',function () {
let txt = $('#c-main_points').val();
let index = layer.load(1);
$.post('ai/talk_skill',{txt:txt},function (res) {
layer.close(index);
$('#c-ai_text').val(res.data);
},'json');
});