db->close(); $lock_key = RedisKeyEnum::suffix('lock_higo_user_hi_value'); $identification = uniqid(); if (!LockHelper::lock($lock_key, $identification, 60, 10)) throw new \Exception('检测会员上笔订单,超出时间,冻结账户嗨值进入处理阶段,当前访问过多'); $mall_list = Mall::getEnableMallList(true); $mall_ids = array_column($mall_list, 'id'); if (empty($mall_ids)) { echo '没有可用商城,不做处理 ... ' . PHP_EOL; return ExitCode::UNSPECIFIED_ERROR; } $redis = \Yii::$app->redis; foreach ($mall_ids as $mall_id) { if (MallAddons::isInstall($mall_id, HiGoEnum::ADDONS_NAME) == 0) continue; $setting = \Yii::$app->services->setting->addons->get($mall_id, HiGoEnum::ADDONS_NAME, 'marketing'); if (!$setting || !$setting['new_order_enable'] || !$setting['new_order_days']) continue; $order_start_time = strtotime('-'.$setting['new_order_days'].' day'); $where = [ 'and', ['mall_id' => $mall_id], ['>', 'hi_value', 0], ['status' => StatusEnum::ENABLED], ]; foreach (HigoWallet::find()->where($where)->each(500) as $user_wallet) { //查询用户上一笔订单 $user_id = $user_wallet->user_id; $last_order = Order::find()->where(['user_id' => $user_id,'mall_id' => $mall_id])->andWhere(['>','pay_time',$order_start_time])->one(); if($last_order) continue; //未查询到订单,冻结嗨值 echo '这是会员ID:'.$user_id; //注册赠送嗨值 $desc = '冻结会员嗨值'; $wallet_log = [ 'mall_id' => $mall_id, 'user_id' => $user_id, 'change_type' => CapitalLog::CHANGE_TYPE_ADD, 'change_num' => $user_wallet->hi_value, 'desc' => $desc, 'source_table' => User::tableName(), 'source_table_id' => $user_id, 'from_type' => HiGoEnum::FROM_TYPE_REPURCHASE_ACTIVE, 'wallet_type' => HiGoEnum::WALLET_TYPE_HI_VALUE, 'is_freeze' => 1, 'from_normal_to_freeze' => 1, 'addon_name' => HiGoEnum::ADDONS_NAME, ]; WalletLogic::handleInQueue($wallet_log); } } LockHelper::uLock($lock_key,$identification); return ExitCode::OK; } catch (\Exception $e) { $msg = '检测会员上笔订单,超出时间,冻结账户嗨值,执行结束失败任务处理出错:' . $e->getMessage() . PHP_EOL; echo $msg; \Yii::error($msg); \Yii::getLogger()->flush(true); return ExitCode::UNSPECIFIED_ERROR; } } }