|
|
@@ -293,40 +293,46 @@ class ProductController extends Controller
|
|
|
//预售到期自动取消
|
|
|
public function actionCancelPresell()
|
|
|
{
|
|
|
- $now = time(); //注意脚本执行时间要在凌晨0点之后,否则会出问题
|
|
|
- $redis = Yii::$app->redis;
|
|
|
- $cursor = '0';
|
|
|
- do {
|
|
|
- $scanResult = $redis->executeCommand('SCAN', [$cursor, 'MATCH', 'product_presell:*', 'COUNT', 500]);
|
|
|
- $cursor = $scanResult[0] ?? '0';
|
|
|
- $keys = $scanResult[1] ?? [];
|
|
|
- if (empty($keys)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- foreach ($keys as $key) {
|
|
|
- $firstDate = (int)$redis->get($key);
|
|
|
- if ($firstDate >= $now) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $id = (int)str_replace('product_presell:', '', $key);
|
|
|
- if ($id <= 0) {
|
|
|
- $redis->del($key);
|
|
|
+ try{
|
|
|
+ $now = time(); //注意脚本执行时间要在凌晨0点之后,否则会出问题
|
|
|
+ $redis = Yii::$app->redis;
|
|
|
+ $cursor = '0';
|
|
|
+ do {
|
|
|
+ $scanResult = $redis->executeCommand('SCAN', [$cursor, 'MATCH', 'product_presell:*', 'COUNT', 500]);
|
|
|
+ $cursor = $scanResult[0] ?? '0';
|
|
|
+ $keys = $scanResult[1] ?? [];
|
|
|
+ if (empty($keys)) {
|
|
|
continue;
|
|
|
}
|
|
|
- $item = ProductClass::getById($id, true);
|
|
|
- if (empty($item)) {
|
|
|
- $redis->del($key);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if ((int)$item->presell !== 1) {
|
|
|
+ foreach ($keys as $key) {
|
|
|
+ $firstDate = (int)$redis->get($key);
|
|
|
+ if ($firstDate >= $now) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $id = (int)str_replace('product_presell:', '', $key);
|
|
|
+ if ($id <= 0) {
|
|
|
+ $redis->del($key);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $item = ProductClass::getById($id, true);
|
|
|
+ if (empty($item)) {
|
|
|
+ $redis->del($key);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ((int)$item->presell !== 1) {
|
|
|
+ $redis->del($key);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $item->presell = 0;
|
|
|
+ $item->presellDate = '';
|
|
|
+ $item->save();
|
|
|
$redis->del($key);
|
|
|
- continue;
|
|
|
}
|
|
|
- $item->presell = 0;
|
|
|
- $item->presellDate = '';
|
|
|
- $item->save();
|
|
|
- $redis->del($key);
|
|
|
- }
|
|
|
- } while ($cursor !== '0');
|
|
|
+ } while ($cursor !== '0');
|
|
|
+
|
|
|
+ Yii::info('预售到期自动取消脚本成功执行');
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Yii::error('预售到期自动取消脚本执行失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|