|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Workchat;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Models\Base;
|
|
|
|
use App\Models\Inquiry\InquiryFormData;
|
|
|
|
use App\Models\ProjectAssociation\ProjectAssociation;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class MessagePush
|
|
|
|
* @package App\Models\Workchat
|
|
|
|
* @author zbj
|
|
|
|
* @date 2024/9/7
|
|
|
|
*/
|
|
|
|
class MessagePush extends Base
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
const STATUS_PENDING = 0;
|
|
|
|
const STATUS_SUCCESS = 1;
|
|
|
|
const STATUS_ERROR = 9;
|
|
|
|
|
|
|
|
const TYPE_INQUIRY = 'inquiry';
|
|
|
|
|
|
|
|
//设置关联表名
|
|
|
|
/**
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
protected $table = 'gl_workchat_message_push';
|
|
|
|
|
|
|
|
|
|
|
|
public static function addInquiryMessage($id, $project_id, $country, $submit_at){
|
|
|
|
if(!ProjectServer::useProject($project_id)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//项目是否有绑定群
|
|
|
|
$friend_id = ProjectAssociation::where('project_id', $project_id)
|
|
|
|
->where('status', ProjectAssociation::STATUS_NORMAL)
|
|
|
|
->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
|
|
|
|
->value('friend_id');
|
|
|
|
if(!$friend_id){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//9-21 点,每条消息及时通知
|
|
|
|
//21-第二天 9 点,整合一起通知
|
|
|
|
$hour = date('H', strtotime($submit_at));
|
|
|
|
if($hour >= 9 && $hour < 21) {
|
|
|
|
$model = new self();
|
|
|
|
$model->project_id = $project_id;
|
|
|
|
$model->friend_id = $friend_id;
|
|
|
|
$model->type = self::TYPE_INQUIRY;
|
|
|
|
$model->ref_ids = $id;
|
|
|
|
$model->content = '[' . date('H:i', strtotime($submit_at)) . '] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!';
|
|
|
|
}else{
|
|
|
|
//定时发送时间
|
|
|
|
$send_time = $hour >= 9 ? date('Y-m-d 09:00:00', strtotime('+1 day')) : date('Y-m-d 09:00:00');
|
|
|
|
|
|
|
|
$model = self::where('project_id', $project_id)->where('type', self::TYPE_INQUIRY)->where('send_time', $send_time)->first();
|
|
|
|
if(!$model){
|
|
|
|
$model = new self();
|
|
|
|
$model->project_id = $project_id;
|
|
|
|
$model->friend_id = $friend_id;
|
|
|
|
$model->type = self::TYPE_INQUIRY;
|
|
|
|
$model->ref_ids = $id;
|
|
|
|
$model->send_time = $send_time;
|
|
|
|
$model->content = '[09:00] 您的站点收到来自【' . $country . '】的询盘信息,请登录全球搜后台进行查看!';
|
|
|
|
}else{
|
|
|
|
$ref_ids = explode(',', $model->ref_ids);
|
|
|
|
$ref_ids[] = $id;
|
|
|
|
$model->ref_ids = implode(',', $ref_ids);
|
|
|
|
$countries = InquiryFormData::whereIn('id', $ref_ids)->pluck('country')->toArray();
|
|
|
|
$count = count($countries);
|
|
|
|
$countries = array_unique($countries);
|
|
|
|
if(count($countries) > 3){
|
|
|
|
$country = implode(',', array_slice($countries, 0, 3)) . '...';
|
|
|
|
}else{
|
|
|
|
$country = implode(',', $countries);
|
|
|
|
}
|
|
|
|
$model->content = '[09:00] 您的站点收到来自【' . $country . '】'.$count.'条询盘信息,请登录全球搜后台进行查看!';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$model->save();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|