setName('haikesendsms') ->setDescription('the haikesendsms command'); } protected function execute(Input $input, Output $output) { Log::info('haikesendsms:start'); try { $MerchantIntentionRepository = app()->make(MerchantIntentionRepository::class); $query = MerchantHaikeApply::getDB() ->where('applysms', 0) ->where('authsms', 0) ->where('trade_type', 'WXAUTHAPPLY') ->whereNotNull('wx_merch_no'); $query->chunk(100, function ($applys) use($MerchantIntentionRepository) { foreach ($applys as $apply) { if ($apply->check_result == '已授权') { if (!$apply->authsms){ $apply->check_result = '已授权'; $apply->authsms = 1; $apply->save(); $return = $MerchantIntentionRepository->createMer($apply->apply_id); if ($return['code'] == 200) { $MerchantIntentionRepository->update($apply->apply_id, ['status' => 1,'check_result' => '已授权', 'mer_id' => $return['data']]); } else { Log::info('创建商户失败:'.$return['msg']); } Log::info('id:'.$apply->id); YunxinSmsService::sendMessage('HAIKE_CHECK_WX_AUTH_SUCCESS_CODE', $apply->id); } } else if (!empty($apply->check_result) && $apply->check_result != '已授权') { if (!$apply->applysms){ $apply->check_result = $apply->check_result; $apply->applysms = 1; $apply->save(); YunxinSmsService::sendMessage('HAIKE_CHECK_FAIL_CODE', $apply->id); } } } }); } catch (\Throwable $e) { Log::info('haikesendsms:error'.$e->getMessage()); $output->writeln('执行失败'.$e->getMessage()); return app('json')->fail($e->getMessage()); } Log::info('haikesendsms:end'); $output->writeln('执行成功'); } }