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.
yanzong/app/command/test.php

73 lines
2.1 KiB

10 months ago
<?php
declare (strict_types=1);
namespace app\command;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use think\facade\Db;
10 months ago
use app\api\model\{Goods as GoodsModel};
use app\api\model\PreSale;
10 months ago
use app\api\model\PreSaleMessage;
use app\api\model\PreSaleLog;
10 months ago
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
class test extends Command
{
protected function configure()
{
// 指令配置
$this->setName('test')
10 months ago
->setDescription('预售到期自动上架');
10 months ago
}
protected function execute(Input $input, Output $output)
{
10 months ago
//todo wmc这边代码需要优化
10 months ago
$info = PreSale::where('status', 1)
->where('p_time', '<=', date('Y-m-d H:i:s'))
->where('is_change', '=', 0)
->select();
foreach ($info as $v) {
//所有商品直接上架
if (!empty($v['goods_list'])) {
$goodslist = explode(',', $v['goods_list']);
GoodsModel::where('store_id', $v['store_id'])
->whereIn('goods_id', $goodslist)
->update(['status' => 10]);
}
//更改预售状态
PreSale::where('id', $v['id'])
->update(['is_change' => 1]);
10 months ago
//获取预约信息
10 months ago
$prelist = PreSaleLog::where([
'store_id' => $v['store_id'],
])->whereIn('goods_id', $goodslist)->select();
10 months ago
10 months ago
//预约的用户推送消息
10 months ago
foreach ($prelist as $v2) {
$goodsName = GoodsModel::where([
'store_id' => $v2['store_id'],
'goods_id' => $v2['goods_id']
])->field('goods_name')->find()->goods_name;
10 months ago
10 months ago
PreSaleMessage::insert([
'user_id' => $v2['user_id'],
'goods_id' => $v2['goods_id'],
'type' => 1,
'store_id' => $v['store_id'],
'content' => '您预约的商品' . $goodsName . '已经开售啦',
'ctime' => date('Y-m-d H:i:s')
]);
}
10 months ago
}
10 months ago
}
}