|
|
<?php
|
|
|
|
|
|
namespace app\mall\controller\api;
|
|
|
|
|
|
|
|
|
use app\mall\model\MallConfig;
|
|
|
use app\mall\model\MallOrder;
|
|
|
use app\mall\model\MallOrderProduct;
|
|
|
use app\mall\model\MallProduct;
|
|
|
use app\mall\model\MallSpikeNotice;
|
|
|
use app\mall\model\MallSpikeProduct;
|
|
|
use think\facade\Db;
|
|
|
|
|
|
class Crontab extends Base
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 每5分钟--取消超过时间的未支付订单
|
|
|
* @date 2022-02-11
|
|
|
*/
|
|
|
public function orderCancel()
|
|
|
{
|
|
|
$order_model = new MallOrder();
|
|
|
$config_model = new MallConfig();
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
//获取全部满足条件的订单
|
|
|
$where = [
|
|
|
['status', '=', 1] //待支付
|
|
|
];
|
|
|
$order_list = $order_model->getAllData($where);
|
|
|
|
|
|
//获取商城配置-X分钟后未付款订单自动取消
|
|
|
$order_cancel_minute = $config_model->column('order_cancel_minute', 'uid');
|
|
|
|
|
|
foreach ($order_list as $k => $v) {
|
|
|
if (strtotime($v['create_time']) + $order_cancel_minute[$v['uid']] * 60 <= time()) {
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->cancelOrder($v['id'], $v['user_id'], 3);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
Db::commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dump('success');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 每天0:01--X天自动确认收货
|
|
|
* @date 2022-02-11
|
|
|
*/
|
|
|
public function orderFinish()
|
|
|
{
|
|
|
$order_model = new MallOrder();
|
|
|
$config_model = new MallConfig();
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
//获取全部满足条件的订单
|
|
|
$where = [
|
|
|
['status', '=', 3] //待收货
|
|
|
];
|
|
|
$order_list = $order_model->getAllData($where);
|
|
|
|
|
|
//获取商城配置-X天自动确认收货
|
|
|
$order_confirm_day = $config_model->column('order_confirm_day', 'uid');
|
|
|
|
|
|
foreach ($order_list as $k => $v) {
|
|
|
if (strtotime($v['express_time']) + $order_confirm_day[$v['uid']] * 24 * 3600 <= time()) {
|
|
|
Db::startTrans();
|
|
|
$res = $order_logic->orderFinish($v['id'], $v['user_id'], 3);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
Db::commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dump('success');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 每天0:01--评价超过时间的未评价订单
|
|
|
* @date 2022-02-11
|
|
|
*/
|
|
|
public function orderEvaluate()
|
|
|
{
|
|
|
$order_model = new MallOrder();
|
|
|
$order_product_model = new MallOrderProduct();
|
|
|
$config_model = new MallConfig();
|
|
|
$order_logic = new \app\mall\logic\Order();
|
|
|
|
|
|
//获取全部满足条件的订单
|
|
|
$where = [
|
|
|
['status', '=', 4] //待评价
|
|
|
];
|
|
|
// TODO field删减 同时订单评价方法同
|
|
|
$order_list = $order_model->getAllData($where);
|
|
|
|
|
|
//获取商城配置-X天自动评价
|
|
|
$order_review_day = $config_model->column('order_review_day', 'uid');
|
|
|
|
|
|
foreach ($order_list as $k => $v) {
|
|
|
if (strtotime($v['confirm_time']) + $order_review_day[$v['uid']] * 24 * 3600 <= time()) {
|
|
|
Db::startTrans();
|
|
|
$order_product = $order_product_model->getAllData([
|
|
|
['order_id', '=', $v['id']]
|
|
|
])->toArray();
|
|
|
foreach ($order_product as $k1 => $v1) {
|
|
|
$order_product[$k1]['star'] = 5;
|
|
|
$order_product[$k1]['content'] = '此用户没有填写评价。';
|
|
|
$order_product[$k1]['img_path'] = [];
|
|
|
$order_product[$k1]['video_path'] = [];
|
|
|
}
|
|
|
$res = $order_logic->orderEvaluate($v['id'], $order_product, $v['user_id']);
|
|
|
if ($res['code'] != 0) {
|
|
|
Db::rollback();
|
|
|
}
|
|
|
Db::commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dump('success');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 每2分钟--秒杀产品即将开抢提醒用户
|
|
|
* @date 2022-02-11
|
|
|
*/
|
|
|
public function sendNotice()
|
|
|
{
|
|
|
$uni_push_param = get_dcloud_uni_push_config();
|
|
|
$notice_model = new MallSpikeNotice();
|
|
|
$spike_product_model = new MallSpikeProduct();
|
|
|
$product_model = new MallProduct();
|
|
|
|
|
|
//获取全部满足条件的订单
|
|
|
$where = [
|
|
|
['status', '=', 1], //未提醒
|
|
|
['notice_time', '>=', time()] //提醒时间已过
|
|
|
];
|
|
|
$notice_list = $notice_model->getAllData($where, 'id,uid,user_id,type,template_id,touser,spike_id,status');
|
|
|
|
|
|
foreach ($notice_list as $k => $v) {
|
|
|
//获取提醒秒杀产品
|
|
|
$spike_product = $spike_product_model->getOneSpikeProduct([
|
|
|
['id', '=', $v['spike_id']]
|
|
|
], 'uid,product_id,price_spike,start_time');
|
|
|
|
|
|
//获取提醒秒杀产品关联的产品
|
|
|
$product = $product_model->getOneProduct([
|
|
|
['id', '=', $spike_product['product_id']]
|
|
|
], 'id,name');
|
|
|
|
|
|
if ($v['type'] == 1) {//APP推送
|
|
|
$push_class = new \getui\push\Push($uni_push_param);
|
|
|
|
|
|
$result = $push_class->toSinglePushByCid($v['touser'], $v['id'], '秒杀提醒', '您预约的产品' . $product['name'] . '即将开枪', $uni_push_param['package_name'], 'spikenotice_' . $v['spike_id']);
|
|
|
platformLog($v['touser'], $result, 'app_uni_push_' . $v['uid']);
|
|
|
if ($result['code'] == 0) {
|
|
|
//发送模板消息成功时,更新状态为已通知
|
|
|
$data = [
|
|
|
'id' => $v['id'],
|
|
|
'status' => 2,
|
|
|
'actual_notice_time' => time()
|
|
|
];
|
|
|
$notice_model->dataUpdate($data);
|
|
|
}
|
|
|
|
|
|
} else if ($v['type'] == 2) { //微信模板消息
|
|
|
$mp_weixin_param = get_mp_weixin_config($v['uid']);
|
|
|
$message_class = new \tencent\wechat\mpweixin\Message($mp_weixin_param);
|
|
|
|
|
|
//模板数组
|
|
|
$template = [
|
|
|
'template_id' => $v['template_id'], // 所需下发的订阅模板id
|
|
|
'touser' => $v['touser'], // 接收者(用户)的 openid
|
|
|
'page' => '/pages/mall/spike/detail?id=' . $v['spike_id'], // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
|
|
|
'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
|
|
|
'thing1' => [
|
|
|
'value' => $product['name'],
|
|
|
],
|
|
|
'time2' => [
|
|
|
'value' => date("Y-m-d H:i", $spike_product['start_time']),
|
|
|
],
|
|
|
'amount3' => [
|
|
|
'value' => $spike_product['price_spike'],
|
|
|
],
|
|
|
'thing5' => [
|
|
|
'value' => '请及时关注抢购',
|
|
|
],
|
|
|
],
|
|
|
];
|
|
|
$result = $message_class->sendTemplateMessage($template); //发送消息
|
|
|
platformLog($template, $result, 'mpweixin_sendtemplate_' . $spike_product['uid']);
|
|
|
|
|
|
if ($result['errcode'] == 0) {
|
|
|
//发送模板消息成功时,更新状态为已通知
|
|
|
$data = [
|
|
|
'id' => $v['id'],
|
|
|
'status' => 2,
|
|
|
'actual_notice_time' => time()
|
|
|
];
|
|
|
$notice_model->dataUpdate($data);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
dump('success');
|
|
|
}
|
|
|
|
|
|
}
|