You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.3 KiB

<?php
namespace app\mall\controller\api;
use app\base\model\app\AppUser;
use app\base\model\mpweixin\MpweixinUser;
use app\mall\model\MallSpikeConfig;
use app\mall\model\MallSpikeNotice;
use app\mall\model\MallSpikeProduct;
class SpikeNotice extends Base
{
/**
* 场次开始前发送消息推送提醒用户
* @date 2021-05-01
*/
public function notice()
{
$param = input('post.');
$notice_model = new MallSpikeNotice();
$spike_product_model = new MallSpikeProduct();
$config_model = new MallSpikeConfig();
$app_user_model = new AppUser();
//是否已设置预约提醒
$notice_id = $notice_model->getOneData([
['user_id', '=', USER_ID],
['spike_id', '=', $param['id']],
['status', '<>', 3]
], 'id');
if (!empty($notice_id)) {
return sendErrorMessage(4001, '您已预约过提醒');
}
//秒杀开始时间
$start_time = $spike_product_model->getOneData([
['id', '=', $param['id']]
], 'start_time');
//秒杀产品前X分钟提醒
$notice_minute = $config_model->getOneData([
['uid', '=', UID]
], 'notice_minute');
$data = [
'uid' => UID,
'user_agent' => USER_AGENT,
'user_id' => USER_ID,
'type' => $param['type'],
'spike_id' => $param['id'],
'status' => 1,
'notice_time' => $start_time - $notice_minute * 60, //提醒时间
'start_time' => $start_time
];
if ($param['type'] == 1) { //APP推送为client_id
$client_id = $app_user_model->getOneData([
['id', '=', APP_USER_ID]
], 'client_id');
$data['touser'] = $client_id;
} else if ($param['type'] == 2) { //微信小程序模板消息为微信小程序OPENID
$mpweixin_user_model = new MpweixinUser();
$openid = $mpweixin_user_model->getOneData([
['user_id', '=', USER_ID]
], 'openid');
$data['touser'] = $openid;
$data['template_id'] = 'j9k-hnY1zJFQKmQ_NermXgt0DC--qPjKnERvf0uAC-o';
}
$res = $notice_model->updateNotice($data);
if (!$res) {
return sendErrorMessage(4002, '预约失败,请稍后重试');
}
return sendSuccessMessage('预约成功');
}
/**
* 场次开始前发送消息推送提醒用户
* @date 2021-05-01
*/
public function noticeCancel()
{
$param = input('post.');
$notice_model = new MallSpikeNotice();
//是否已设置预约提醒
$notice_id = $notice_model->getOneData([
['user_agent', '=', USER_AGENT],
['user_id', '=', USER_ID],
['spike_id', '=', $param['id']],
['status', '<>', 3]
], 'id');
if (empty($notice_id)) {
return sendErrorMessage(4001, '您没有设置提醒');
}
$data = [
'id' => $notice_id,
'status' => 3,
'cancel_time' => time()
];
$res = $notice_model->dataUpdate($data);
if (!$res) {
return sendErrorMessage(4002, '取消失败,请稍后重试');
}
return sendSuccessMessage('取消成功');
}
}