44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace process;
|
|
|
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
|
use app\common\model\store_order\StoreOrder;
|
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use Workerman\Crontab\Crontab;
|
|
|
|
class Task
|
|
{
|
|
public function onWorkerStart()
|
|
{
|
|
|
|
// 每5分钟执行一次
|
|
new Crontab('0 */10 * * * *', function () {
|
|
$where = ['paid' => 0];
|
|
$where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单
|
|
// 删除10分钟未支付的订单
|
|
$oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除
|
|
if($oid){
|
|
StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]);
|
|
$arr = StoreOrderCartInfo::where('oid', 'in', $oid)->field('store_id,product_id,cart_num')->select();
|
|
$updateData = [];
|
|
$updateDataTwo = [];
|
|
foreach ($arr as $v) {
|
|
$updateData[] = [
|
|
'id' => $v['branch_product_id'],
|
|
'sales' => ['dec', $v['cart_num']]
|
|
];
|
|
$updateDataTwo[] = [
|
|
'id' => $v['product_id'],
|
|
'sales' => ['dec', $v['cart_num']]
|
|
];
|
|
}
|
|
(new StoreBranchProduct())->saveAll($updateData);
|
|
(new StoreProduct())->saveAll($updateDataTwo);
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|